blob: 2d4d3f190c01317d0a514cb9aa301011ca69fcf4 [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>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090016#define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
17 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
18
Johnny Kimc5c77ba2015-05-11 14:30:56 +090019/* Basic Frame Type Codes (2-bit) */
Tony Cho9dd2f772015-10-02 14:22:03 +090020enum basic_frame_type {
Stanislav Kholmanskikh13994d12015-06-10 21:57:26 +030021 FRAME_TYPE_CONTROL = 0x04,
22 FRAME_TYPE_DATA = 0x08,
23 FRAME_TYPE_MANAGEMENT = 0x00,
24 FRAME_TYPE_RESERVED = 0x0C,
25 FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
Tony Cho9dd2f772015-10-02 14:22:03 +090026};
Johnny Kimc5c77ba2015-05-11 14:30:56 +090027
28/* Frame Type and Subtype Codes (6-bit) */
Tony Cho9dd2f772015-10-02 14:22:03 +090029enum sub_frame_type {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090030 ASSOC_REQ = 0x00,
31 ASSOC_RSP = 0x10,
32 REASSOC_REQ = 0x20,
33 REASSOC_RSP = 0x30,
34 PROBE_REQ = 0x40,
35 PROBE_RSP = 0x50,
36 BEACON = 0x80,
37 ATIM = 0x90,
38 DISASOC = 0xA0,
39 AUTH = 0xB0,
40 DEAUTH = 0xC0,
41 ACTION = 0xD0,
42 PS_POLL = 0xA4,
43 RTS = 0xB4,
44 CTS = 0xC4,
45 ACK = 0xD4,
46 CFEND = 0xE4,
47 CFEND_ACK = 0xF4,
48 DATA = 0x08,
49 DATA_ACK = 0x18,
50 DATA_POLL = 0x28,
51 DATA_POLL_ACK = 0x38,
52 NULL_FRAME = 0x48,
53 CFACK = 0x58,
54 CFPOLL = 0x68,
55 CFPOLL_ACK = 0x78,
56 QOS_DATA = 0x88,
57 QOS_DATA_ACK = 0x98,
58 QOS_DATA_POLL = 0xA8,
59 QOS_DATA_POLL_ACK = 0xB8,
60 QOS_NULL_FRAME = 0xC8,
61 QOS_CFPOLL = 0xE8,
62 QOS_CFPOLL_ACK = 0xF8,
63 BLOCKACK_REQ = 0x84,
64 BLOCKACK = 0x94,
65 FRAME_SUBTYPE_FORCE_32BIT = 0xFFFFFFFF
Tony Cho9dd2f772015-10-02 14:22:03 +090066};
Johnny Kimc5c77ba2015-05-11 14:30:56 +090067
Johnny Kimc5c77ba2015-05-11 14:30:56 +090068/* Element ID of various Information Elements */
Tony Cho9dd2f772015-10-02 14:22:03 +090069enum info_element_id {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090070 ISSID = 0, /* Service Set Identifier */
71 ISUPRATES = 1, /* Supported Rates */
72 IFHPARMS = 2, /* FH parameter set */
73 IDSPARMS = 3, /* DS parameter set */
74 ICFPARMS = 4, /* CF parameter set */
75 ITIM = 5, /* Traffic Information Map */
76 IIBPARMS = 6, /* IBSS parameter set */
77 ICOUNTRY = 7, /* Country element */
78 IEDCAPARAMS = 12, /* EDCA parameter set */
79 ITSPEC = 13, /* Traffic Specification */
80 ITCLAS = 14, /* Traffic Classification */
81 ISCHED = 15, /* Schedule */
82 ICTEXT = 16, /* Challenge Text */
83 IPOWERCONSTRAINT = 32, /* Power Constraint */
84 IPOWERCAPABILITY = 33, /* Power Capability */
85 ITPCREQUEST = 34, /* TPC Request */
86 ITPCREPORT = 35, /* TPC Report */
87 ISUPCHANNEL = 36, /* Supported channel list */
88 ICHSWANNOUNC = 37, /* Channel Switch Announcement */
89 IMEASUREMENTREQUEST = 38, /* Measurement request */
90 IMEASUREMENTREPORT = 39, /* Measurement report */
91 IQUIET = 40, /* Quiet element Info */
92 IIBSSDFS = 41, /* IBSS DFS */
93 IERPINFO = 42, /* ERP Information */
94 ITSDELAY = 43, /* TS Delay */
95 ITCLASPROCESS = 44, /* TCLAS Processing */
96 IHTCAP = 45, /* HT Capabilities */
97 IQOSCAP = 46, /* QoS Capability */
98 IRSNELEMENT = 48, /* RSN Information Element */
99 IEXSUPRATES = 50, /* Extended Supported Rates */
100 IEXCHSWANNOUNC = 60, /* Extended Ch Switch Announcement*/
101 IHTOPERATION = 61, /* HT Information */
102 ISECCHOFF = 62, /* Secondary Channel Offeset */
103 I2040COEX = 72, /* 20/40 Coexistence IE */
104 I2040INTOLCHREPORT = 73, /* 20/40 Intolerant channel report*/
105 IOBSSSCAN = 74, /* OBSS Scan parameters */
106 IEXTCAP = 127, /* Extended capability */
107 IWMM = 221, /* WMM parameters */
108 IWPAELEMENT = 221, /* WPA Information Element */
109 INFOELEM_ID_FORCE_32BIT = 0xFFFFFFFF
Tony Cho9dd2f772015-10-02 14:22:03 +0900110};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900111
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900112/* This function extracts the beacon period field from the beacon or probe */
113/* response frame. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900114static inline u16 get_beacon_period(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900115{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530116 u16 bcn_per;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900117
118 bcn_per = data[0];
119 bcn_per |= (data[1] << 8);
120
121 return bcn_per;
122}
123
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900124static inline u32 get_beacon_timestamp_lo(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900125{
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900126 u32 time_stamp = 0;
127 u32 index = MAC_HDR_LEN;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900128
129 time_stamp |= data[index++];
130 time_stamp |= (data[index++] << 8);
131 time_stamp |= (data[index++] << 16);
132 time_stamp |= (data[index] << 24);
133
134 return time_stamp;
135}
136
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900137static inline u32 get_beacon_timestamp_hi(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900138{
Chaehyun Lim8a54d912015-06-11 14:35:53 +0900139 u32 time_stamp = 0;
140 u32 index = (MAC_HDR_LEN + 4);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900141
142 time_stamp |= data[index++];
143 time_stamp |= (data[index++] << 8);
144 time_stamp |= (data[index++] << 16);
145 time_stamp |= (data[index] << 24);
146
147 return time_stamp;
148}
149
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900150/* This function extracts the 'frame type and sub type' bits from the MAC */
151/* header of the input frame. */
152/* Returns the value in the LSB of the returned value. */
Tony Cho9dd2f772015-10-02 14:22:03 +0900153static inline enum sub_frame_type get_sub_type(u8 *header)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900154{
Tony Cho9dd2f772015-10-02 14:22:03 +0900155 return ((enum sub_frame_type)(header[0] & 0xFC));
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900156}
157
158/* This function extracts the 'to ds' bit from the MAC header of the input */
159/* frame. */
160/* Returns the value in the LSB of the returned value. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900161static inline u8 get_to_ds(u8 *header)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900162{
163 return (header[1] & 0x01);
164}
165
166/* This function extracts the 'from ds' bit from the MAC header of the input */
167/* frame. */
168/* Returns the value in the LSB of the returned value. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900169static inline u8 get_from_ds(u8 *header)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900170{
171 return ((header[1] & 0x02) >> 1);
172}
173
Glen Leeb57f9f32015-11-05 18:51:23 +0900174/* This function extracts the MAC Address in 'address1' field of the MAC */
175/* header and updates the MAC Address in the allocated 'addr' variable. */
176static inline void get_address1(u8 *pu8msa, u8 *addr)
177{
178 memcpy(addr, pu8msa + 4, 6);
179}
180
181/* This function extracts the MAC Address in 'address2' field of the MAC */
182/* header and updates the MAC Address in the allocated 'addr' variable. */
183static inline void get_address2(u8 *pu8msa, u8 *addr)
184{
185 memcpy(addr, pu8msa + 10, 6);
186}
187
188/* This function extracts the MAC Address in 'address3' field of the MAC */
189/* header and updates the MAC Address in the allocated 'addr' variable. */
190static inline void get_address3(u8 *pu8msa, u8 *addr)
191{
192 memcpy(addr, pu8msa + 16, 6);
193}
194
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900195/* This function extracts the BSSID from the incoming WLAN packet based on */
Glen Leeb57f9f32015-11-05 18:51:23 +0900196/* the 'from ds' bit, and updates the MAC Address in the allocated 'addr' */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197/* variable. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900198static inline void get_BSSID(u8 *data, u8 *bssid)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900199{
200 if (get_from_ds(data) == 1)
Glen Leeb57f9f32015-11-05 18:51:23 +0900201 get_address2(data, bssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900202 else if (get_to_ds(data) == 1)
Glen Leeb57f9f32015-11-05 18:51:23 +0900203 get_address1(data, bssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900204 else
Glen Leeb57f9f32015-11-05 18:51:23 +0900205 get_address3(data, bssid);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900206}
207
208/* This function extracts the SSID from a beacon/probe response frame */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900209static inline void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210{
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900211 u8 len = 0;
212 u8 i = 0;
213 u8 j = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900214
215 len = data[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
216 CAP_INFO_LEN + 1];
217 j = MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
218 CAP_INFO_LEN + 2;
219
220 /* If the SSID length field is set wrongly to a value greater than the */
221 /* allowed maximum SSID length limit, reset the length to 0 */
222 if (len >= MAX_SSID_LEN)
223 len = 0;
224
225 for (i = 0; i < len; i++, j++)
226 ssid[i] = data[j];
227
228 ssid[len] = '\0';
229
230 *p_ssid_len = len;
231}
232
233/* This function extracts the capability info field from the beacon or probe */
234/* response frame. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900235static inline u16 get_cap_info(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900236{
Chaehyun Limd85f5322015-06-11 14:35:54 +0900237 u16 cap_info = 0;
238 u16 index = MAC_HDR_LEN;
Tony Cho9dd2f772015-10-02 14:22:03 +0900239 enum sub_frame_type st;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900240
241 st = get_sub_type(data);
242
243 /* Location of the Capability field is different for Beacon and */
244 /* Association frames. */
245 if ((st == BEACON) || (st == PROBE_RSP))
246 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
247
248 cap_info = data[index];
249 cap_info |= (data[index + 1] << 8);
250
251 return cap_info;
252}
253
254/* This function extracts the capability info field from the Association */
255/* response frame. */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900256static inline u16 get_assoc_resp_cap_info(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900257{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530258 u16 cap_info;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900259
260 cap_info = data[0];
261 cap_info |= (data[1] << 8);
262
263 return cap_info;
264}
265
Aybuke Ozdemir960819a2015-10-06 22:14:02 +0300266/* This function extracts the association status code from the incoming */
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900267/* association response frame and returns association status code */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900268static inline u16 get_asoc_status(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900269{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530270 u16 asoc_status;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900271
272 asoc_status = data[3];
273 asoc_status = (asoc_status << 8) | data[2];
274
275 return asoc_status;
276}
277
278/* This function extracts association ID from the incoming association */
279/* response frame */
Chaehyun Lim9af382b2015-09-16 20:11:27 +0900280static inline u16 get_asoc_id(u8 *data)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900281{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530282 u16 asoc_id;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900283
284 asoc_id = data[4];
285 asoc_id |= (data[5] << 8);
286
287 return asoc_id;
288}
289
Arnd Bergmann1608c402015-11-16 15:04:53 +0100290static u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900291{
Amitoj Kaur Chawlab5c84cd2015-10-15 13:49:47 +0530292 u16 u16index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900293
294 /*************************************************************************/
295 /* Beacon Frame - Frame Body */
296 /* --------------------------------------------------------------------- */
297 /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm | */
298 /* --------------------------------------------------------------------- */
299 /* |8 |2 |2 |2-34 |3-10 |3 |4-256 | */
300 /* --------------------------------------------------------------------- */
301 /* */
302 /*************************************************************************/
303
304 u16index = u16TagParamOffset;
305
306 /* Search for the TIM Element Field and return if the element is found */
307 while (u16index < (u16RxLen - FCS_LEN)) {
Chandra S Gorentla78174ad2015-08-08 17:41:36 +0530308 if (pu8msa[u16index] == ITIM)
Stanislav Kholmanskikhcea3b202015-06-10 21:57:25 +0300309 return &pu8msa[u16index];
Aybuke Ozdemir86e41802015-10-17 15:25:34 +0300310 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900311 }
312
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530313 return NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900314}
315
316/* This function gets the current channel information from
317 * the 802.11n beacon/probe response frame */
Arnd Bergmann1608c402015-11-16 15:04:53 +0100318static u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900319{
Chaehyun Limd85f5322015-06-11 14:35:54 +0900320 u16 index;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900321
322 index = TAG_PARAM_OFFSET;
323 while (index < (u16RxLen - FCS_LEN)) {
324 if (pu8msa[index] == IDSPARMS)
Stanislav Kholmanskikhcea3b202015-06-10 21:57:25 +0300325 return pu8msa[index + 2];
Aybuke Ozdemir86e41802015-10-17 15:25:34 +0300326 /* Increment index by length information and header */
327 index += pu8msa[index + 1] + IE_HDR_LEN;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900328 }
329
330 /* Return current channel information from the MIB, if beacon/probe */
331 /* response frame does not contain the DS parameter set IE */
332 /* return (mget_CurrentChannel() + 1); */
333 return 0; /* no MIB here */
334}
335
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900336/**
337 * @brief parses the received 'N' message
338 * @details
339 * @param[in] pu8MsgBuffer The message to be parsed
340 * @param[out] ppstrNetworkInfo pointer to pointer to the structure containing the parsed Network Info
341 * @return Error code indicating success/failure
342 * @note
343 * @author mabubakr
344 * @date 1 Mar 2012
345 * @version 1.0
346 */
Arnd Bergmann0e1af732015-11-16 15:04:54 +0100347s32 wilc_parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900348{
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900349 tstrNetworkInfo *pstrNetworkInfo = NULL;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900350 u8 u8MsgType = 0;
351 u8 u8MsgID = 0;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900352 u16 u16MsgLen = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900353
Chaehyun Limd85f5322015-06-11 14:35:54 +0900354 u16 u16WidID = (u16)WID_NIL;
355 u16 u16WidLen = 0;
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530356 u8 *pu8WidVal = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900357
358 u8MsgType = pu8MsgBuffer[0];
359
360 /* Check whether the received message type is 'N' */
361 if ('N' != u8MsgType) {
362 PRINT_ER("Received Message format incorrect.\n");
Leo Kim24db7132015-09-16 18:36:01 +0900363 return -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900364 }
365
366 /* Extract message ID */
367 u8MsgID = pu8MsgBuffer[1];
368
369 /* Extract message Length */
370 u16MsgLen = MAKE_WORD16(pu8MsgBuffer[2], pu8MsgBuffer[3]);
371
372 /* Extract WID ID */
373 u16WidID = MAKE_WORD16(pu8MsgBuffer[4], pu8MsgBuffer[5]);
374
375 /* Extract WID Length */
376 u16WidLen = MAKE_WORD16(pu8MsgBuffer[6], pu8MsgBuffer[7]);
377
378 /* Assign a pointer to the WID value */
379 pu8WidVal = &pu8MsgBuffer[8];
380
381 /* parse the WID value of the WID "WID_NEWORK_INFO" */
382 {
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530383 u8 *pu8msa = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900384 u16 u16RxLen = 0;
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530385 u8 *pu8TimElm = NULL;
386 u8 *pu8IEs = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900387 u16 u16IEsLen = 0;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900388 u8 u8index = 0;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900389 u32 u32Tsf_Lo;
390 u32 u32Tsf_Hi;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900391
Chaehyun Limef154412015-09-22 22:47:39 +0900392 pstrNetworkInfo = kzalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900393 if (!pstrNetworkInfo)
394 return -ENOMEM;
395
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900396 pstrNetworkInfo->s8rssi = pu8WidVal[0];
397
398 /* Assign a pointer to msa "Mac Header Start Address" */
399 pu8msa = &pu8WidVal[1];
400
401 u16RxLen = u16WidLen - 1;
402
403 /* parse msa*/
404
405 /* Get the cap_info */
406 pstrNetworkInfo->u16CapInfo = get_cap_info(pu8msa);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900407 /* Get time-stamp [Low only 32 bit] */
408 pstrNetworkInfo->u32Tsf = get_beacon_timestamp_lo(pu8msa);
409 PRINT_D(CORECONFIG_DBG, "TSF :%x\n", pstrNetworkInfo->u32Tsf);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900410
411 /* Get full time-stamp [Low and High 64 bit] */
412 u32Tsf_Lo = get_beacon_timestamp_lo(pu8msa);
413 u32Tsf_Hi = get_beacon_timestamp_hi(pu8msa);
414
Chaehyun Lim57b298f2015-06-11 14:35:56 +0900415 pstrNetworkInfo->u64Tsf = u32Tsf_Lo | ((u64)u32Tsf_Hi << 32);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900416
417 /* Get SSID */
Aybuke Ozdemir09c02cb2015-10-17 15:25:35 +0300418 get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &pstrNetworkInfo->u8SsidLen);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900419
420 /* Get BSSID */
421 get_BSSID(pu8msa, pstrNetworkInfo->au8bssid);
422
Shivani Bhardwajce081892015-10-27 22:58:06 +0530423 /*
Shivani Bhardwaja66907d2015-10-26 20:21:05 +0530424 * Extract current channel information from
Shivani Bhardwajce081892015-10-27 22:58:06 +0530425 * the beacon/probe response frame
Shivani Bhardwaja66907d2015-10-26 20:21:05 +0530426 */
427 pstrNetworkInfo->u8channel = get_current_channel_802_11n(pu8msa,
Shivani Bhardwajb5c4e4e2015-10-26 20:21:26 +0530428 u16RxLen + FCS_LEN);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900429
430 /* Get beacon period */
Shivani Bhardwajb5c4e4e2015-10-26 20:21:26 +0530431 u8index = MAC_HDR_LEN + TIME_STAMP_LEN;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900432
433 pstrNetworkInfo->u16BeaconPeriod = get_beacon_period(pu8msa + u8index);
434
435 u8index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
436
437 /* Get DTIM Period */
Shivani Bhardwajb5c4e4e2015-10-26 20:21:26 +0530438 pu8TimElm = get_tim_elm(pu8msa, u16RxLen + FCS_LEN, u8index);
Bogicevic Sasaf6e0e2a2015-11-18 12:45:05 +0100439 if (pu8TimElm)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900440 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900441 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
442 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
443
444 if (u16IEsLen > 0) {
Chaehyun Lim02cf2992015-09-22 22:47:40 +0900445 pstrNetworkInfo->pu8IEs = kmemdup(pu8IEs, u16IEsLen,
446 GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900447 if (!pstrNetworkInfo->pu8IEs)
448 return -ENOMEM;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900449 }
450 pstrNetworkInfo->u16IEsLen = u16IEsLen;
451
452 }
453
454 *ppstrNetworkInfo = pstrNetworkInfo;
455
Chaehyun Lim74a443e2015-09-22 22:47:45 +0900456 return 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900457}
458
459/**
460 * @brief Deallocates the parsed Network Info
461 * @details
462 * @param[in] pstrNetworkInfo Network Info to be deallocated
463 * @return Error code indicating success/failure
464 * @note
465 * @author mabubakr
466 * @date 1 Mar 2012
467 * @version 1.0
468 */
Arnd Bergmann0e1af732015-11-16 15:04:54 +0100469s32 wilc_dealloc_network_info(tstrNetworkInfo *pstrNetworkInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900470{
Leo Kime6e12662015-09-16 18:36:03 +0900471 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900472
Bogicevic Sasaf6e0e2a2015-11-18 12:45:05 +0100473 if (pstrNetworkInfo) {
474 if (pstrNetworkInfo->pu8IEs) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900475 kfree(pstrNetworkInfo->pu8IEs);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900476 pstrNetworkInfo->pu8IEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900477 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900478 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900479 }
480
Chaehyun Lim49188af2015-08-11 10:32:41 +0900481 kfree(pstrNetworkInfo);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900482 pstrNetworkInfo = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900483
484 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900485 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900486 }
487
488 return s32Error;
489}
490
491/**
492 * @brief parses the received Association Response frame
493 * @details
494 * @param[in] pu8Buffer The Association Response frame to be parsed
495 * @param[out] ppstrConnectRespInfo pointer to pointer to the structure containing the parsed Association Response Info
496 * @return Error code indicating success/failure
497 * @note
498 * @author mabubakr
499 * @date 2 Apr 2012
500 * @version 1.0
501 */
Arnd Bergmann0e1af732015-11-16 15:04:54 +0100502s32 wilc_parse_assoc_resp_info(u8 *pu8Buffer, u32 u32BufferLen,
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900503 tstrConnectRespInfo **ppstrConnectRespInfo)
504{
Leo Kime6e12662015-09-16 18:36:03 +0900505 s32 s32Error = 0;
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900506 tstrConnectRespInfo *pstrConnectRespInfo = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900507 u16 u16AssocRespLen = 0;
Ronit Halder0e04f3f2015-09-14 11:03:34 +0530508 u8 *pu8IEs = NULL;
Chaehyun Limd85f5322015-06-11 14:35:54 +0900509 u16 u16IEsLen = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900510
Chaehyun Limef154412015-09-22 22:47:39 +0900511 pstrConnectRespInfo = kzalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900512 if (!pstrConnectRespInfo)
513 return -ENOMEM;
514
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900515 /* u16AssocRespLen = pu8Buffer[0]; */
Chaehyun Limd85f5322015-06-11 14:35:54 +0900516 u16AssocRespLen = (u16)u32BufferLen;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900517
518 /* get the status code */
519 pstrConnectRespInfo->u16ConnectStatus = get_asoc_status(pu8Buffer);
520 if (pstrConnectRespInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
521
522 /* get the capability */
523 pstrConnectRespInfo->u16capability = get_assoc_resp_cap_info(pu8Buffer);
524
525 /* get the Association ID */
526 pstrConnectRespInfo->u16AssocID = get_asoc_id(pu8Buffer);
527
528 /* get the Information Elements */
529 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
530 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
531
Chaehyun Lim02cf2992015-09-22 22:47:40 +0900532 pstrConnectRespInfo->pu8RespIEs = kmemdup(pu8IEs, u16IEsLen, GFP_KERNEL);
Chaehyun Lima78d9a32015-08-17 11:05:15 +0900533 if (!pstrConnectRespInfo->pu8RespIEs)
534 return -ENOMEM;
535
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900536 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
537 }
538
539 *ppstrConnectRespInfo = pstrConnectRespInfo;
540
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900541 return s32Error;
542}
543
544/**
545 * @brief Deallocates the parsed Association Response Info
546 * @details
547 * @param[in] pstrNetworkInfo Network Info to be deallocated
548 * @return Error code indicating success/failure
549 * @note
550 * @author mabubakr
551 * @date 2 Apr 2012
552 * @version 1.0
553 */
Arnd Bergmann0e1af732015-11-16 15:04:54 +0100554s32 wilc_dealloc_assoc_resp_info(tstrConnectRespInfo *pstrConnectRespInfo)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900555{
Leo Kime6e12662015-09-16 18:36:03 +0900556 s32 s32Error = 0;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900557
Bogicevic Sasaf6e0e2a2015-11-18 12:45:05 +0100558 if (pstrConnectRespInfo) {
559 if (pstrConnectRespInfo->pu8RespIEs) {
Chaehyun Lim49188af2015-08-11 10:32:41 +0900560 kfree(pstrConnectRespInfo->pu8RespIEs);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900561 pstrConnectRespInfo->pu8RespIEs = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900562 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900563 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900564 }
565
Chaehyun Lim49188af2015-08-11 10:32:41 +0900566 kfree(pstrConnectRespInfo);
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900567 pstrConnectRespInfo = NULL;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900568
569 } else {
Leo Kime6e12662015-09-16 18:36:03 +0900570 s32Error = -EFAULT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900571 }
572
573 return s32Error;
574}
575
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900576/**
577 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
578 * using driver config layer
579 *
580 * @details
581 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
582 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
583 * @param[out] pu8RxResp The received Packet Response
584 * @param[out] ps32RxRespLen Length of the received Packet Response
585 * @return Error code indicating success/failure
586 * @note
587 * @author mabubakr
588 * @date 1 Mar 2012
589 * @version 1.0
590 */
Glen Leeec62e6d2015-11-18 15:11:33 +0900591s32 wilc_send_config_pkt(struct wilc *wilc, u8 mode, struct wid *wids,
592 u32 count, u32 drv)
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900593{
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +0900594 s32 counter = 0, ret = 0;
Chaehyun Lim8dfaafd2015-08-18 23:18:11 +0900595
Tony Cho684125a2015-10-12 16:55:40 +0900596 if (mode == GET_CFG) {
597 for (counter = 0; counter < count; counter++) {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900598 PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter,
Tony Cho684125a2015-10-12 16:55:40 +0900599 (counter == count - 1));
Glen Leed40c99c2015-11-18 15:11:35 +0900600 if (!wilc_wlan_cfg_get(wilc, !counter,
Leo Kimdaaf16b2015-10-12 16:55:44 +0900601 wids[counter].id,
Tony Cho684125a2015-10-12 16:55:40 +0900602 (counter == count - 1),
603 drv)) {
Glen Leec2ba8b22015-11-20 16:56:32 +0900604 ret = -ETIMEDOUT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900605 printk("[Sendconfigpkt]Get Timed out\n");
606 break;
607 }
608 }
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900609 counter = 0;
Tony Cho684125a2015-10-12 16:55:40 +0900610 for (counter = 0; counter < count; counter++) {
Leo Kim2fd3e442015-10-12 16:55:45 +0900611 wids[counter].size = wilc_wlan_cfg_get_val(
Leo Kimdaaf16b2015-10-12 16:55:44 +0900612 wids[counter].id,
Leo Kim900bb4a2015-10-12 16:55:46 +0900613 wids[counter].val,
Leo Kim2fd3e442015-10-12 16:55:45 +0900614 wids[counter].size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900615 }
Tony Cho684125a2015-10-12 16:55:40 +0900616 } else if (mode == SET_CFG) {
617 for (counter = 0; counter < count; counter++) {
Leo Kimdaaf16b2015-10-12 16:55:44 +0900618 PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", wids[counter].id);
Glen Lee89758e12015-11-18 15:11:34 +0900619 if (!wilc_wlan_cfg_set(wilc, !counter,
Leo Kimdaaf16b2015-10-12 16:55:44 +0900620 wids[counter].id,
Leo Kim900bb4a2015-10-12 16:55:46 +0900621 wids[counter].val,
Leo Kim2fd3e442015-10-12 16:55:45 +0900622 wids[counter].size,
Tony Cho684125a2015-10-12 16:55:40 +0900623 (counter == count - 1),
624 drv)) {
Glen Leec2ba8b22015-11-20 16:56:32 +0900625 ret = -ETIMEDOUT;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900626 printk("[Sendconfigpkt]Set Timed out\n");
627 break;
628 }
629 }
630 }
631
632 return ret;
633}