1 #include "coreconfigurator.h"
2 #include "wilc_wlan_if.h"
4 #include <linux/errno.h>
5 #include <linux/slab.h>
6 #define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
7 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
9 enum basic_frame_type {
10 FRAME_TYPE_CONTROL = 0x04,
11 FRAME_TYPE_DATA = 0x08,
12 FRAME_TYPE_MANAGEMENT = 0x00,
13 FRAME_TYPE_RESERVED = 0x0C,
14 FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
47 QOS_DATA_POLL_ACK = 0xB8,
48 QOS_NULL_FRAME = 0xC8,
50 QOS_CFPOLL_ACK = 0xF8,
53 FRAME_SUBTYPE_FORCE_32BIT = 0xFFFFFFFF
56 enum info_element_id {
57 ISSID = 0, /* Service Set Identifier */
58 ISUPRATES = 1, /* Supported Rates */
59 IFHPARMS = 2, /* FH parameter set */
60 IDSPARMS = 3, /* DS parameter set */
61 ICFPARMS = 4, /* CF parameter set */
62 ITIM = 5, /* Traffic Information Map */
63 IIBPARMS = 6, /* IBSS parameter set */
64 ICOUNTRY = 7, /* Country element */
65 IEDCAPARAMS = 12, /* EDCA parameter set */
66 ITSPEC = 13, /* Traffic Specification */
67 ITCLAS = 14, /* Traffic Classification */
68 ISCHED = 15, /* Schedule */
69 ICTEXT = 16, /* Challenge Text */
70 IPOWERCONSTRAINT = 32, /* Power Constraint */
71 IPOWERCAPABILITY = 33, /* Power Capability */
72 ITPCREQUEST = 34, /* TPC Request */
73 ITPCREPORT = 35, /* TPC Report */
74 ISUPCHANNEL = 36, /* Supported channel list */
75 ICHSWANNOUNC = 37, /* Channel Switch Announcement */
76 IMEASUREMENTREQUEST = 38, /* Measurement request */
77 IMEASUREMENTREPORT = 39, /* Measurement report */
78 IQUIET = 40, /* Quiet element Info */
79 IIBSSDFS = 41, /* IBSS DFS */
80 IERPINFO = 42, /* ERP Information */
81 ITSDELAY = 43, /* TS Delay */
82 ITCLASPROCESS = 44, /* TCLAS Processing */
83 IHTCAP = 45, /* HT Capabilities */
84 IQOSCAP = 46, /* QoS Capability */
85 IRSNELEMENT = 48, /* RSN Information Element */
86 IEXSUPRATES = 50, /* Extended Supported Rates */
87 IEXCHSWANNOUNC = 60, /* Extended Ch Switch Announcement*/
88 IHTOPERATION = 61, /* HT Information */
89 ISECCHOFF = 62, /* Secondary Channel Offeset */
90 I2040COEX = 72, /* 20/40 Coexistence IE */
91 I2040INTOLCHREPORT = 73, /* 20/40 Intolerant channel report*/
92 IOBSSSCAN = 74, /* OBSS Scan parameters */
93 IEXTCAP = 127, /* Extended capability */
94 IWMM = 221, /* WMM parameters */
95 IWPAELEMENT = 221, /* WPA Information Element */
96 INFOELEM_ID_FORCE_32BIT = 0xFFFFFFFF
99 static inline u16 get_beacon_period(u8 *data)
104 bcn_per |= (data[1] << 8);
109 static inline u32 get_beacon_timestamp_lo(u8 *data)
112 u32 index = MAC_HDR_LEN;
114 time_stamp |= data[index++];
115 time_stamp |= (data[index++] << 8);
116 time_stamp |= (data[index++] << 16);
117 time_stamp |= (data[index] << 24);
122 static inline u32 get_beacon_timestamp_hi(u8 *data)
125 u32 index = (MAC_HDR_LEN + 4);
127 time_stamp |= data[index++];
128 time_stamp |= (data[index++] << 8);
129 time_stamp |= (data[index++] << 16);
130 time_stamp |= (data[index] << 24);
135 static inline enum sub_frame_type get_sub_type(u8 *header)
137 return ((enum sub_frame_type)(header[0] & 0xFC));
140 static inline u8 get_to_ds(u8 *header)
142 return (header[1] & 0x01);
145 static inline u8 get_from_ds(u8 *header)
147 return ((header[1] & 0x02) >> 1);
150 static inline void get_address1(u8 *pu8msa, u8 *addr)
152 memcpy(addr, pu8msa + 4, 6);
155 static inline void get_address2(u8 *pu8msa, u8 *addr)
157 memcpy(addr, pu8msa + 10, 6);
160 static inline void get_address3(u8 *pu8msa, u8 *addr)
162 memcpy(addr, pu8msa + 16, 6);
165 static inline void get_BSSID(u8 *data, u8 *bssid)
167 if (get_from_ds(data) == 1)
168 get_address2(data, bssid);
169 else if (get_to_ds(data) == 1)
170 get_address1(data, bssid);
172 get_address3(data, bssid);
175 static inline void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
181 len = data[TAG_PARAM_OFFSET + 1];
182 j = TAG_PARAM_OFFSET + 2;
184 if (len >= MAX_SSID_LEN)
187 for (i = 0; i < len; i++, j++)
195 static inline u16 get_cap_info(u8 *data)
198 u16 index = MAC_HDR_LEN;
199 enum sub_frame_type st;
201 st = get_sub_type(data);
203 if ((st == BEACON) || (st == PROBE_RSP))
204 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
206 cap_info = data[index];
207 cap_info |= (data[index + 1] << 8);
212 static inline u16 get_assoc_resp_cap_info(u8 *data)
217 cap_info |= (data[1] << 8);
222 static inline u16 get_asoc_status(u8 *data)
226 asoc_status = data[3];
227 asoc_status = (asoc_status << 8) | data[2];
232 static inline u16 get_asoc_id(u8 *data)
237 asoc_id |= (data[5] << 8);
242 static u8 *get_tim_elm(u8 *pu8msa, u16 rx_len, u16 tag_param_offset)
246 index = tag_param_offset;
248 while (index < (rx_len - FCS_LEN)) {
249 if (pu8msa[index] == ITIM)
250 return &pu8msa[index];
251 index += (IE_HDR_LEN + pu8msa[index + 1]);
257 static u8 get_current_channel_802_11n(u8 *pu8msa, u16 rx_len)
261 index = TAG_PARAM_OFFSET;
262 while (index < (rx_len - FCS_LEN)) {
263 if (pu8msa[index] == IDSPARMS)
264 return pu8msa[index + 2];
265 index += pu8msa[index + 1] + IE_HDR_LEN;
271 s32 wilc_parse_network_info(u8 *msg_buffer,
272 struct network_info **ret_network_info)
274 struct network_info *network_info = NULL;
279 u16 wid_id = (u16)WID_NIL;
283 msg_type = msg_buffer[0];
288 msg_id = msg_buffer[1];
289 msg_len = MAKE_WORD16(msg_buffer[2], msg_buffer[3]);
290 wid_id = MAKE_WORD16(msg_buffer[4], msg_buffer[5]);
291 wid_len = MAKE_WORD16(msg_buffer[6], msg_buffer[7]);
292 wid_val = &msg_buffer[8];
304 network_info = kzalloc(sizeof(*network_info), GFP_KERNEL);
308 network_info->rssi = wid_val[0];
312 rx_len = wid_len - 1;
313 network_info->cap_info = get_cap_info(msa);
314 network_info->tsf_lo = get_beacon_timestamp_lo(msa);
316 tsf_lo = get_beacon_timestamp_lo(msa);
317 tsf_hi = get_beacon_timestamp_hi(msa);
319 network_info->tsf_hi = tsf_lo | ((u64)tsf_hi << 32);
321 get_ssid(msa, network_info->ssid, &network_info->ssid_len);
322 get_BSSID(msa, network_info->bssid);
324 network_info->ch = get_current_channel_802_11n(msa,
327 index = MAC_HDR_LEN + TIME_STAMP_LEN;
329 network_info->beacon_period = get_beacon_period(msa + index);
331 index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
333 tim_elm = get_tim_elm(msa, rx_len + FCS_LEN, index);
335 network_info->dtim_period = tim_elm[3];
336 ies = &msa[TAG_PARAM_OFFSET];
337 ies_len = rx_len - TAG_PARAM_OFFSET;
340 network_info->ies = kmemdup(ies, ies_len, GFP_KERNEL);
341 if (!network_info->ies) {
346 network_info->ies_len = ies_len;
349 *ret_network_info = network_info;
354 s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
355 struct connect_resp_info **ret_connect_resp_info)
357 struct connect_resp_info *connect_resp_info = NULL;
358 u16 assoc_resp_len = 0;
362 connect_resp_info = kzalloc(sizeof(*connect_resp_info), GFP_KERNEL);
363 if (!connect_resp_info)
366 assoc_resp_len = (u16)buffer_len;
368 connect_resp_info->status = get_asoc_status(buffer);
369 if (connect_resp_info->status == SUCCESSFUL_STATUSCODE) {
370 connect_resp_info->capability = get_assoc_resp_cap_info(buffer);
371 connect_resp_info->assoc_id = get_asoc_id(buffer);
373 ies = &buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
374 ies_len = assoc_resp_len - (CAP_INFO_LEN + STATUS_CODE_LEN +
377 connect_resp_info->ies = kmemdup(ies, ies_len, GFP_KERNEL);
378 if (!connect_resp_info->ies) {
379 kfree(connect_resp_info);
383 connect_resp_info->ies_len = ies_len;
386 *ret_connect_resp_info = connect_resp_info;