1 /*
2 * Copyright (c) 2021 iSoftStone Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "wifi_mac80211_ops.h"
10 #include "net_adpater.h"
11 #include "hdf_wlan_utils.h"
12 #include "wifi_module.h"
13 #include <net/cfg80211.h>
14 #include <net/regulatory.h>
15 #include "osal_mem.h"
16 #include "hdf_wifi_event.h"
17
18 #define HDF_LOG_TAG Xr829Driver
19 #ifndef errno_t
20 typedef int errno_t;
21 #endif
22
23 #define XR829_POINT_CHANNEL_SIZE (8)
24
25
26 extern struct cfg80211_ops xrmac_config_ops;
27
28 extern NetDevice *get_netDev(void);
29 extern struct wiphy* wrap_get_wiphy(void);
30 extern struct net_device *get_krn_netdev(void);
31 extern struct wireless_dev* wrap_get_widev(void);
32 extern int32_t HdfWifiEventInformBssFrame(const struct NetDevice *netDev, const struct WlanChannel *channel, const struct ScannedBssInfo *bssInfo);
33 extern void xradio_get_mac_addrs(uint8_t *macaddr);
34 extern int set_wifi_custom_mac_address(char *addr_str, uint8_t len);
35 extern int ieee80211_cancel_scan(struct wiphy *wiphy, struct wireless_dev *wdev);
36
37 extern errno_t memset_s(void * dest, size_t dest_max, int ch, size_t count);
38 extern errno_t memcpy_s(void *dest, size_t dest_max, const void *src, size_t count);
39 extern int snprintf_s(char *dest, size_t dest_max, size_t count, const char *format, ...);
40 extern void rtnl_lock(void);
41 extern void rtnl_unlock(void);
42
43 typedef enum {
44 WLAN_BAND_2G,
45 WLAN_BAND_BUTT
46 } wlan_channel_band_enum;
47
48 #define WIFI_24G_CHANNEL_NUMS (14)
49 #define WAL_MIN_CHANNEL_2G (1)
50 #define WAL_MAX_CHANNEL_2G (14)
51 #define WAL_MIN_FREQ_2G (2412 + 5*(WAL_MIN_CHANNEL_2G - 1))
52 #define WAL_MAX_FREQ_2G (2484)
53 #define WAL_FREQ_2G_INTERVAL (5)
54 #define WLAN_WPS_IE_MAX_SIZE (352) // (WLAN_MEM_EVENT_SIZE2 - 32) /* 32表示事件自身占用的空间 */
55 /* Driver supports AP mode */
56 #define HISI_DRIVER_FLAGS_AP 0x00000040
57 /* Driver supports concurrent P2P operations */
58 #define HISI_DRIVER_FLAGS_P2P_CONCURRENT 0x00000200
59
60 #define HISI_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE 0x00000400
61 /* P2P capable (P2P GO or P2P Client) */
62 #define HISI_DRIVER_FLAGS_P2P_CAPABLE 0x00000800
63 /* Driver supports a dedicated interface for P2P Device */
64 #define HISI_DRIVER_FLAGS_DEDICATED_P2P_DEVICE 0x20000000
65
66 struct WlanAssocParams *global_param = NULL;
67
68 typedef struct WlanAssocParams {
69 uint32_t centerFreq; /**< Connection channel. If this parameter is not specified, the connection channel
70 * is automatically obtained from the scan result.
71 */
72 uint8_t bssid[ETH_ADDR_LEN]; /**< AP BSSID. If this parameter is not specified, the AP BSSID is automatically
73 * obtained from the scan result.
74 */
75 uint8_t ssid[OAL_IEEE80211_MAX_SSID_LEN]; /**< SSID */
76 uint32_t ssidLen; /**< SSID length */
77 u8 *ie;
78 size_t ie_len;
79 struct cfg80211_crypto_settings crypto;
80 } WlanAssocParams;
81
82
83 /*--------------------------------------------------------------------------------------------------*/
84 /* public */
85 /*--------------------------------------------------------------------------------------------------*/
GetIfName(enum nl80211_iftype type,char * ifName,uint32_t len)86 static int32_t GetIfName(enum nl80211_iftype type, char *ifName, uint32_t len)
87 {
88 if (ifName == NULL || len == 0) {
89 HDF_LOGE("%s:para is null!", __func__);
90 return HDF_FAILURE;
91 }
92 switch (type) {
93 case NL80211_IFTYPE_P2P_DEVICE:
94 if (snprintf_s(ifName, len, len -1, "p2p%d", 0) < 0) {
95 HDF_LOGE("%s:format ifName failed!", __func__);
96 return HDF_FAILURE;
97 }
98 break;
99 case NL80211_IFTYPE_P2P_CLIENT:
100 /* fall-through */
101 case NL80211_IFTYPE_P2P_GO:
102 if (snprintf_s(ifName, len, len -1, "p2p-p2p0-%d", 0) < 0) {
103 HDF_LOGE("%s:format ifName failed!", __func__);
104 return HDF_FAILURE;
105 }
106 break;
107 default:
108 HDF_LOGE("%s:GetIfName::not supported dev type!", __func__);
109 return HDF_FAILURE;
110 }
111 return HDF_SUCCESS;
112 }
113
WalReleaseHwCapability(struct WlanHwCapability * self)114 void WalReleaseHwCapability(struct WlanHwCapability *self)
115 {
116 uint8_t i;
117 if (self == NULL) {
118 return;
119 }
120 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
121 if (self->bands[i] != NULL) {
122 OsalMemFree(self->bands[i]);
123 self->bands[i] = NULL;
124 }
125 }
126 if (self->supportedRates != NULL) {
127 OsalMemFree(self->supportedRates);
128 self->supportedRates = NULL;
129 }
130 OsalMemFree(self);
131 }
132
GetChannelByFreq(struct wiphy * wiphy,uint16_t center_freq)133 static struct ieee80211_channel *GetChannelByFreq(struct wiphy* wiphy, uint16_t center_freq)
134 {
135 enum Ieee80211Band band;
136 struct ieee80211_supported_band *currentBand = NULL;
137 int32_t loop;
138 for (band = (enum Ieee80211Band)0; band < IEEE80211_NUM_BANDS; band++) {
139 currentBand = wiphy->bands[band];
140 if (currentBand == NULL) {
141 continue;
142 }
143 for (loop = 0; loop < currentBand->n_channels; loop++) {
144 if (currentBand->channels[loop].center_freq == center_freq) {
145 return ¤tBand->channels[loop];
146 }
147 }
148 }
149 return NULL;
150 }
151
WalGetChannel(struct wiphy * wiphy,int32_t freq)152 static struct ieee80211_channel *WalGetChannel(struct wiphy *wiphy, int32_t freq)
153 {
154 int32_t loop = 0;
155 enum Ieee80211Band band = IEEE80211_BAND_2GHZ;
156 struct ieee80211_supported_band *currentBand = NULL;
157
158 if (wiphy == NULL) {
159 HDF_LOGE("%s: capality is NULL!", __func__);
160 return NULL;
161 }
162
163 for (band = (enum Ieee80211Band)0; band < IEEE80211_NUM_BANDS; band++) {
164 currentBand = wiphy->bands[band];
165 if (currentBand == NULL) {
166 continue;
167 }
168
169 for (loop = 0; loop < currentBand->n_channels; loop++) {
170 if (currentBand->channels[loop].center_freq == freq) {
171 return ¤tBand->channels[loop];
172 }
173 }
174 }
175
176 return NULL;
177 }
178
179 /*--------------------------------------------------------------------------------------------------*/
180 /* HdfMac80211STAOps */
181 /*--------------------------------------------------------------------------------------------------*/
WalAssociate(void)182 static int32_t WalAssociate(void)
183 {
184 int ret = 0;
185 int32_t retVal = 0;
186 struct wiphy* wiphy = wrap_get_wiphy();
187 struct net_device *netdev = get_krn_netdev();
188 struct ieee80211_channel *channel;
189 struct cfg80211_assoc_request assoc_params = { 0 };
190
191 HDF_LOGE("%s: start ...!", __func__);
192
193 /*
194 HDF_LOGV("%s: centerFreq:%u ssidLen:%u ssid:%s", __func__, global_param->centerFreq, global_param->ssidLen, global_param->ssid);
195 HDF_LOGV("%s: bssid:%02x:%02x:%02x:%02x:%02x:%02x!", __func__,
196 global_param->bssid[0], global_param->bssid[1], global_param->bssid[2],
197 global_param->bssid[3], global_param->bssid[4], global_param->bssid[5]);
198 HDF_LOGV("%s: global_param->ie:%s, global_param->ie_len %d", __func__, global_param->ie, global_param->ie_len);
199 */
200
201 if (global_param->centerFreq != WLAN_FREQ_NOT_SPECFIED) {
202 channel = WalGetChannel(wiphy, global_param->centerFreq);
203 if ((channel == NULL) || (channel->flags & WIFI_CHAN_DISABLED)) {
204 HDF_LOGE("%s:illegal channel.flags=%u", __func__,
205 (channel == NULL) ? 0 : channel->flags);
206 retVal = HDF_FAILURE;
207 goto end;
208 }
209 }
210 assoc_params.bss = cfg80211_get_bss(wiphy, channel, global_param->bssid, global_param->ssid, global_param->ssidLen,
211 IEEE80211_BSS_TYPE_ESS,
212 IEEE80211_PRIVACY_ANY);
213
214 assoc_params.ie = global_param->ie;
215 assoc_params.ie_len = global_param->ie_len;
216 ret = memcpy_s(&assoc_params.crypto, sizeof(assoc_params.crypto), &global_param->crypto, sizeof(global_param->crypto));
217 if (ret != 0) {
218 HDF_LOGE("%s:Copy crypto info failed!ret=%d", __func__, ret);
219 retVal = HDF_FAILURE;
220 goto end;
221 }
222
223 retVal = xrmac_config_ops.assoc(wiphy, netdev, &assoc_params);
224 if (retVal < 0) {
225 HDF_LOGE("%s: connect failed!\n", __func__);
226 }
227
228 end:
229 if (global_param->ie != NULL) {
230 kfree(global_param->ie);
231 global_param->ie = NULL;
232 }
233 return retVal;
234 }
235
236
inform_bss_frame(struct ieee80211_channel * channel,int32_t signal,int16_t freq,struct ieee80211_mgmt * mgmt,uint32_t mgmtLen)237 void inform_bss_frame(struct ieee80211_channel *channel, int32_t signal, int16_t freq, struct ieee80211_mgmt *mgmt, uint32_t mgmtLen)
238 {
239 int32_t retVal = 0;
240 NetDevice *netDev = get_netDev();
241 struct ScannedBssInfo bssInfo;
242 struct WlanChannel hdfchannel;
243
244 if (channel == NULL || netDev == NULL || mgmt == NULL) {
245 HDF_LOGE("%s: inform_bss_frame channel = null or netDev = null!", __func__);
246 return;
247 }
248
249 bssInfo.signal = signal;
250 bssInfo.freq = freq;
251 bssInfo.mgmtLen = mgmtLen;
252 bssInfo.mgmt = (struct Ieee80211Mgmt *)mgmt;
253
254 hdfchannel.flags = channel->flags;
255 hdfchannel.channelId = channel->hw_value;
256 hdfchannel.centerFreq = channel->center_freq;
257
258 /*
259 HDF_LOGV("%s: hdfchannel signal:%d flags:%d--channelId:%d--centerFreq:%d--dstMac:%02x:%02x:%02x:%02x:%02x:%02x!",
260 __func__, bssInfo.signal, hdfchannel.flags, hdfchannel.channelId, hdfchannel.centerFreq,
261 bssInfo.mgmt->bssid[0], bssInfo.mgmt->bssid[1], bssInfo.mgmt->bssid[2],
262 bssInfo.mgmt->bssid[3], bssInfo.mgmt->bssid[4], bssInfo.mgmt->bssid[5]);
263 */
264
265 retVal = HdfWifiEventInformBssFrame(netDev, &hdfchannel, &bssInfo);
266 if (retVal < 0) {
267 HDF_LOGE("%s: hdf wifi event inform bss frame failed!", __func__);
268 }
269 }
270
271 #define HDF_ETHER_ADDR_LEN (6)
inform_connect_result(uint8_t * bssid,uint8_t * rspIe,uint8_t * reqIe,uint32_t reqIeLen,uint32_t rspIeLen,uint16_t connectStatus)272 void inform_connect_result(uint8_t *bssid, uint8_t *rspIe, uint8_t *reqIe, uint32_t reqIeLen, uint32_t rspIeLen, uint16_t connectStatus)
273 {
274 int32_t retVal = 0;
275 NetDevice *netDev = get_netDev();
276 struct ConnetResult connResult;
277
278 if (netDev == NULL || bssid == NULL || rspIe == NULL || reqIe == NULL) {
279 HDF_LOGE("%s: netDev / bssid / rspIe / reqIe null!", __func__);
280 return;
281 }
282
283 HDF_LOGE("%s: reqIe %s rspIe %s reqIeLen %d rspIeLen %d", __func__, reqIe, rspIe, reqIeLen, rspIeLen);
284
285 memcpy_s(&connResult.bssid[0], HDF_ETHER_ADDR_LEN, bssid, HDF_ETHER_ADDR_LEN);
286 HDF_LOGE("%s: connResult:%02x:%02x:%02x:%02x:%02x:%02x\n", __func__,
287 connResult.bssid[0], connResult.bssid[1], connResult.bssid[2], connResult.bssid[3], connResult.bssid[4], connResult.bssid[5]);
288
289 connResult.rspIe = rspIe;
290 connResult.rspIeLen = rspIeLen;
291
292 connResult.reqIe = reqIe;
293 connResult.reqIeLen = reqIeLen;
294
295 connResult.connectStatus = connectStatus;
296
297 // TODO: modify freq & statusCode
298 connResult.freq = 0;
299 connResult.statusCode = connectStatus;
300
301 retVal = HdfWifiEventConnectResult(netDev, &connResult);
302 if (retVal < 0) {
303 HDF_LOGE("%s: hdf wifi event inform connect result failed!", __func__);
304 }
305 }
306
inform_auth_result(struct net_device * dev,const u8 * buf,size_t len)307 void inform_auth_result(struct net_device *dev, const u8 *buf, size_t len)
308 {
309 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
310 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
311
312 if (status_code != WLAN_STATUS_SUCCESS) {
313 HDF_LOGE("%s: status_code %d!", __func__, status_code);
314 } else {
315 HDF_LOGE("%s: sucess!", __func__);
316 WalAssociate();
317 }
318 }
319
320 struct wireless_dev ap_wireless_dev;
321 struct ieee80211_channel ap_ieee80211_channel;
322 #define GET_DEV_CFG80211_WIRELESS(dev) ((struct wireless_dev*)((dev)->ieee80211_ptr))
SetupWireLessDev(struct net_device * netDev,struct WlanAPConf * apSettings)323 static int32_t SetupWireLessDev(struct net_device *netDev, struct WlanAPConf *apSettings)
324 {
325
326 if (netDev->ieee80211_ptr == NULL) {
327 netDev->ieee80211_ptr = &ap_wireless_dev;
328 }
329
330 if (GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan == NULL) {
331 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan = &ap_ieee80211_channel;
332 }
333 GET_DEV_CFG80211_WIRELESS(netDev)->iftype = NL80211_IFTYPE_AP;
334 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.width = (enum nl80211_channel_type)apSettings->width;
335 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.center_freq1 = apSettings->centerFreq1;
336 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.center_freq2 = apSettings->centerFreq2;
337 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan->hw_value = apSettings->channel;
338 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan->band = IEEE80211_BAND_2GHZ;
339 GET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan->center_freq = apSettings->centerFreq1;
340
341 return HDF_SUCCESS;
342 }
343
344 /*--------------------------------------------------------------------------------------------------*/
345 /* HdfMac80211BaseOps */
346 /*--------------------------------------------------------------------------------------------------*/
347 // OK
WalSetMode(NetDevice * netDev,enum WlanWorkMode iftype)348 int32_t WalSetMode(NetDevice *netDev, enum WlanWorkMode iftype)
349 {
350 int32_t retVal = 0;
351 struct wiphy* wiphy = wrap_get_wiphy();
352 struct net_device *netdev = get_krn_netdev();
353
354 HDF_LOGE("%s: start... iftype=%d ", __func__, iftype);
355 rtnl_lock();
356 retVal = (int32_t)xrmac_config_ops.change_virtual_intf(wiphy, netdev, (enum nl80211_iftype)iftype, NULL);
357 rtnl_unlock();
358 if (retVal < 0) {
359 HDF_LOGE("%s: set mode failed!", __func__);
360 }
361
362 return retVal;
363 }
364
365
WalAddKey(struct NetDevice * netDev,uint8_t keyIndex,bool pairwise,const uint8_t * macAddr,struct KeyParams * params)366 int32_t WalAddKey(struct NetDevice *netDev, uint8_t keyIndex, bool pairwise, const uint8_t *macAddr,
367 struct KeyParams *params)
368 {
369 int32_t retVal = 0;
370 struct wiphy* wiphy = wrap_get_wiphy();
371 struct net_device *netdev = get_krn_netdev();
372 struct key_params keypm;
373
374 HDF_LOGE("%s: start...", __func__);
375
376 (void)netDev;
377 memset_s(&keypm, sizeof(struct key_params), 0, sizeof(struct key_params));
378 keypm.key = params->key;
379 keypm.seq = params->seq;
380 keypm.key_len = params->keyLen;
381 keypm.seq_len = params->seqLen;
382 keypm.cipher = params->cipher;
383 keypm.vlan_id = 0;
384
385 if(macAddr)
386 HDF_LOGE("macAddr=%02x:%02x:%02x:%02x:%02x:%02x\n",
387 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
388 else
389 HDF_LOGE("macAddr is null");
390
391 retVal = (int32_t)xrmac_config_ops.add_key(wiphy, netdev, keyIndex, pairwise, macAddr, &keypm);
392 if (retVal < 0) {
393 HDF_LOGE("%s: add key failed!", __func__);
394 }
395
396 return retVal;
397 }
398
WalDelKey(struct NetDevice * netDev,uint8_t keyIndex,bool pairwise,const uint8_t * macAddr)399 int32_t WalDelKey(struct NetDevice *netDev, uint8_t keyIndex, bool pairwise, const uint8_t *macAddr)
400 {
401 int32_t retVal = 0;
402 struct wiphy* wiphy = wrap_get_wiphy();
403 struct net_device *netdev = get_krn_netdev();
404
405 (void)netDev;
406 HDF_LOGE("%s: start...", __func__);
407
408 if(macAddr != NULL) {
409 if ((macAddr[0] == 0) && (macAddr[1] == 0) && (macAddr[2] == 0) && (macAddr[3] == 0) && (macAddr[4] == 0) && (macAddr[5] == 0)) {
410 HDF_LOGE("%s: macAddr value is 0 ", __func__);
411 macAddr = NULL;
412 }
413 }
414
415 retVal = (int32_t)xrmac_config_ops.del_key(wiphy, netdev, keyIndex, pairwise, macAddr);
416 if (retVal < 0) {
417 HDF_LOGE("%s: delete key failed!", __func__);
418 }
419
420 return retVal;
421 }
422
WalSetDefaultKey(struct NetDevice * netDev,uint8_t keyIndex,bool unicast,bool multicas)423 int32_t WalSetDefaultKey(struct NetDevice *netDev, uint8_t keyIndex, bool unicast, bool multicas)
424 {
425 int32_t retVal = 0;
426 struct wiphy* wiphy = wrap_get_wiphy();
427 struct net_device *netdev = get_krn_netdev();
428
429 HDF_LOGE("%s: start...", __func__);
430
431 retVal = (int32_t)xrmac_config_ops.set_default_key(wiphy, netdev, keyIndex, unicast, multicas);
432 if (retVal < 0) {
433 HDF_LOGE("%s: set default key failed!", __func__);
434 }
435
436 return retVal;
437 }
438
WalGetDeviceMacAddr(NetDevice * netDev,int32_t type,uint8_t * mac,uint8_t len)439 int32_t WalGetDeviceMacAddr(NetDevice *netDev, int32_t type, uint8_t *mac, uint8_t len)
440 {
441 (void)len;
442 (void)type;
443 (void)netDev;
444 HDF_LOGE("%s: start...", __func__);
445
446 xradio_get_mac_addrs(mac);
447 return HDF_SUCCESS;
448 }
449
WalSetMacAddr(NetDevice * netDev,uint8_t * mac,uint8_t len)450 int32_t WalSetMacAddr(NetDevice *netDev, uint8_t *mac, uint8_t len)
451 {
452 int32_t retVal = 0;
453
454 (void)len;
455 (void)netDev;
456 HDF_LOGE("%s: start... len = %d", __func__, len);
457
458 if (len <= ETH_ADDR_LEN) {
459 char addr_mac[ETH_ADDR_LEN] = {0};
460 HDF_LOGE("ADDR=%02x:%02x:%02x:%02x:%02x:%02x\n",
461 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
462
463 sprintf(addr_mac, "%02x:%02x:%02x:%02x:%02x:%02x\n",
464 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
465 retVal = set_wifi_custom_mac_address(addr_mac, len);
466 } else {
467 HDF_LOGE("%s: lenght(%u) is err", __func__, len);
468 }
469
470 if (retVal < 0)
471 return -1;
472
473 return HDF_SUCCESS;
474 }
475
WalSetTxPower(NetDevice * netDev,int32_t power)476 int32_t WalSetTxPower(NetDevice *netDev, int32_t power)
477 {
478 int retVal = 0;
479 struct wiphy* wiphy = wrap_get_wiphy();
480 struct wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
481
482 HDF_LOGE("%s: start...", __func__);
483
484 retVal = (int32_t)xrmac_config_ops.set_tx_power(wiphy, wdev, NL80211_TX_POWER_FIXED ,power);
485
486 if (retVal < 0) {
487 HDF_LOGE("%s: set_tx_power failed!", __func__);
488 }
489
490 return HDF_SUCCESS;
491 }
492
WalGetValidFreqsWithBand(NetDevice * netDev,int32_t band,int32_t * freqs,uint32_t * num)493 int32_t WalGetValidFreqsWithBand(NetDevice *netDev, int32_t band, int32_t *freqs, uint32_t *num)
494 {
495 uint32_t freqIndex = 0;
496 uint32_t channelNumber;
497 uint32_t freqTmp;
498 uint32_t minFreq;
499 uint32_t maxFreq;
500 (void)band;
501 (void)freqs;
502 (void)num;
503 HDF_LOGE("%s: start...", __func__);
504 if (freqs == NULL) {
505 HDF_LOGE("%s: freq is null, error!", __func__);
506 return -1;
507 }
508
509 /*const struct ieee80211_regdomain *regdom = wrp_get_regdomain();
510 NOT SUPPORT
511 if (regdom == NULL) {
512 HDF_LOGE("%s: wal_get_cfg_regdb failed!", __func__);
513 return HDF_FAILURE;
514 }*/
515
516 // for pass verfy
517 minFreq = 2412;
518 maxFreq = 2472;
519 switch (band) {
520 case WLAN_BAND_2G:
521 for (channelNumber = 1; channelNumber <= WIFI_24G_CHANNEL_NUMS; channelNumber++) {
522 if (channelNumber < WAL_MAX_CHANNEL_2G) {
523 freqTmp = WAL_MIN_FREQ_2G + (channelNumber - 1) * WAL_FREQ_2G_INTERVAL;
524 } else if (channelNumber == WAL_MAX_CHANNEL_2G) {
525 freqTmp = WAL_MAX_FREQ_2G;
526 }
527 if (freqTmp < minFreq || freqTmp > maxFreq) {
528 continue;
529 }
530 freqs[freqIndex] = freqTmp;
531 freqIndex++;
532 }
533 *num = freqIndex;
534 break;
535 default:
536 HDF_LOGE("%s: no support band!", __func__);
537 return HDF_ERR_NOT_SUPPORT;
538 }
539 return HDF_SUCCESS;
540 }
541
542
WalGetHwCapability(struct NetDevice * netDev,struct WlanHwCapability ** capability)543 int32_t WalGetHwCapability(struct NetDevice *netDev, struct WlanHwCapability **capability)
544 {
545 uint8_t loop = 0;
546 struct wiphy* wiphy = wrap_get_wiphy();
547 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_2GHZ];
548 struct WlanHwCapability *hwCapability = (struct WlanHwCapability *)OsalMemCalloc(sizeof(struct WlanHwCapability));
549
550 (void)netDev;
551 if (hwCapability == NULL) {
552 HDF_LOGE("%s: oom!\n", __func__);
553 return HDF_FAILURE;
554 }
555 hwCapability->Release = WalReleaseHwCapability;
556 if (hwCapability->bands[IEEE80211_BAND_2GHZ] == NULL) {
557 hwCapability->bands[IEEE80211_BAND_2GHZ] =
558 OsalMemCalloc(sizeof(struct WlanBand) + (sizeof(struct WlanChannel) * band->n_channels));
559 if (hwCapability->bands[IEEE80211_BAND_2GHZ] == NULL) {
560 HDF_LOGE("%s: oom!\n", __func__);
561 WalReleaseHwCapability(hwCapability);
562 return HDF_FAILURE;
563 }
564 }
565 hwCapability->htCapability = band->ht_cap.cap;
566 hwCapability->bands[IEEE80211_BAND_2GHZ]->channelCount = band->n_channels;
567 for (loop = 0; loop < band->n_channels; loop++) {
568 hwCapability->bands[IEEE80211_BAND_2GHZ]->channels[loop].centerFreq = band->channels[loop].center_freq;
569 hwCapability->bands[IEEE80211_BAND_2GHZ]->channels[loop].flags = band->channels[loop].flags;
570 hwCapability->bands[IEEE80211_BAND_2GHZ]->channels[loop].channelId = band->channels[loop].hw_value;
571 }
572 hwCapability->supportedRateCount = band->n_bitrates;
573 hwCapability->supportedRates = OsalMemCalloc(sizeof(uint16_t) * band->n_bitrates);
574 if (hwCapability->supportedRates == NULL) {
575 HDF_LOGE("%s: oom!\n", __func__);
576 WalReleaseHwCapability(hwCapability);
577 return HDF_FAILURE;
578 }
579 for (loop = 0; loop < band->n_bitrates; loop++) {
580 hwCapability->supportedRates[loop] = band->bitrates[loop].bitrate;
581 }
582 *capability = hwCapability;
583 HDF_LOGE("%s: start...", __func__);
584 return HDF_SUCCESS;
585 }
586
587 #ifdef XR829_WLAN_FEATURE_P2P
WalRemainOnChannel(struct NetDevice * netDev,WifiOnChannel * onChannel)588 int32_t WalRemainOnChannel(struct NetDevice *netDev, WifiOnChannel *onChannel)
589 {
590 int32_t retVal = 0;
591 struct wiphy* wiphy = wrap_get_wiphy();
592 struct net_device *netdev = get_krn_netdev();
593 struct ieee80211_channel *channel;
594 u64 cookie;
595 struct wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
596
597 (void)netDev;
598 HDF_LOGE("%s: start...", __func__);
599 if (netdev == NULL || onChannel == NULL) {
600 HDF_LOGE("%s:NULL ptr!", __func__);
601 return HDF_FAILURE;
602 }
603 if (onChannel->freq != WLAN_FREQ_NOT_SPECFIED) {
604 channel = WalGetChannel(wiphy, onChannel->freq);
605 if ((channel == NULL) || (channel->flags & WIFI_CHAN_DISABLED)) {
606 HDF_LOGE("%s:illegal channel.flags=%u", __func__,
607 (channel == NULL) ? 0 : channel->flags);
608 return HDF_FAILURE;
609 }
610 }
611
612 retVal = xrmac_config_ops.remain_on_channel(wiphy, wdev, channel, onChannel->duration, &cookie);
613 if (retVal) {
614 HDF_LOGE("%s: remain on channel failed! ret = %d", __func__, retVal);
615 }
616 return retVal;
617 }
618
WalCancelRemainOnChannel(struct NetDevice * netDev)619 int32_t WalCancelRemainOnChannel(struct NetDevice *netDev)
620 {
621 int32_t retVal = 0;
622 struct wiphy* wiphy = wrap_get_wiphy();
623 struct net_device *netdev = get_krn_netdev();
624 struct wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
625
626 (void)netDev;
627 HDF_LOGE("%s: start...", __func__);
628 if (netdev == NULL) {
629 HDF_LOGE("%s:NULL ptr!", __func__);
630 return HDF_FAILURE;
631 }
632
633 retVal = xrmac_config_ops.cancel_remain_on_channel(wiphy, wdev, 0);
634 if (retVal) {
635 HDF_LOGE("%s: cancel remain on channel failed!", __func__);
636 }
637 HDF_LOGE("%s: start...", __func__);
638 return retVal;
639 }
640
WalProbeReqReport(struct NetDevice * netDev,int32_t report)641 int32_t WalProbeReqReport(struct NetDevice *netDev, int32_t report)
642 {
643 // NO SUPPORT
644 (void)report;
645 HDF_LOGE("%s: start...", __func__);
646 if (netDev == NULL) {
647 HDF_LOGE("%s:NULL ptr!", __func__);
648 return HDF_FAILURE;
649 }
650 return HDF_SUCCESS;
651 }
652
WalAddIf(struct NetDevice * netDev,WifiIfAdd * ifAdd)653 int32_t WalAddIf(struct NetDevice *netDev, WifiIfAdd *ifAdd)
654 {
655 char ifName[16] = {0};
656 struct wiphy* wiphy = wrap_get_wiphy();
657
658 HDF_LOGE("%s: start...", __func__);
659
660 GetIfName(ifAdd->type, ifName, 16);
661 xrmac_config_ops.add_virtual_intf(wiphy, ifName, 0, ifAdd->type, NULL);
662
663 return HDF_SUCCESS;
664 }
665
666
WalRemoveIf(struct NetDevice * netDev,WifiIfRemove * ifRemove)667 int32_t WalRemoveIf(struct NetDevice *netDev, WifiIfRemove *ifRemove)
668 {
669 struct NetDevice *removeNetdev = NULL;
670 struct wireless_dev *wdev = NULL;
671 struct wiphy* wiphy = wrap_get_wiphy();
672
673 (void)netDev;
674 HDF_LOGE("%s: start...", __func__);
675 if (ifRemove == NULL) {
676 HDF_LOGE("%s:NULL ptr!", __func__);
677 return HDF_FAILURE;
678 }
679
680 removeNetdev = NetDeviceGetInstByName((const char*)(ifRemove->ifname));
681 if (removeNetdev == NULL) {
682 return HDF_FAILURE;
683 }
684
685 wdev = GET_NET_DEV_CFG80211_WIRELESS(removeNetdev);
686 xrmac_config_ops.del_virtual_intf(wiphy, wdev);
687
688 return HDF_SUCCESS;
689 }
690
WalSetApWpsP2pIe(struct NetDevice * netDev,WifiAppIe * appIe)691 int32_t WalSetApWpsP2pIe(struct NetDevice *netDev, WifiAppIe *appIe)
692 {
693 // NO SUPPORT
694 (void)appIe;
695 HDF_LOGE("%s: start...", __func__);
696 if (netDev == NULL) {
697 HDF_LOGE("%s:NULL ptr!", __func__);
698 return HDF_FAILURE;
699 }
700 return HDF_SUCCESS;
701 }
702
WalGetDriverFlag(struct NetDevice * netDev,WifiGetDrvFlags ** params)703 int32_t WalGetDriverFlag(struct NetDevice *netDev, WifiGetDrvFlags **params)
704 {
705 struct wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
706 WifiGetDrvFlags *getDrvFlag = (WifiGetDrvFlags *)OsalMemCalloc(sizeof(WifiGetDrvFlags));
707
708 if (netDev == NULL || params == NULL) {
709 HDF_LOGE("%s:NULL ptr!", __func__);
710 return HDF_FAILURE;
711 }
712
713 HDF_LOGE("%s: start...", __func__);
714
715 if (NULL == wdev) {
716 HDF_LOGE("%s: wdev NULL", __func__);
717 return HDF_FAILURE;
718 } else {
719 HDF_LOGE("%s: p_wdev:%p", __func__, wdev);
720 }
721
722 if (NULL == getDrvFlag) {
723 HDF_LOGE("%s: getDrvFlag NULL", __func__);
724 }
725 switch (wdev->iftype) {
726 case NL80211_IFTYPE_P2P_CLIENT:
727 /* fall-through */
728 case NL80211_IFTYPE_P2P_GO:
729 HDF_LOGE("%s: NL80211_IFTYPE_P2P_GO case!", __func__);
730 getDrvFlag->drvFlags = HISI_DRIVER_FLAGS_AP;
731 break;
732 case NL80211_IFTYPE_P2P_DEVICE:
733 HDF_LOGE("%s: NL80211_IFTYPE_P2P_DEVICE case!", __func__);
734 getDrvFlag->drvFlags = (HISI_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
735 HISI_DRIVER_FLAGS_P2P_CONCURRENT |
736 HISI_DRIVER_FLAGS_P2P_CAPABLE);
737 break;
738 default:
739 HDF_LOGE("%s: getDrvFlag->drvFlags default to 0 case!", __func__);
740 getDrvFlag->drvFlags = 0;
741 }
742 *params = getDrvFlag;
743 return HDF_SUCCESS;
744 }
745 #endif
746
WalSendAction(struct NetDevice * netDev,WifiActionData * actionData)747 int32_t WalSendAction(struct NetDevice *netDev, WifiActionData *actionData)
748 {
749 (void)netDev;
750 (void)actionData;
751 HDF_LOGE("%s: start...", __func__);
752 return HDF_ERR_NOT_SUPPORT;
753 }
754
WalGetIftype(struct NetDevice * netDev,uint8_t * iftype)755 int32_t WalGetIftype(struct NetDevice *netDev, uint8_t *iftype)
756 {
757 iftype = (uint8_t *)(&(GET_NET_DEV_CFG80211_WIRELESS(netDev)->iftype));
758 if (iftype != NULL)
759 HDF_LOGE("%s: start...", __func__);
760 return HDF_SUCCESS;
761 }
762
763
764 /*--------------------------------------------------------------------------------------------------*/
765 /* HdfMac80211STAOps */
766 /*--------------------------------------------------------------------------------------------------*/
WalAuthenticate(NetDevice * netDev,WlanConnectParams * param)767 static int32_t WalAuthenticate(NetDevice *netDev, WlanConnectParams *param)
768 {
769 int ret = 0;
770 int32_t retVal = 0;
771 struct wiphy* wiphy = wrap_get_wiphy();
772 struct net_device *netdev = get_krn_netdev();
773 struct ieee80211_channel *channel;
774 struct cfg80211_auth_request auth_params = { 0 };
775
776 HDF_LOGE("%s: start ...!", __func__);
777
778 (void)netDev;
779 if (netdev == NULL || param == NULL) {
780 HDF_LOGE("%s:NULL ptr!", __func__);
781 return HDF_FAILURE;
782 }
783
784 auth_params.ie = param->ie;
785 auth_params.ie_len = param->ieLen;
786 auth_params.key = param->key;
787 auth_params.auth_type = (u_int8_t)param->authType;
788 auth_params.key_len = param->keyLen;
789 auth_params.key_idx = param->keyIdx;
790 auth_params.auth_data = NULL;
791 auth_params.auth_data_len = 0;
792
793 if (param->centerFreq != WLAN_FREQ_NOT_SPECFIED) {
794 channel = WalGetChannel(wiphy, param->centerFreq);
795 if ((channel == NULL) || (channel->flags & WIFI_CHAN_DISABLED)) {
796 HDF_LOGE("%s:illegal channel.flags=%u", __func__,
797 (channel == NULL) ? 0 : channel->flags);
798 return HDF_FAILURE;
799 }
800 }
801 auth_params.bss = cfg80211_get_bss(wiphy, channel, param->bssid, param->ssid, param->ssidLen,
802 IEEE80211_BSS_TYPE_ESS,
803 IEEE80211_PRIVACY_ANY);
804
805 global_param->centerFreq = param->centerFreq;
806 global_param->ssidLen = param->ssidLen;
807 global_param->ie_len = param->ieLen;
808 memcpy_s(global_param->bssid, ETH_ADDR_LEN, param->bssid, ETH_ADDR_LEN);
809 memcpy_s(global_param->ssid, OAL_IEEE80211_MAX_SSID_LEN, param->ssid, param->ssidLen);
810 if (global_param->ie != NULL) {
811 HDF_LOGE("%s: global_param ie is not NULL, kfree!", __func__);
812 kfree(global_param->ie);
813 global_param->ie = NULL;
814 }
815 global_param->ie = NULL;
816 global_param->ie = kzalloc(global_param->ie_len, GFP_KERNEL);
817 if (global_param->ie == NULL) {
818 HDF_LOGE("%s: global_param ie is NULL", __func__);
819 return HDF_FAILURE;
820 }
821 ret = memcpy_s(&global_param->crypto, sizeof(global_param->crypto), ¶m->crypto, sizeof(param->crypto));
822 if (ret != 0) {
823 HDF_LOGE("%s:Copy crypto info failed!ret=%d", __func__, ret);
824 return HDF_FAILURE;
825 }
826 //global_param->ie = param->ie;
827 memcpy_s(global_param->ie, global_param->ie_len, param->ie, param->ieLen);
828 //HDF_LOGV("%s: global_param->ie:%s, global_param->ie_len %d", __func__, global_param->ie, global_param->ie_len);
829
830 retVal = xrmac_config_ops.auth(wiphy, netdev, &auth_params);
831 if (retVal < 0) {
832 kfree(global_param->ie);
833 global_param->ie = NULL;
834 HDF_LOGE("%s: connect failed!\n", __func__);
835 }
836
837 return retVal;
838 }
839
WalDisconnect(NetDevice * netDev,uint16_t reasonCode)840 int32_t WalDisconnect(NetDevice *netDev, uint16_t reasonCode)
841 {
842 int32_t retVal = 0;
843 struct wiphy* wiphy = wrap_get_wiphy();
844 struct net_device *netdev = get_krn_netdev();
845 struct cfg80211_deauth_request req;
846
847 (void)netDev;
848 req.bssid = global_param->bssid;
849 req.reason_code = reasonCode;
850 HDF_LOGE("%s: start...reasonCode:%d", __func__, reasonCode);
851
852 retVal = (int32_t)xrmac_config_ops.deauth(wiphy, netdev, &req);
853 if (retVal < 0) {
854 HDF_LOGE("%s: sta disconnect failed!", __func__);
855 }
856
857 return retVal;
858 }
859
WalStartScan(NetDevice * netDev,struct WlanScanRequest * scanParam)860 int32_t WalStartScan(NetDevice *netDev, struct WlanScanRequest *scanParam)
861 {
862 int32_t loop;
863 int32_t count = 0;
864 int32_t retVal = 0;
865 enum Ieee80211Band band = IEEE80211_BAND_2GHZ;
866 struct ieee80211_channel *chan = NULL;
867 struct wiphy* wiphy = wrap_get_wiphy();
868 int32_t channelTotal;channelTotal = ieee80211_get_num_supported_channels(wiphy);
869
870 struct cfg80211_scan_request *request =
871 (struct cfg80211_scan_request *)OsalMemCalloc(sizeof(struct cfg80211_scan_request) + XR829_POINT_CHANNEL_SIZE * channelTotal);
872
873 HDF_LOGE("%s: start ...", __func__);
874
875 if (request == NULL) {
876 HDF_LOGE("%s: calloc request null!\n", __func__);
877 return HDF_FAILURE;
878 }
879
880 // basic info
881 request->wiphy = wiphy;
882 request->wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
883 request->n_ssids = scanParam->ssidCount;
884
885 // channel info
886 if ((scanParam->freqs == NULL) || (scanParam->freqsCount == 0)) {
887 if (wiphy->bands[band] == NULL) {
888 HDF_LOGE("%s: wiphy->bands[band] = NULL!\n", __func__);
889 return HDF_FAILURE;
890 }
891
892 for (loop = 0; loop < (int32_t)wiphy->bands[band]->n_channels; loop++) {
893 chan = &wiphy->bands[band]->channels[loop];
894 if ((chan->flags & WIFI_CHAN_DISABLED) != 0) {
895 continue;
896 }
897 request->channels[count++] = chan;
898 }
899 } else {
900 for (loop = 0; loop < scanParam->freqsCount; loop++) {
901 chan = GetChannelByFreq(wiphy, (uint16_t)(scanParam->freqs[loop]));
902 if (chan == NULL) {
903 HDF_LOGE("%s: freq not found!freq=%d!\n", __func__, scanParam->freqs[loop]);
904 continue;
905 }
906 request->channels[count++] = chan;
907 }
908 }
909
910 if (count == 0) {
911 HDF_LOGE("%s: invalid freq info!\n", __func__);
912 return HDF_FAILURE;
913 }
914 request->n_channels = count;
915
916 // ssid info
917 count = 0;
918 loop = 0;
919 if (scanParam->ssidCount > WPAS_MAX_SCAN_SSIDS) {
920 HDF_LOGE("%s:unexpected numSsids!numSsids=%u", __func__, scanParam->ssidCount);
921 return HDF_FAILURE;
922 }
923
924 if (scanParam->ssidCount == 0) {
925 HDF_LOGE("%s:ssid number is 0!", __func__);
926 return HDF_SUCCESS;
927 }
928
929 request->ssids = (struct cfg80211_ssid *)OsalMemCalloc(scanParam->ssidCount * sizeof(struct cfg80211_ssid));
930 if (request->ssids == NULL) {
931 HDF_LOGE("%s: calloc request->ssids null", __func__);
932 return HDF_FAILURE;
933 }
934
935 for (loop = 0; loop < scanParam->ssidCount; loop++) {
936 if (count >= DRIVER_MAX_SCAN_SSIDS) {
937 break;
938 }
939
940 if (scanParam->ssids[loop].ssidLen > IEEE80211_MAX_SSID_LEN) {
941 continue;
942 }
943
944 request->ssids[count].ssid_len = scanParam->ssids[loop].ssidLen;
945 if (memcpy_s(request->ssids[count].ssid, OAL_IEEE80211_MAX_SSID_LEN, scanParam->ssids[loop].ssid,
946 scanParam->ssids[loop].ssidLen) != 0) {
947 continue;
948 }
949 count++;
950 }
951 request->n_ssids = count;
952
953 // User Ie Info
954 if (scanParam->extraIEsLen > 512) {
955 HDF_LOGE("%s:unexpected extra len!extraIesLen=%d", __func__, scanParam->extraIEsLen);
956 return HDF_FAILURE;
957 }
958
959 if ((scanParam->extraIEs != NULL) && (scanParam->extraIEsLen != 0)) {
960 request->ie = (uint8_t *)OsalMemCalloc(scanParam->extraIEsLen);
961 if (request->ie == NULL) {
962 HDF_LOGE("%s: calloc request->ie null", __func__);
963 goto fail;
964 }
965 (void)memcpy_s((void*)request->ie, scanParam->extraIEsLen, scanParam->extraIEs, scanParam->extraIEsLen);
966 request->ie_len = scanParam->extraIEsLen;
967 }
968
969 retVal = (int32_t)xrmac_config_ops.scan(wiphy, request);
970 if (retVal < 0) {
971 HDF_LOGE("%s: scan Failed!", __func__);
972 if (request != NULL) {
973 if ((request)->ie != NULL) {
974 OsalMemFree((void*)(request->ie));
975 request->ie = NULL;
976 }
977 if ((request)->ssids != NULL) {
978 OsalMemFree(request->ssids);
979 (request)->ssids = NULL;
980 }
981 OsalMemFree(request);
982 request = NULL;
983 }
984 } else {
985 HDF_LOGE("%s: scan OK!", __func__);
986 }
987
988 return retVal;
989
990 fail:
991 if (request->ie != NULL) {
992 OsalMemFree((void*)request->ie);
993 request->ie = NULL;
994 }
995
996 return HDF_FAILURE;
997 }
998
WalAbortScan(NetDevice * netDev)999 int32_t WalAbortScan(NetDevice *netDev)
1000 {
1001 int retVal = 0;
1002 struct wiphy* wiphy = wrap_get_wiphy();
1003 struct wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
1004
1005 HDF_LOGE("%s: start...", __func__);
1006 retVal = ieee80211_cancel_scan(wiphy, wdev);
1007
1008 return retVal;
1009 }
1010
WalSetScanningMacAddress(NetDevice * netDev,unsigned char * mac,uint32_t len)1011 int32_t WalSetScanningMacAddress(NetDevice *netDev, unsigned char *mac, uint32_t len)
1012 {
1013 (void)netDev;
1014 (void)mac;
1015 (void)len;
1016 return HDF_ERR_NOT_SUPPORT;
1017 }
1018
1019 /*--------------------------------------------------------------------------------------------------*/
1020 /* HdfMac80211APOps */
1021 /*--------------------------------------------------------------------------------------------------*/
1022 struct cfg80211_ap_settings ap_setting_info;
1023 u8 ap_ssid[IEEE80211_MAX_SSID_LEN];
1024 struct ieee80211_channel ap_chan;
WalConfigAp(NetDevice * netDev,struct WlanAPConf * apConf)1025 int32_t WalConfigAp(NetDevice *netDev, struct WlanAPConf *apConf)
1026 {
1027 int32_t ret = 0;
1028 struct wiphy* wiphy = wrap_get_wiphy();
1029 struct net_device *netdev = get_krn_netdev();
1030
1031 (void)netDev;
1032 ret = SetupWireLessDev(netdev, apConf);
1033 if (0 != ret) {
1034 HDF_LOGE("%s: set up wireless device failed!", __func__);
1035 return HDF_FAILURE;
1036 }
1037
1038 HDF_LOGE("%s: before iftype = %d!", __func__, netdev->ieee80211_ptr->iftype);
1039 netdev->ieee80211_ptr->iftype = NL80211_IFTYPE_AP;
1040 HDF_LOGE("%s: after iftype = %d!", __func__, netdev->ieee80211_ptr->iftype);
1041
1042 ap_setting_info.ssid_len = apConf->ssidConf.ssidLen;
1043 memcpy_s(&ap_ssid[0], IEEE80211_MAX_SSID_LEN, &apConf->ssidConf.ssid[0], apConf->ssidConf.ssidLen);
1044
1045 ap_setting_info.ssid = &ap_ssid[0];
1046 ap_setting_info.chandef.center_freq1 = apConf->centerFreq1;
1047 ap_setting_info.chandef.center_freq2 = apConf->centerFreq2;
1048 ap_setting_info.chandef.width = apConf->width;
1049
1050 ap_chan.center_freq = apConf->centerFreq1;
1051 ap_chan.hw_value= apConf->channel;
1052 ap_chan.band = apConf->band;
1053 ap_chan.band = IEEE80211_BAND_2GHZ;
1054 ap_setting_info.chandef.chan = &ap_chan;
1055
1056 ret = (int32_t)xrmac_config_ops.change_virtual_intf(wiphy, netdev, (enum nl80211_iftype)netdev->ieee80211_ptr->iftype, NULL);
1057 if (ret < 0) {
1058 HDF_LOGE("%s: set mode failed!", __func__);
1059 }
1060 HDF_LOGE("%s: start ...!", __func__);
1061
1062 return HDF_SUCCESS;
1063 }
1064
WalStartAp(NetDevice * netDev)1065 int32_t WalStartAp(NetDevice *netDev)
1066 {
1067 int32_t retVal = 0;
1068 struct wiphy* wiphy = wrap_get_wiphy();
1069 struct net_device *netdev = get_krn_netdev();
1070
1071 (void)netDev;
1072 HDF_LOGE("%s: start...", __func__);
1073 GET_DEV_CFG80211_WIRELESS(netdev)->preset_chandef.chan->center_freq = netdev->ieee80211_ptr->preset_chandef.center_freq1;
1074 retVal = (int32_t)xrmac_config_ops.start_ap(wiphy, netdev, &ap_setting_info);
1075 if (retVal < 0) {
1076 HDF_LOGE("%s: start_ap failed!", __func__);
1077 }
1078 HDF_LOGE("%s: start ...!", __func__);
1079 return retVal;
1080 }
1081
WalStopAp(NetDevice * netDev)1082 int32_t WalStopAp(NetDevice *netDev)
1083 {
1084 int32_t retVal = 0;
1085 struct wiphy* wiphy = wrap_get_wiphy();
1086 struct net_device *netdev = get_krn_netdev();
1087
1088 (void)netDev;
1089 HDF_LOGE("%s: start...", __func__);
1090
1091 retVal = (int32_t)xrmac_config_ops.stop_ap(wiphy, netdev);
1092 if (retVal < 0) {
1093 HDF_LOGE("%s: stop_ap failed!", __func__);
1094 }
1095
1096 HDF_LOGE("%s: start ...!", __func__);
1097 return retVal;
1098 }
1099
WalChangeBeacon(NetDevice * netDev,struct WlanBeaconConf * param)1100 int32_t WalChangeBeacon(NetDevice *netDev, struct WlanBeaconConf *param)
1101 {
1102 int32_t retVal = 0;
1103 struct cfg80211_beacon_data info;
1104 struct wiphy* wiphy = wrap_get_wiphy();
1105 struct net_device *netdev = get_krn_netdev();
1106
1107 (void)netDev;
1108 HDF_LOGE("%s: start...", __func__);
1109
1110 memset_s(&info, sizeof(info), 0x00, sizeof(info));
1111 info.head = param->headIEs;
1112 info.head_len = (size_t)param->headIEsLength;
1113 info.tail = param->tailIEs;
1114 info.tail_len = (size_t)param->tailIEsLength;
1115
1116 info.beacon_ies = NULL;
1117 info.proberesp_ies = NULL;
1118 info.assocresp_ies = NULL;
1119 info.probe_resp = NULL;
1120 info.beacon_ies_len = 0X00;
1121 info.proberesp_ies_len = 0X00;
1122 info.assocresp_ies_len = 0X00;
1123 info.probe_resp_len = 0X00;
1124
1125 // add beacon data for start ap
1126 ap_setting_info.dtim_period = param->DTIMPeriod;
1127 ap_setting_info.hidden_ssid = param->hiddenSSID;
1128 ap_setting_info.beacon_interval = param->interval;
1129 HDF_LOGE("%s: dtim_period:%d---hidden_ssid:%d---beacon_interval:%d!",
1130 __func__, ap_setting_info.dtim_period, ap_setting_info.hidden_ssid, ap_setting_info.beacon_interval);
1131
1132 ap_setting_info.beacon.head = param->headIEs;
1133 ap_setting_info.beacon.head_len = param->headIEsLength;
1134 ap_setting_info.beacon.tail = param->tailIEs;
1135 ap_setting_info.beacon.tail_len = param->tailIEsLength;
1136
1137 ap_setting_info.beacon.beacon_ies = NULL;
1138 ap_setting_info.beacon.proberesp_ies = NULL;
1139 ap_setting_info.beacon.assocresp_ies = NULL;
1140 ap_setting_info.beacon.probe_resp = NULL;
1141 ap_setting_info.beacon.beacon_ies_len = 0X00;
1142 ap_setting_info.beacon.proberesp_ies_len = 0X00;
1143 ap_setting_info.beacon.assocresp_ies_len = 0X00;
1144 ap_setting_info.beacon.probe_resp_len = 0X00;
1145
1146 HDF_LOGE("%s: headIEsLen:%d---tailIEsLen:%d!", __func__, param->headIEsLength, param->tailIEsLength);
1147
1148 retVal = (int32_t)xrmac_config_ops.change_beacon(wiphy, netdev, &info);
1149 if (retVal < 0) {
1150 HDF_LOGE("%s: change_beacon failed!", __func__);
1151 }
1152 HDF_LOGE("%s: start ...!", __func__);
1153 return HDF_SUCCESS;
1154 }
1155
WalDelStation(NetDevice * netDev,const uint8_t * macAddr)1156 int32_t WalDelStation(NetDevice *netDev, const uint8_t *macAddr)
1157 {
1158 int32_t retVal = 0;
1159 struct wiphy* wiphy = wrap_get_wiphy();
1160 struct net_device *netdev = get_krn_netdev();
1161 struct station_del_parameters del_param = {macAddr, 10, 0};
1162
1163 (void)netDev;
1164 (void)macAddr;
1165 HDF_LOGE("%s: start...", __func__);
1166
1167 retVal = (int32_t)xrmac_config_ops.del_station(wiphy, netdev, &del_param);
1168 if (retVal < 0) {
1169 HDF_LOGE("%s: del_station failed!", __func__);
1170 }
1171
1172 HDF_LOGE("%s: start ...!", __func__);
1173 return retVal;
1174 }
1175
WalSetCountryCode(NetDevice * netDev,const char * code,uint32_t len)1176 int32_t WalSetCountryCode(NetDevice *netDev, const char *code, uint32_t len)
1177 {
1178 // NO SUPPORT
1179 (void)code;
1180 HDF_LOGE("%s: start...", __func__);
1181 if (netDev == NULL) {
1182 HDF_LOGE("%s:NULL ptr!", __func__);
1183 return HDF_FAILURE;
1184 }
1185 return HDF_SUCCESS;
1186
1187 }
1188
WalGetAssociatedStasCount(NetDevice * netDev,uint32_t * num)1189 int32_t WalGetAssociatedStasCount(NetDevice *netDev, uint32_t *num)
1190 {
1191 // NO SUPPORT
1192 (void)num;
1193 HDF_LOGE("%s: start...", __func__);
1194 if (netDev == NULL) {
1195 HDF_LOGE("%s:NULL ptr!", __func__);
1196 return HDF_FAILURE;
1197 }
1198 return HDF_SUCCESS;
1199
1200 }
1201
WalGetAssociatedStasInfo(NetDevice * netDev,WifiStaInfo * staInfo,uint32_t num)1202 int32_t WalGetAssociatedStasInfo(NetDevice *netDev, WifiStaInfo *staInfo, uint32_t num)
1203 {
1204 // NO SUPPORT
1205 (void)staInfo;
1206 (void)num;
1207 HDF_LOGE("%s: start...", __func__);
1208 if (netDev == NULL) {
1209 HDF_LOGE("%s:NULL ptr!", __func__);
1210 return HDF_FAILURE;
1211 }
1212 return HDF_SUCCESS;
1213
1214 }
1215
1216 /*--------------------------------------------------------------------------------------------------*/
1217 /*--------------------------------------------------------------------------------------------------*/
1218 /*--------------------------------------------------------------------------------------------------*/
1219 static struct HdfMac80211BaseOps g_baseOps =
1220 {
1221 .SetMode = WalSetMode,
1222 .AddKey = WalAddKey,
1223 .DelKey = WalDelKey,
1224 .SetDefaultKey = WalSetDefaultKey,
1225 .GetDeviceMacAddr = WalGetDeviceMacAddr,
1226 .SetMacAddr = WalSetMacAddr,
1227 .SetTxPower = WalSetTxPower,
1228 .GetValidFreqsWithBand = WalGetValidFreqsWithBand,
1229 .GetHwCapability = WalGetHwCapability,
1230 .SendAction = WalSendAction,
1231 .GetIftype = WalGetIftype,
1232 };
1233
1234 static struct HdfMac80211STAOps g_staOps =
1235 {
1236 .Connect = WalAuthenticate,
1237 .Disconnect = WalDisconnect,
1238 .StartScan = WalStartScan,
1239 .AbortScan = WalAbortScan,
1240 .SetScanningMacAddress = WalSetScanningMacAddress,
1241 };
1242
1243 static struct HdfMac80211APOps g_apOps =
1244 {
1245 .ConfigAp = WalConfigAp,
1246 .StartAp = WalStartAp,
1247 .StopAp = WalStopAp,
1248 .ConfigBeacon = WalChangeBeacon,
1249 .DelStation = WalDelStation,
1250 .SetCountryCode = WalSetCountryCode,
1251 .GetAssociatedStasCount = WalGetAssociatedStasCount,
1252 .GetAssociatedStasInfo = WalGetAssociatedStasInfo
1253 };
1254
1255 #ifdef XR829_WLAN_FEATURE_P2P
1256 static struct HdfMac80211P2POps g_p2pOps = {
1257 .RemainOnChannel = WalRemainOnChannel,
1258 .CancelRemainOnChannel = WalCancelRemainOnChannel,
1259 .ProbeReqReport = WalProbeReqReport,
1260 .AddIf = WalAddIf,
1261 .RemoveIf = WalRemoveIf,
1262 .SetApWpsP2pIe = WalSetApWpsP2pIe,
1263 .GetDriverFlag = WalGetDriverFlag,
1264 };
1265 #endif
1266
XrMac80211Init(struct HdfChipDriver * chipDriver)1267 void XrMac80211Init(struct HdfChipDriver *chipDriver)
1268 {
1269 HDF_LOGE("%s: start...", __func__);
1270
1271 if (chipDriver == NULL) {
1272 HDF_LOGE("%s: input is NULL", __func__);
1273 return;
1274 }
1275
1276 if (global_param == NULL) {
1277 global_param = kzalloc(sizeof(struct WlanConnectParams), GFP_KERNEL);
1278 }
1279 if (global_param == NULL) {
1280 HDF_LOGE("%s: global_param is NULL", __func__);
1281 return;
1282 }
1283
1284 chipDriver->ops = &g_baseOps;
1285 chipDriver->staOps = &g_staOps;
1286 chipDriver->apOps = &g_apOps;
1287 #ifdef XR829_WLAN_FEATURE_P2P
1288 chipDriver->p2pOps = g_p2pOps;
1289 #else
1290 chipDriver->p2pOps = NULL;
1291 #endif
1292 };
1293
1294 EXPORT_SYMBOL(inform_bss_frame);
1295 EXPORT_SYMBOL(inform_connect_result);
1296 EXPORT_SYMBOL(inform_auth_result);
1297