summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/rda/rda_wlan/wlan_event.c
blob: 2bda586b00198d2e1cbf3835f83edfa941b52913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "wlan_includes.h"

void wlan_push_event(wlan_private * priv, wlan_event_type type, void* para, u8 front)
{
	wlan_event *event = NULL;
	ENTER();

	event = kzalloc(sizeof(wlan_event), GFP_KERNEL);
    if (event)
        event->EventType = type;
	else {
		WLAN_ERRP("kzalloc wlan_event memory failed\n");
		return;
	}

	event->Para = para;

	spin_lock(&priv->EventLock);
	if(front)
		list_add(&event->list, &priv->EventQueue);
	else
		list_add_tail(&event->list, &priv->EventQueue);
	priv->EventQuNum ++;
	spin_unlock(&priv->EventLock);

		complete(&priv->EventThread.comp);
	
	LEAVE();
}

wlan_event* wlan_pull_event(wlan_private * priv)
{
	wlan_event* event;

	ENTER();
	spin_lock(&priv->EventLock);
	if (list_empty(&priv->EventQueue)) {
		spin_unlock(&priv->EventLock);
		return NULL;
	}
	event = (wlan_event*)priv->EventQueue.next;
	list_del(&event->list);
	priv->EventQuNum --;
	spin_unlock(&priv->EventLock);
	LEAVE();
	return event;
}

void wlan_timer_handler(unsigned long fcontext)
{
	PWLAN_DRV_TIMER timer = (PWLAN_DRV_TIMER) fcontext;

	if(timer->timer_function)
		timer->timer_function(timer->function_context);
	else {
		wlan_push_event((wlan_private *) timer->function_context, timer->EventType, timer->function_context, TRUE);
	}
		
	if (timer->timer_is_periodic == TRUE) {
		mod_timer(&timer->tl, jiffies + ((timer->time_period * HZ) / 1000));
	} else
		timer->timer_is_canceled = TRUE;
}


void wlan_mac_status(wlan_private *priv, 
		char *wid_status, unsigned short wid_status_len)
{
	char mac_status;

	WLAN_DBGLAP(WLAN_DA_WID, WLAN_DL_DEBUG, "%s >>>\n", __func__);

#ifdef WLAN_FORCE_SUSPEND_SUPPORT
	if (priv->CardInSuspend == TRUE) {
		WLAN_DBGLAP(WLAN_DA_WID, WLAN_DL_TRACE, "%s ingnored in ap deep sleep mode.\n", __func__);
		return;
	}
#endif
	mac_status = wid_status[7];

	if (mac_status == MAC_CONNECTED) {

		
		WLAN_DBGLAP(WLAN_DA_WID, WLAN_DL_CRIT, "MAC CONNECTED\n");
		
		priv->connect_status = MAC_CONNECTED;
		netif_carrier_on(priv->netDev);
		netif_wake_queue(priv->netDev);

		wlan_cancel_timer(&priv->ReAssociationTimeOut);
		//report connect to supper layer
		wlan_indicate_connected(priv);	  
		{
			wlan_push_event(priv, WLAN_EVENT_SET_PHY_ERR_INT, priv, FALSE);
		}
		wake_lock_timeout(&priv->MacStatusLock, 6 * HZ);
	} else if (mac_status == MAC_DISCONNECTED) {
		WLAN_DBGLAP(WLAN_DA_WID, WLAN_DL_CRIT, "MAC_DISCONNECTED\n");
		
		wlan_cancel_timer(&priv->ReAssociationTimeOut);
		//for wep we should toggler from open to shared if auth failed
		if(priv->ToggalAssociation){
			wlan_re_assocication(priv);
		}else{
			wlan_cancel_timer(&priv->AssociationTimeOut);
			
			priv->connect_status = MAC_DISCONNECTED;
			priv->assoc_ongoing = FALSE;
			netif_stop_queue(priv->netDev);
			netif_carrier_off(priv->netDev);
			
			//report disconnect to supper layer
			if(!priv->IgnoreFisrtDisconnect){
				wlan_indicate_disconnected(priv);
				
				wake_lock_timeout(&priv->MacStatusLock, 6*HZ);
			}else{
				priv->IgnoreFisrtDisconnect = FALSE;
			}
		}		  
	} else {
		WLAN_ERRP("Invalid MAC Status 0x%02x\n", mac_status);
	}

	WLAN_DBGLAP(WLAN_DA_WID, WLAN_DL_DEBUG, "%s <<<\n", __func__);
}

void wlan_start_netif(wlan_private* priv)
{
	netif_wake_queue(priv->netDev);
}
void wlan_process_event(wlan_private * priv)
{
	int ret=0;
	wlan_event *event = NULL;

	event = wlan_pull_event(priv);
	if (!event)
		return;

	WLAN_DBGLAP(WLAN_DA_MAIN, WLAN_DL_TRACE, "type :%d \n", event->EventType);
	
	switch(event->EventType){
	case WLAN_EVENT_SCAN_RESULT_TIMEOUT:
		wlan_report_scan_result(priv);
		break;

	case WLAN_EVENT_START_ASSOC:
		wlan_assocication(priv);
		break;

	case WLAN_EVENT_ASSOC_TIMEOUT:
		wlan_assocication_timeout(priv);
		break;

	case WLAN_EVENT_REASSOC_TIMEOUT:
		wlan_re_assocication(priv);
		break;

	case WLAN_EVENT_CARD_TO_SLEEP:
		handle_card_to_sleep_cmd(priv);
		break;

	case WLAN_EVENT_CARD_CONTROL_INIT:
		ret=wlan_card_control_init(priv);
		if (ret) {
			WLAN_ERRP("Wlan Card Control Init Failed! \n");
		} else {
			WLAN_DBGLAP(WLAN_DA_MAIN, WLAN_DL_CRIT, "Wlan Card Control Init Success, Chip Version:%d \n", priv->version);
		}

		break;
	case WLAN_EVENT_CHECK_SDIO:
		wlan_card_check_sdio(priv);
		break;

	case WLAN_EVENT_START_NETIF:
		wlan_start_netif(priv);
		break;

	case WLAN_EVENT_SET_PHY_ERR_INT:
		wlan_set_phy_timeout(priv);
		break;

	case WLAN_EVENT_START_SCAN:
		wlan_set_scan_by_driver(priv);
		break;
	default:
		break;
	}
	
	kfree(event);
}


int wlan_event_thread(void *data)
{
	wlan_thread *thread = (wlan_thread *)data;
	wlan_private *priv = thread->priv;
	
	ENTER();

	wlan_activate_thread(thread);
	
	current->flags |= PF_NOFREEZE;

	while(1){
		
		wait_for_completion_interruptible(&thread->comp);

		if (kthread_should_stop()){
			WLAN_DBGLAP(WLAN_DA_MAIN, WLAN_DL_CRIT,"wlan_event_thread: break from main thread \n");
			break;
		}

		if(priv->CardRemoved){			
			break;
		}
		
				wlan_process_event(priv);
	}
	wlan_deactivate_thread(thread);

	LEAVE();
	return 0;
}