blob: d002cfbb2a60e120ab434ba6658cf6b05ef1049f [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001
2/*!
3 * @file coreconfigurator.c
4 * @brief
5 * @author
6 * @sa coreconfigurator.h
7 * @date 1 Mar 2012
8 * @version 1.0
9 */
10
Johnny Kimc5c77ba2015-05-11 14:30:56 +090011#include "coreconfigurator.h"
Chaehyun Limdd322572015-09-22 22:47:43 +090012#include "wilc_wlan_if.h"
Glen Lee1028e5a2015-10-01 16:03:40 +090013#include "wilc_wlan.h"
Leo Kim24db7132015-09-16 18:36:01 +090014#include <linux/errno.h>
Chaehyun Lime215a872015-09-30 08:15:41 +090015#include <linux/slab.h>
Shivani Bhardwajd4622f62015-10-26 20:16:32 +053016#include <linux/etherdevice.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090017#define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
18 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
Shivani Bhardwajd4622f62015-10-26 20:16:32 +053019#define ADDR1 4
20#define ADDR2 10
21#define ADDR3 16
Johnny Kimc5c77ba2015-05-11 14:30:56 +090022
Johnny Kimc5c77ba2015-05-11 14:30:56 +090023/* Basic Frame Type Codes (2-bit) */
Tony Cho9dd2f772015-10-02 14:22:03 +090024enum basic_frame_type {
Stanislav Kholmanskikh13994d12015-06-10 21:57:26 +030025 FRAME_TYPE_CONTROL = 0x04,
26 FRAME_TYPE_DATA = 0x08,
27 FRAME_TYPE_MANAGEMENT = 0x00,
28 FRAME_TYPE_RESERVED = 0x0C,
29 FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
Tony Cho9dd2f772015-10-02 14:22:03 +090030};
Johnny Kimc5c77ba2015-05-11 14:30:56 +090031
32/* Frame Type and Subtype Codes (6-bit) */
Tony Cho9dd2f772015-10-02 14:22:03 +090033enum sub_frame_type {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090034 ASSOC_REQ = 0x00,
35 ASSOC_RSP = 0x10,
36 REASSOC_REQ = 0x20,
37 REASSOC_RSP = 0x30,
38 PROBE_REQ = 0x40,
39 PROBE_RSP = 0x50,
40 BEACON = 0x80,
41 ATIM = 0x90,
42 DISASOC = 0xA0,
43 AUTH = 0xB0,
44 DEAUTH = 0xC0,
45 ACTION = 0xD0,
46 PS_POLL = 0xA4,
47 RTS = 0xB4,
48 CTS = 0xC4,
49 ACK = 0xD4,
50 CFEND = 0xE4,
51 CFEND_ACK = 0xF4,
52 DATA = 0x08,
53 DATA_ACK = 0x18,
54 DATA_POLL = 0x28,
55 DATA_POLL_ACK = 0x38,
56 NULL_FRAME = 0x48,
57 CFACK = 0x58,
58 CFPOLL = 0x68,
59 CFPOLL_ACK = 0x78,
60 QOS_DATA = 0x88,
61 QOS_DATA_ACK = 0x98,
62 QOS_DATA_POLL = 0xA8,
63 QOS_DATA_POLL_ACK = 0xB8,
64 QOS_NULL_FRAME = 0xC8,
65 QOS_CFPOLL = 0xE8,
66 QOS_CFPOLL_ACK = 0xF8,
67 BLOCKACK_REQ = 0x84,
68 BLOCKACK = 0x94,
69 FRAME_SUBTYPE_FORCE_32BIT = 0xFFFFFFFF
Tony Cho9dd2f772015-10-02 14:22:03 +090070};
Johnny Kimc5c77ba2015-05-11 14:30:56 +090071
Johnny Kimc5c77ba2015-05-11 14:30:56 +090072/* Element ID of various Information Elements */
Tony Cho9dd2f772015-10-02 14:22:03 +090073enum info_element_id {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090074 ISSID = 0, /* Service Set Identifier */
75 ISUPRATES = 1, /* Supported Rates */
76 IFHPARMS = 2, /* FH parameter set */
77 IDSPARMS = 3, /* DS parameter set */
78 ICFPARMS = 4, /* CF parameter set */
79 ITIM = 5, /* Traffic Information Map */
80 IIBPARMS = 6, /* IBSS parameter set */
81 ICOUNTRY = 7, /* Country element */
82 IEDCAPARAMS = 12, /* EDCA parameter set */
83 ITSPEC = 13, /* Traffic Specification */
84 ITCLAS = 14, /* Traffic Classification */
85 ISCHED = 15, /* Schedule */
86 ICTEXT = 16, /* Challenge Text */
87 IPOWERCONSTRAINT = 32, /* Power Constraint */
88 IPOWERCAPABILITY = 33, /* Power Capability */
89 ITPCREQUEST = 34, /* TPC Request */
90 ITPCREPORT = 35, /* TPC Report */
91 ISUPCHANNEL = 36, /* Supported channel list */
92 ICHSWANNOUNC = 37, /* Channel Switch Announcement */
93 IMEASUREMENTREQUEST = 38, /* Measurement request */
94 IMEASUREMENTREPORT = 39, /* Measurement report */
95 IQUIET = 40, /* Quiet element Info */
96 IIBSSDFS = 41, /* IBSS DFS */
97 IERPINFO = 42, /* ERP Information */
98 ITSDELAY = 43, /* TS Delay */
99 ITCLASPROCESS = 44, /* TCLAS Processing */
100 IHTCAP = 45, /* HT Capabilities */
101 IQOSCAP = 46, /* QoS Capability */
102 IRSNELEMENT = 48, /* RSN Information Element */
103 IEXSUPRATES = 50, /* Extended Supported Rates */
104 IEXCHSWANNOUNC = 60, /* Extended Ch Switch Announcement*/
105 IHTOPERATION = 61, /* HT Information */
106 ISECCHOFF = 62, /* Secondary Channel Offeset */
107 I2040COEX = 72, /* 20/40 Coexistence IE */
108 I2040INTOLCHREPORT = 73, /* 20/40 Intolerant channel report*/
109 IOBSSSCAN = 74, /* OBSS Scan parameters */
110 IEXTCAP = 127, /* Extended capability */
111 IWMM = 221, /* WMM parameters */
112 IWPAELEMENT = 221, /* WPA Information Element */
113 INFOELEM_ID_FORCE_32BIT = 0xFFFFFFFF
Tony Cho9dd2f772015-10-02 14:22:03 +0900114};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900115
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900116/* This function extracts the beacon period field from the beacon or probe */
117/* response frame. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900118static inline u16 get_beacon_period(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900119{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530120 u16 bcn_per;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900121
122 bcn_per = data[0];
123 bcn_per |= (data[1] << 8);
124
125 return bcn_per;
126}
127
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900128static inline u32 get_beacon_timestamp_lo(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900130 u32 time_stamp = 0;
131 u32 index = MAC_HDR_LEN;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132
133 time_stamp |= data[index++];
134 time_stamp |= (data[index++] << 8);
135 time_stamp |= (data[index++] << 16);
136 time_stamp |= (data[index] << 24);
137
138 return time_stamp;
139}
140
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900141static inline u32 get_beacon_timestamp_hi(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900142{
Chaehyun Lim8a54d912015-06-11 14:35:53 +0900143 u32 time_stamp = 0;
144 u32 index = (MAC_HDR_LEN + 4);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900145
146 time_stamp |= data[index++];
147 time_stamp |= (data[index++] << 8);
148 time_stamp |= (data[index++] << 16);
149 time_stamp |= (data[index] << 24);
150
151 return time_stamp;
152}
153
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900154/* This function extracts the 'frame type and sub type' bits from the MAC */
155/* header of the input frame. */
156/* Returns the value in the LSB of the returned value. */
Tony Cho9dd2f772015-10-02 14:22:03 +0900157static inline enum sub_frame_type get_sub_type(u8 *header)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900158{
Tony Cho9dd2f772015-10-02 14:22:03 +0900159 return ((enum sub_frame_type)(header[0] & 0xFC));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900160}
161
162/* This function extracts the 'to ds' bit from the MAC header of the input */
163/* frame. */
164/* Returns the value in the LSB of the returned value. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900165static inline u8 get_to_ds(u8 *header)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900166{
167 return (header[1] & 0x01);
168}
169
170/* This function extracts the 'from ds' bit from the MAC header of the input */
171/* frame. */
172/* Returns the value in the LSB of the returned value. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900173static inline u8 get_from_ds(u8 *header)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900174{
175 return ((header[1] & 0x02) >> 1);
176}
177
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900178/* This function extracts the BSSID from the incoming WLAN packet based on */
Shivani Bhardwajd4622f62015-10-26 20:16:32 +0530179/* the 'from ds' bit, and updates the MAC Address in the allocated 'data' */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900180/* variable. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900181static inline void get_BSSID(u8 *data, u8 *bssid)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900182{
183 if (get_from_ds(data) == 1)
Shivani Bhardwajd4622f62015-10-26 20:16:32 +0530184 /*
185 * Extract the MAC Address in 'address2' field of the MAC
186 * header and update the MAC Address in the allocated 'data'
187 * variable.
188 */
189 ether_addr_copy(data, bssid + ADDR2);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900190 else if (get_to_ds(data) == 1)
Shivani Bhardwajd4622f62015-10-26 20:16:32 +0530191 /*
192 * Extract the MAC Address in 'address1' field of the MAC
193 * header and update the MAC Address in the allocated 'data'
194 * variable.
195 */
196 ether_addr_copy(data, bssid + ADDR1);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 else
Shivani Bhardwajd4622f62015-10-26 20:16:32 +0530198 /*
199 * Extract the MAC Address in 'address3' field of the MAC
200 * header and update the MAC Address in the allocated 'data'
201 * variable.
202 */
203 ether_addr_copy(data, bssid + ADDR3);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900204}
205
206/* This function extracts the SSID from a beacon/probe response frame */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900207static inline void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900208{
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900209 u8 len = 0;
210 u8 i = 0;
211 u8 j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900212
213 len = data[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
214 CAP_INFO_LEN + 1];
215 j = MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
216 CAP_INFO_LEN + 2;
217
218 /* If the SSID length field is set wrongly to a value greater than the */
219 /* allowed maximum SSID length limit, reset the length to 0 */
220 if (len >= MAX_SSID_LEN)
221 len = 0;
222
223 for (i = 0; i < len; i++, j++)
224 ssid[i] = data[j];
225
226 ssid[len] = '\0';
227
228 *p_ssid_len = len;
229}
230
231/* This function extracts the capability info field from the beacon or probe */
232/* response frame. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900233static inline u16 get_cap_info(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900234{
Chaehyun Limd85f5322015-06-11 14:35:54 +0900235 u16 cap_info = 0;
236 u16 index = MAC_HDR_LEN;
Tony Cho9dd2f772015-10-02 14:22:03 +0900237 enum sub_frame_type st;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900238
239 st = get_sub_type(data);
240
241 /* Location of the Capability field is different for Beacon and */
242 /* Association frames. */
243 if ((st == BEACON) || (st == PROBE_RSP))
244 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
245
246 cap_info = data[index];
247 cap_info |= (data[index + 1] << 8);
248
249 return cap_info;
250}
251
252/* This function extracts the capability info field from the Association */
253/* response frame. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900254static inline u16 get_assoc_resp_cap_info(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900255{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530256 u16 cap_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900257
258 cap_info = data[0];
259 cap_info |= (data[1] << 8);
260
261 return cap_info;
262}
263
Aybuke Ozdemir960819a2015-10-06 22:14:02 +0300264/* This function extracts the association status code from the incoming */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900265/* association response frame and returns association status code */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900266static inline u16 get_asoc_status(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900267{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530268 u16 asoc_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900269
270 asoc_status = data[3];
271 asoc_status = (asoc_status << 8) | data[2];
272
273 return asoc_status;
274}
275
276/* This function extracts association ID from the incoming association */
277/* response frame */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900278static inline u16 get_asoc_id(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900279{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530280 u16 asoc_id;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900281
282 asoc_id = data[4];
283 asoc_id |= (data[5] << 8);
284
285 return asoc_id;
286}
287
Chaehyun Limd85f5322015-06-11 14:35:54 +0900288u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900289{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530290 u16 u16index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900291
292 /*************************************************************************/
293 /* Beacon Frame - Frame Body */
294 /* --------------------------------------------------------------------- */
295 /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm | */
296 /* --------------------------------------------------------------------- */
297 /* |8 |2 |2 |2-34 |3-10 |3 |4-256 | */
298 /* --------------------------------------------------------------------- */
299 /* */
300 /*************************************************************************/
301
302 u16index = u16TagParamOffset;
303
304 /* Search for the TIM Element Field and return if the element is found */
305 while (u16index < (u16RxLen - FCS_LEN)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530306 if (pu8msa[u16index] == ITIM)
Stanislav Kholmanskikhcea3b202015-06-10 21:57:25 +0300307 return &pu8msa[u16index];
Aybuke Ozdemir86e41802015-10-17 15:25:34 +0300308 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900309 }
310
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530311 return NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900312}
313
314/* This function gets the current channel information from
315 * the 802.11n beacon/probe response frame */
Chaehyun Limd85f5322015-06-11 14:35:54 +0900316u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900317{
Chaehyun Limd85f5322015-06-11 14:35:54 +0900318 u16 index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900319
320 index = TAG_PARAM_OFFSET;
321 while (index < (u16RxLen - FCS_LEN)) {
322 if (pu8msa[index] == IDSPARMS)
Stanislav Kholmanskikhcea3b202015-06-10 21:57:25 +0300323 return pu8msa[index + 2];
Aybuke Ozdemir86e41802015-10-17 15:25:34 +0300324 /* Increment index by length information and header */
325 index += pu8msa[index + 1] + IE_HDR_LEN;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900326 }
327
328 /* Return current channel information from the MIB, if beacon/probe */
329 /* response frame does not contain the DS parameter set IE */
330 /* return (mget_CurrentChannel() + 1); */
331 return 0; /* no MIB here */
332}
333
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900334/**
335 * @brief parses the received 'N' message
336 * @details
337 * @param[in] pu8MsgBuffer The message to be parsed
338 * @param[out] ppstrNetworkInfo pointer to pointer to the structure containing the parsed Network Info
339 * @return Error code indicating success/failure
340 * @note
341 * @author mabubakr
342 * @date 1 Mar 2012
343 * @version 1.0
344 */
Chaehyun Lima1f7f642015-09-22 22:47:44 +0900345s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900346{
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900347 tstrNetworkInfo *pstrNetworkInfo = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900348 u8 u8MsgType = 0;
349 u8 u8MsgID = 0;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900350 u16 u16MsgLen = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900351
Chaehyun Limd85f5322015-06-11 14:35:54 +0900352 u16 u16WidID = (u16)WID_NIL;
353 u16 u16WidLen = 0;
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530354 u8 *pu8WidVal = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900355
356 u8MsgType = pu8MsgBuffer[0];
357
358 /* Check whether the received message type is 'N' */
359 if ('N' != u8MsgType) {
360 PRINT_ER("Received Message format incorrect.\n");
Leo Kim24db7132015-09-16 18:36:01 +0900361 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900362 }
363
364 /* Extract message ID */
365 u8MsgID = pu8MsgBuffer[1];
366
367 /* Extract message Length */
368 u16MsgLen = MAKE_WORD16(pu8MsgBuffer[2], pu8MsgBuffer[3]);
369
370 /* Extract WID ID */
371 u16WidID = MAKE_WORD16(pu8MsgBuffer[4], pu8MsgBuffer[5]);
372
373 /* Extract WID Length */
374 u16WidLen = MAKE_WORD16(pu8MsgBuffer[6], pu8MsgBuffer[7]);
375
376 /* Assign a pointer to the WID value */
377 pu8WidVal = &pu8MsgBuffer[8];
378
379 /* parse the WID value of the WID "WID_NEWORK_INFO" */
380 {
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530381 u8 *pu8msa = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900382 u16 u16RxLen = 0;
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530383 u8 *pu8TimElm = NULL;
384 u8 *pu8IEs = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900385 u16 u16IEsLen = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900386 u8 u8index = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900387 u32 u32Tsf_Lo;
388 u32 u32Tsf_Hi;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900389
Chaehyun Limef154412015-09-22 22:47:39 +0900390 pstrNetworkInfo = kzalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900391 if (!pstrNetworkInfo)
392 return -ENOMEM;
393
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900394 pstrNetworkInfo->s8rssi = pu8WidVal[0];
395
396 /* Assign a pointer to msa "Mac Header Start Address" */
397 pu8msa = &pu8WidVal[1];
398
399 u16RxLen = u16WidLen - 1;
400
401 /* parse msa*/
402
403 /* Get the cap_info */
404 pstrNetworkInfo->u16CapInfo = get_cap_info(pu8msa);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900405 /* Get time-stamp [Low only 32 bit] */
406 pstrNetworkInfo->u32Tsf = get_beacon_timestamp_lo(pu8msa);
407 PRINT_D(CORECONFIG_DBG, "TSF :%x\n", pstrNetworkInfo->u32Tsf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900408
409 /* Get full time-stamp [Low and High 64 bit] */
410 u32Tsf_Lo = get_beacon_timestamp_lo(pu8msa);
411 u32Tsf_Hi = get_beacon_timestamp_hi(pu8msa);
412
Chaehyun Lim57b298f2015-06-11 14:35:56 +0900413 pstrNetworkInfo->u64Tsf = u32Tsf_Lo | ((u64)u32Tsf_Hi << 32);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900414
415 /* Get SSID */
Aybuke Ozdemir09c02cb2015-10-17 15:25:35 +0300416 get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &pstrNetworkInfo->u8SsidLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900417
418 /* Get BSSID */
419 get_BSSID(pu8msa, pstrNetworkInfo->au8bssid);
420
Shivani Bhardwaja66907d2015-10-26 20:21:05 +0530421 /*
422 * Extract current channel information from
423 * the beacon/probe response frame
424 */
425 pstrNetworkInfo->u8channel = get_current_channel_802_11n(pu8msa,
Shivani Bhardwajb5c4e4e2015-10-26 20:21:26 +0530426 u16RxLen + FCS_LEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900427
428 /* Get beacon period */
Shivani Bhardwajb5c4e4e2015-10-26 20:21:26 +0530429 u8index = MAC_HDR_LEN + TIME_STAMP_LEN;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900430
431 pstrNetworkInfo->u16BeaconPeriod = get_beacon_period(pu8msa + u8index);
432
433 u8index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
434
435 /* Get DTIM Period */
Shivani Bhardwajb5c4e4e2015-10-26 20:21:26 +0530436 pu8TimElm = get_tim_elm(pu8msa, u16RxLen + FCS_LEN, u8index);
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530437 if (pu8TimElm != NULL)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900438 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900439 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
440 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
441
442 if (u16IEsLen > 0) {
Chaehyun Lim02cf2992015-09-22 22:47:40 +0900443 pstrNetworkInfo->pu8IEs = kmemdup(pu8IEs, u16IEsLen,
444 GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900445 if (!pstrNetworkInfo->pu8IEs)
446 return -ENOMEM;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900447 }
448 pstrNetworkInfo->u16IEsLen = u16IEsLen;
449
450 }
451
452 *ppstrNetworkInfo = pstrNetworkInfo;
453
Chaehyun Lim74a443e2015-09-22 22:47:45 +0900454 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900455}
456
457/**
458 * @brief Deallocates the parsed Network Info
459 * @details
460 * @param[in] pstrNetworkInfo Network Info to be deallocated
461 * @return Error code indicating success/failure
462 * @note
463 * @author mabubakr
464 * @date 1 Mar 2012
465 * @version 1.0
466 */
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900467s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900468{
Leo Kime6e12662015-09-16 18:36:03 +0900469 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900471 if (pstrNetworkInfo != NULL) {
472 if (pstrNetworkInfo->pu8IEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900473 kfree(pstrNetworkInfo->pu8IEs);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900474 pstrNetworkInfo->pu8IEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900475 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900476 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900477 }
478
Chaehyun Lim49188af2015-08-11 10:32:41 +0900479 kfree(pstrNetworkInfo);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900480 pstrNetworkInfo = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900481
482 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900483 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900484 }
485
486 return s32Error;
487}
488
489/**
490 * @brief parses the received Association Response frame
491 * @details
492 * @param[in] pu8Buffer The Association Response frame to be parsed
493 * @param[out] ppstrConnectRespInfo pointer to pointer to the structure containing the parsed Association Response Info
494 * @return Error code indicating success/failure
495 * @note
496 * @author mabubakr
497 * @date 2 Apr 2012
498 * @version 1.0
499 */
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900500s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900501 tstrConnectRespInfo **ppstrConnectRespInfo)
502{
Leo Kime6e12662015-09-16 18:36:03 +0900503 s32 s32Error = 0;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900504 tstrConnectRespInfo *pstrConnectRespInfo = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900505 u16 u16AssocRespLen = 0;
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530506 u8 *pu8IEs = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900507 u16 u16IEsLen = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900508
Chaehyun Limef154412015-09-22 22:47:39 +0900509 pstrConnectRespInfo = kzalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900510 if (!pstrConnectRespInfo)
511 return -ENOMEM;
512
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900513 /* u16AssocRespLen = pu8Buffer[0]; */
Chaehyun Limd85f5322015-06-11 14:35:54 +0900514 u16AssocRespLen = (u16)u32BufferLen;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900515
516 /* get the status code */
517 pstrConnectRespInfo->u16ConnectStatus = get_asoc_status(pu8Buffer);
518 if (pstrConnectRespInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
519
520 /* get the capability */
521 pstrConnectRespInfo->u16capability = get_assoc_resp_cap_info(pu8Buffer);
522
523 /* get the Association ID */
524 pstrConnectRespInfo->u16AssocID = get_asoc_id(pu8Buffer);
525
526 /* get the Information Elements */
527 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
528 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
529
Chaehyun Lim02cf2992015-09-22 22:47:40 +0900530 pstrConnectRespInfo->pu8RespIEs = kmemdup(pu8IEs, u16IEsLen, GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900531 if (!pstrConnectRespInfo->pu8RespIEs)
532 return -ENOMEM;
533
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900534 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
535 }
536
537 *ppstrConnectRespInfo = pstrConnectRespInfo;
538
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900539 return s32Error;
540}
541
542/**
543 * @brief Deallocates the parsed Association Response Info
544 * @details
545 * @param[in] pstrNetworkInfo Network Info to be deallocated
546 * @return Error code indicating success/failure
547 * @note
548 * @author mabubakr
549 * @date 2 Apr 2012
550 * @version 1.0
551 */
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900552s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900553{
Leo Kime6e12662015-09-16 18:36:03 +0900554 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900555
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900556 if (pstrConnectRespInfo != NULL) {
557 if (pstrConnectRespInfo->pu8RespIEs != NULL) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900558 kfree(pstrConnectRespInfo->pu8RespIEs);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900559 pstrConnectRespInfo->pu8RespIEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900560 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900561 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900562 }
563
Chaehyun Lim49188af2015-08-11 10:32:41 +0900564 kfree(pstrConnectRespInfo);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900565 pstrConnectRespInfo = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900566
567 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900568 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900569 }
570
571 return s32Error;
572}
573
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900574/**
575 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
576 * using driver config layer
577 *
578 * @details
579 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
580 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
581 * @param[out] pu8RxResp The received Packet Response
582 * @param[out] ps32RxRespLen Length of the received Packet Response
583 * @return Error code indicating success/failure
584 * @note
585 * @author mabubakr
586 * @date 1 Mar 2012
587 * @version 1.0
588 */
Leo Kime9e0c262015-10-12 16:55:41 +0900589s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900590{
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900591 s32 counter = 0, ret = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900592
Tony Cho684125a2015-10-12 16:55:40 +0900593 if (mode == GET_CFG) {
594 for (counter = 0; counter < count; counter++) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900595 PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter,
Tony Cho684125a2015-10-12 16:55:40 +0900596 (counter == count - 1));
Glen Lee07056a82015-10-01 16:03:41 +0900597 if (!wilc_wlan_cfg_get(!counter,
Leo Kimdaaf16b2015-10-12 16:55:44 +0900598 wids[counter].id,
Tony Cho684125a2015-10-12 16:55:40 +0900599 (counter == count - 1),
600 drv)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900601 ret = -1;
602 printk("[Sendconfigpkt]Get Timed out\n");
603 break;
604 }
605 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900606 counter = 0;
Tony Cho684125a2015-10-12 16:55:40 +0900607 for (counter = 0; counter < count; counter++) {
Leo Kim2fd3e442015-10-12 16:55:45 +0900608 wids[counter].size = wilc_wlan_cfg_get_val(
Leo Kimdaaf16b2015-10-12 16:55:44 +0900609 wids[counter].id,
Leo Kim900bb4a2015-10-12 16:55:46 +0900610 wids[counter].val,
Leo Kim2fd3e442015-10-12 16:55:45 +0900611 wids[counter].size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900612
613 }
Tony Cho684125a2015-10-12 16:55:40 +0900614 } else if (mode == SET_CFG) {
615 for (counter = 0; counter < count; counter++) {
Leo Kimdaaf16b2015-10-12 16:55:44 +0900616 PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", wids[counter].id);
Glen Lee1028e5a2015-10-01 16:03:40 +0900617 if (!wilc_wlan_cfg_set(!counter,
Leo Kimdaaf16b2015-10-12 16:55:44 +0900618 wids[counter].id,
Leo Kim900bb4a2015-10-12 16:55:46 +0900619 wids[counter].val,
Leo Kim2fd3e442015-10-12 16:55:45 +0900620 wids[counter].size,
Tony Cho684125a2015-10-12 16:55:40 +0900621 (counter == count - 1),
622 drv)) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900623 ret = -1;
624 printk("[Sendconfigpkt]Set Timed out\n");
625 break;
626 }
627 }
628 }
629
630 return ret;
631}