3 * @brief File Operations OS wrapper functionality
5 * @sa wilc_wfi_netdevice.h
9 #include "wilc_wfi_cfgoperations.h"
10 #include "linux_wlan_common.h"
11 #include "wilc_wlan_if.h"
12 #include "wilc_wlan.h"
14 #ifdef WILC_AP_EXTERNAL_MLME
16 struct wilc_wfi_radiotap_hdr
{
17 struct ieee80211_radiotap_header hdr
;
20 } __attribute__((packed
));
22 struct wilc_wfi_radiotap_cb_hdr
{
23 struct ieee80211_radiotap_header hdr
;
28 } __attribute__((packed
));
30 extern linux_wlan_t
*g_linux_wlan
;
32 static struct net_device
*wilc_wfi_mon
; /* global monitor netdev */
35 extern int mac_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
41 u8 broadcast
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
43 * @brief WILC_WFI_monitor_rx
46 * @return int : Return 0 on Success
52 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
53 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive*/
54 #define IS_MANAGMEMENT 0x100
55 #define IS_MANAGMEMENT_CALLBACK 0x080
56 #define IS_MGMT_STATUS_SUCCES 0x040
57 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
59 void WILC_WFI_monitor_rx(uint8_t *buff
, uint32_t size
)
61 uint32_t header
, pkt_offset
;
62 struct sk_buff
*skb
= NULL
;
63 struct wilc_wfi_radiotap_hdr
*hdr
;
64 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
66 PRINT_INFO(HOSTAPD_DBG
, "In monitor interface receive function\n");
68 /* struct WILC_WFI_priv *priv = netdev_priv(dev); */
70 /* priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
73 if (wilc_wfi_mon
== NULL
)
76 if (!netif_running(wilc_wfi_mon
)) {
77 PRINT_INFO(HOSTAPD_DBG
, "Monitor interface already RUNNING\n");
82 memcpy(&header
, (buff
- HOST_HDR_OFFSET
), HOST_HDR_OFFSET
);
84 /* The packet offset field conain info about what type of managment frame */
85 /* we are dealing with and ack status */
86 pkt_offset
= GET_PKT_OFFSET(header
);
88 if (pkt_offset
& IS_MANAGMEMENT_CALLBACK
) {
90 /* hostapd callback mgmt frame */
92 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
94 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
98 memcpy(skb_put(skb
, size
), buff
, size
);
100 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*) skb_push(skb
, sizeof(*cb_hdr
));
101 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
103 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
105 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
107 cb_hdr
->hdr
.it_present
= cpu_to_le32(
108 (1 << IEEE80211_RADIOTAP_RATE
) |
109 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
111 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
113 if (pkt_offset
& IS_MGMT_STATUS_SUCCES
) {
115 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_RTS
;
117 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_FAIL
;
122 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_hdr
));
125 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
129 /* skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC); */
130 /* if (skb == NULL) */
133 memcpy(skb_put(skb
, size
), buff
, size
);
134 hdr
= (struct wilc_wfi_radiotap_hdr
*) skb_push(skb
, sizeof(*hdr
));
135 memset(hdr
, 0, sizeof(struct wilc_wfi_radiotap_hdr
));
136 hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
137 /* hdr->hdr.it_pad = 0; */
138 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_hdr
));
139 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len %d\n", hdr
->hdr
.it_len
);
140 hdr
->hdr
.it_present
= cpu_to_le32
141 (1 << IEEE80211_RADIOTAP_RATE
); /* | */
142 /* (1 << IEEE80211_RADIOTAP_CHANNEL)); */
143 PRINT_INFO(HOSTAPD_DBG
, "Presentflags %d\n", hdr
->hdr
.it_present
);
144 hdr
->rate
= 5; /* txrate->bitrate / 5; */
148 /* if(INFO || if(skb->data[9] == 0x00 || skb->data[9] == 0xb0))
150 * for(i=0;i<skb->len;i++)
151 * PRINT_INFO(HOSTAPD_DBG,"Mon RxData[%d] = %02x\n",i,skb->data[i]);
155 skb
->dev
= wilc_wfi_mon
;
156 skb_set_mac_header(skb
, 0);
157 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
158 skb
->pkt_type
= PACKET_OTHERHOST
;
159 skb
->protocol
= htons(ETH_P_802_2
);
160 memset(skb
->cb
, 0, sizeof(skb
->cb
));
167 struct tx_complete_mon_data
{
172 static void mgmt_tx_complete(void *priv
, int status
)
175 /* struct sk_buff *skb2; */
176 /* struct wilc_wfi_radiotap_cb_hdr *cb_hdr; */
178 struct tx_complete_mon_data
*pv_data
= (struct tx_complete_mon_data
*)priv
;
179 u8
*buf
= pv_data
->buff
;
184 if (INFO
|| buf
[0] == 0x10 || buf
[0] == 0xb0)
185 PRINT_INFO(HOSTAPD_DBG
, "Packet sent successfully - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
187 PRINT_INFO(HOSTAPD_DBG
, "Couldn't send packet - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
191 /* //(skb->data[9] == 0x00 || skb->data[9] == 0xb0 || skb->data[9] == 0x40 || skb->data[9] == 0xd0 )
193 * skb2 = dev_alloc_skb(pv_data->size+sizeof(struct wilc_wfi_radiotap_cb_hdr));
195 * memcpy(skb_put(skb2,pv_data->size),pv_data->buff, pv_data->size);
197 * cb_hdr = (struct wilc_wfi_radiotap_cb_hdr *) skb_push(skb2, sizeof(*cb_hdr));
198 * memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
200 * cb_hdr->hdr.it_version = 0;//PKTHDR_RADIOTAP_VERSION;
202 * cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr));
204 * cb_hdr->hdr.it_present = cpu_to_le32(
205 * (1 << IEEE80211_RADIOTAP_RATE) |
206 * (1 << IEEE80211_RADIOTAP_TX_FLAGS));
208 * cb_hdr->rate = 5;//txrate->bitrate / 5;
209 * cb_hdr->tx_flags = 0x0004;
211 * skb2->dev = wilc_wfi_mon;
212 * skb_set_mac_header(skb2, 0);
213 * skb2->ip_summed = CHECKSUM_UNNECESSARY;
214 * skb2->pkt_type = PACKET_OTHERHOST;
215 * skb2->protocol = htons(ETH_P_802_2);
216 * memset(skb2->cb, 0, sizeof(skb2->cb));
221 /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */
222 kfree(pv_data
->buff
);
226 static int mon_mgmt_tx(struct net_device
*dev
, const u8
*buf
, size_t len
)
228 struct tx_complete_mon_data
*mgmt_tx
= NULL
;
231 PRINT_D(HOSTAPD_DBG
, "ERROR: dev == NULL\n");
235 netif_stop_queue(dev
);
236 mgmt_tx
= kmalloc(sizeof(struct tx_complete_mon_data
), GFP_ATOMIC
);
237 if (mgmt_tx
== NULL
) {
238 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
242 mgmt_tx
->buff
= kmalloc(len
, GFP_ATOMIC
);
243 if (mgmt_tx
->buff
== NULL
) {
244 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
252 memcpy(mgmt_tx
->buff
, buf
, len
);
253 g_linux_wlan
->oup
.wlan_add_mgmt_to_tx_que(mgmt_tx
, mgmt_tx
->buff
, mgmt_tx
->size
, mgmt_tx_complete
);
255 netif_wake_queue(dev
);
260 * @brief WILC_WFI_mon_xmit
263 * @return int : Return 0 on Success
268 static netdev_tx_t
WILC_WFI_mon_xmit(struct sk_buff
*skb
,
269 struct net_device
*dev
)
271 u32 rtap_len
, i
, ret
= 0;
272 struct WILC_WFI_mon_priv
*mon_priv
;
274 struct sk_buff
*skb2
;
275 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
278 if (wilc_wfi_mon
== NULL
)
281 /* if(skb->data[3] == 0x10 || skb->data[3] == 0xb0) */
283 mon_priv
= netdev_priv(wilc_wfi_mon
);
285 if (mon_priv
== NULL
) {
286 PRINT_ER("Monitor interface private structure is NULL\n");
291 rtap_len
= ieee80211_get_radiotap_len(skb
->data
);
292 if (skb
->len
< rtap_len
) {
293 PRINT_ER("Error in radiotap header\n");
296 /* skip the radiotap header */
297 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len: %d\n", rtap_len
);
300 for (i
= 0; i
< rtap_len
; i
++)
301 PRINT_INFO(HOSTAPD_DBG
, "Radiotap_hdr[%d] %02x\n", i
, skb
->data
[i
]);
303 /* Skip the ratio tap header */
304 skb_pull(skb
, rtap_len
);
306 if (skb
->data
[0] == 0xc0)
307 PRINT_INFO(HOSTAPD_DBG
, "%x:%x:%x:%x:%x%x\n", skb
->data
[4], skb
->data
[5], skb
->data
[6], skb
->data
[7], skb
->data
[8], skb
->data
[9]);
309 if (skb
->data
[0] == 0xc0 && (!(memcmp(broadcast
, &skb
->data
[4], 6)))) {
310 skb2
= dev_alloc_skb(skb
->len
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
312 memcpy(skb_put(skb2
, skb
->len
), skb
->data
, skb
->len
);
314 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*) skb_push(skb2
, sizeof(*cb_hdr
));
315 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
317 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
319 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
321 cb_hdr
->hdr
.it_present
= cpu_to_le32(
322 (1 << IEEE80211_RADIOTAP_RATE
) |
323 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
325 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
326 cb_hdr
->tx_flags
= 0x0004;
328 skb2
->dev
= wilc_wfi_mon
;
329 skb_set_mac_header(skb2
, 0);
330 skb2
->ip_summed
= CHECKSUM_UNNECESSARY
;
331 skb2
->pkt_type
= PACKET_OTHERHOST
;
332 skb2
->protocol
= htons(ETH_P_802_2
);
333 memset(skb2
->cb
, 0, sizeof(skb2
->cb
));
339 skb
->dev
= mon_priv
->real_ndev
;
341 PRINT_INFO(HOSTAPD_DBG
, "Skipping the radiotap header\n");
345 /* actual deliver of data is device-specific, and not shown here */
346 PRINT_INFO(HOSTAPD_DBG
, "SKB netdevice name = %s\n", skb
->dev
->name
);
347 PRINT_INFO(HOSTAPD_DBG
, "MONITOR real dev name = %s\n", mon_priv
->real_ndev
->name
);
350 /* Identify if Ethernet or MAC header (data or mgmt) */
351 memcpy(srcAdd
, &skb
->data
[10], 6);
352 memcpy(bssid
, &skb
->data
[16], 6);
353 /* if source address and bssid fields are equal>>Mac header */
354 /*send it to mgmt frames handler */
355 if (!(memcmp(srcAdd
, bssid
, 6))) {
356 mon_mgmt_tx(mon_priv
->real_ndev
, skb
->data
, skb
->len
);
359 ret
= mac_xmit(skb
, mon_priv
->real_ndev
);
362 /* return NETDEV_TX_OK; */
366 static const struct net_device_ops wilc_wfi_netdev_ops
= {
367 .ndo_start_xmit
= WILC_WFI_mon_xmit
,
372 * @brief WILC_WFI_mon_setup
375 * @return int : Return 0 on Success
380 static void WILC_WFI_mon_setup(struct net_device
*dev
)
383 dev
->netdev_ops
= &wilc_wfi_netdev_ops
;
384 /* dev->destructor = free_netdev; */
385 PRINT_INFO(CORECONFIG_DBG
, "In Ethernet setup function\n");
387 dev
->priv_flags
|= IFF_NO_QUEUE
;
388 dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
389 eth_zero_addr(dev
->dev_addr
);
394 unsigned char mac_add
[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x8f};
395 /* priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
396 /* mac_add = (u8*)WILC_MALLOC(ETH_ALEN); */
397 /* status = host_int_get_MacAddress(priv->hWILCWFIDrv,mac_add); */
398 /* mac_add[ETH_ALEN-1]+=1; */
399 memcpy(dev
->dev_addr
, mac_add
, ETH_ALEN
);
402 dev
->dev_addr
[0] = 0x12;
408 * @brief WILC_WFI_init_mon_interface
411 * @return int : Return 0 on Success
416 struct net_device
*WILC_WFI_init_mon_interface(const char *name
, struct net_device
*real_dev
)
420 u32 ret
= WILC_SUCCESS
;
421 struct WILC_WFI_mon_priv
*priv
;
423 /*If monitor interface is already initialized, return it*/
428 wilc_wfi_mon
= alloc_etherdev(sizeof(struct WILC_WFI_mon_priv
));
430 PRINT_ER("failed to allocate memory\n");
435 wilc_wfi_mon
->type
= ARPHRD_IEEE80211_RADIOTAP
;
436 strncpy(wilc_wfi_mon
->name
, name
, IFNAMSIZ
);
437 wilc_wfi_mon
->name
[IFNAMSIZ
- 1] = 0;
438 wilc_wfi_mon
->netdev_ops
= &wilc_wfi_netdev_ops
;
440 ret
= register_netdevice(wilc_wfi_mon
);
442 PRINT_ER(" register_netdevice failed (%d)\n", ret
);
445 priv
= netdev_priv(wilc_wfi_mon
);
447 PRINT_ER("private structure is NULL\n");
451 priv
->real_ndev
= real_dev
;
457 * @brief WILC_WFI_deinit_mon_interface
460 * @return int : Return 0 on Success
465 int WILC_WFI_deinit_mon_interface(void)
467 bool rollback_lock
= false;
469 if (wilc_wfi_mon
!= NULL
) {
470 PRINT_D(HOSTAPD_DBG
, "In Deinit monitor interface\n");
471 PRINT_D(HOSTAPD_DBG
, "RTNL is being locked\n");
472 if (rtnl_is_locked()) {
474 rollback_lock
= true;
476 PRINT_D(HOSTAPD_DBG
, "Unregister netdev\n");
477 unregister_netdev(wilc_wfi_mon
);
478 /* free_netdev(wilc_wfi_mon); */
482 rollback_lock
= false;
489 #endif /* WILC_AP_EXTERNAL_MLME */