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 */
34 extern int mac_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
39 u8 broadcast
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
41 * @brief WILC_WFI_monitor_rx
44 * @return int : Return 0 on Success
50 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
51 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive*/
52 #define IS_MANAGMEMENT 0x100
53 #define IS_MANAGMEMENT_CALLBACK 0x080
54 #define IS_MGMT_STATUS_SUCCES 0x040
55 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
57 void WILC_WFI_monitor_rx(u8
*buff
, uint32_t size
)
59 uint32_t header
, pkt_offset
;
60 struct sk_buff
*skb
= NULL
;
61 struct wilc_wfi_radiotap_hdr
*hdr
;
62 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
64 PRINT_INFO(HOSTAPD_DBG
, "In monitor interface receive function\n");
66 /* struct wilc_priv *priv = netdev_priv(dev); */
68 /* priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
71 if (wilc_wfi_mon
== NULL
)
74 if (!netif_running(wilc_wfi_mon
)) {
75 PRINT_INFO(HOSTAPD_DBG
, "Monitor interface already RUNNING\n");
80 memcpy(&header
, (buff
- HOST_HDR_OFFSET
), HOST_HDR_OFFSET
);
82 /* The packet offset field conain info about what type of managment frame */
83 /* we are dealing with and ack status */
84 pkt_offset
= GET_PKT_OFFSET(header
);
86 if (pkt_offset
& IS_MANAGMEMENT_CALLBACK
) {
88 /* hostapd callback mgmt frame */
90 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
92 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
96 memcpy(skb_put(skb
, size
), buff
, size
);
98 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*) skb_push(skb
, sizeof(*cb_hdr
));
99 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
101 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
103 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
105 cb_hdr
->hdr
.it_present
= cpu_to_le32(
106 (1 << IEEE80211_RADIOTAP_RATE
) |
107 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
109 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
111 if (pkt_offset
& IS_MGMT_STATUS_SUCCES
) {
113 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_RTS
;
115 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_FAIL
;
120 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_hdr
));
123 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
127 /* skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC); */
128 /* if (skb == NULL) */
131 memcpy(skb_put(skb
, size
), buff
, size
);
132 hdr
= (struct wilc_wfi_radiotap_hdr
*) skb_push(skb
, sizeof(*hdr
));
133 memset(hdr
, 0, sizeof(struct wilc_wfi_radiotap_hdr
));
134 hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
135 /* hdr->hdr.it_pad = 0; */
136 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_hdr
));
137 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len %d\n", hdr
->hdr
.it_len
);
138 hdr
->hdr
.it_present
= cpu_to_le32
139 (1 << IEEE80211_RADIOTAP_RATE
); /* | */
140 /* (1 << IEEE80211_RADIOTAP_CHANNEL)); */
141 PRINT_INFO(HOSTAPD_DBG
, "Presentflags %d\n", hdr
->hdr
.it_present
);
142 hdr
->rate
= 5; /* txrate->bitrate / 5; */
146 /* if(INFO || if(skb->data[9] == 0x00 || skb->data[9] == 0xb0))
148 * for(i=0;i<skb->len;i++)
149 * PRINT_INFO(HOSTAPD_DBG,"Mon RxData[%d] = %02x\n",i,skb->data[i]);
153 skb
->dev
= wilc_wfi_mon
;
154 skb_set_mac_header(skb
, 0);
155 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
156 skb
->pkt_type
= PACKET_OTHERHOST
;
157 skb
->protocol
= htons(ETH_P_802_2
);
158 memset(skb
->cb
, 0, sizeof(skb
->cb
));
165 struct tx_complete_mon_data
{
170 static void mgmt_tx_complete(void *priv
, int status
)
173 /* struct sk_buff *skb2; */
174 /* struct wilc_wfi_radiotap_cb_hdr *cb_hdr; */
176 struct tx_complete_mon_data
*pv_data
= (struct tx_complete_mon_data
*)priv
;
177 u8
*buf
= pv_data
->buff
;
182 if (INFO
|| buf
[0] == 0x10 || buf
[0] == 0xb0)
183 PRINT_INFO(HOSTAPD_DBG
, "Packet sent successfully - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
185 PRINT_INFO(HOSTAPD_DBG
, "Couldn't send packet - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
189 /* //(skb->data[9] == 0x00 || skb->data[9] == 0xb0 || skb->data[9] == 0x40 || skb->data[9] == 0xd0 )
191 * skb2 = dev_alloc_skb(pv_data->size+sizeof(struct wilc_wfi_radiotap_cb_hdr));
193 * memcpy(skb_put(skb2,pv_data->size),pv_data->buff, pv_data->size);
195 * cb_hdr = (struct wilc_wfi_radiotap_cb_hdr *) skb_push(skb2, sizeof(*cb_hdr));
196 * memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
198 * cb_hdr->hdr.it_version = 0;//PKTHDR_RADIOTAP_VERSION;
200 * cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr));
202 * cb_hdr->hdr.it_present = cpu_to_le32(
203 * (1 << IEEE80211_RADIOTAP_RATE) |
204 * (1 << IEEE80211_RADIOTAP_TX_FLAGS));
206 * cb_hdr->rate = 5;//txrate->bitrate / 5;
207 * cb_hdr->tx_flags = 0x0004;
209 * skb2->dev = wilc_wfi_mon;
210 * skb_set_mac_header(skb2, 0);
211 * skb2->ip_summed = CHECKSUM_UNNECESSARY;
212 * skb2->pkt_type = PACKET_OTHERHOST;
213 * skb2->protocol = htons(ETH_P_802_2);
214 * memset(skb2->cb, 0, sizeof(skb2->cb));
219 /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */
220 kfree(pv_data
->buff
);
224 static int mon_mgmt_tx(struct net_device
*dev
, const u8
*buf
, size_t len
)
226 struct tx_complete_mon_data
*mgmt_tx
= NULL
;
229 PRINT_D(HOSTAPD_DBG
, "ERROR: dev == NULL\n");
233 netif_stop_queue(dev
);
234 mgmt_tx
= kmalloc(sizeof(struct tx_complete_mon_data
), GFP_ATOMIC
);
235 if (mgmt_tx
== NULL
) {
236 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
240 mgmt_tx
->buff
= kmalloc(len
, GFP_ATOMIC
);
241 if (mgmt_tx
->buff
== NULL
) {
242 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
250 memcpy(mgmt_tx
->buff
, buf
, len
);
251 g_linux_wlan
->oup
.wlan_add_mgmt_to_tx_que(mgmt_tx
, mgmt_tx
->buff
, mgmt_tx
->size
, mgmt_tx_complete
);
253 netif_wake_queue(dev
);
258 * @brief WILC_WFI_mon_xmit
261 * @return int : Return 0 on Success
266 static netdev_tx_t
WILC_WFI_mon_xmit(struct sk_buff
*skb
,
267 struct net_device
*dev
)
269 u32 rtap_len
, i
, ret
= 0;
270 struct WILC_WFI_mon_priv
*mon_priv
;
272 struct sk_buff
*skb2
;
273 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
276 if (wilc_wfi_mon
== NULL
)
279 /* if(skb->data[3] == 0x10 || skb->data[3] == 0xb0) */
281 mon_priv
= netdev_priv(wilc_wfi_mon
);
283 if (mon_priv
== NULL
) {
284 PRINT_ER("Monitor interface private structure is NULL\n");
289 rtap_len
= ieee80211_get_radiotap_len(skb
->data
);
290 if (skb
->len
< rtap_len
) {
291 PRINT_ER("Error in radiotap header\n");
294 /* skip the radiotap header */
295 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len: %d\n", rtap_len
);
298 for (i
= 0; i
< rtap_len
; i
++)
299 PRINT_INFO(HOSTAPD_DBG
, "Radiotap_hdr[%d] %02x\n", i
, skb
->data
[i
]);
301 /* Skip the ratio tap header */
302 skb_pull(skb
, rtap_len
);
304 if (skb
->data
[0] == 0xc0)
305 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]);
307 if (skb
->data
[0] == 0xc0 && (!(memcmp(broadcast
, &skb
->data
[4], 6)))) {
308 skb2
= dev_alloc_skb(skb
->len
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
310 memcpy(skb_put(skb2
, skb
->len
), skb
->data
, skb
->len
);
312 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*) skb_push(skb2
, sizeof(*cb_hdr
));
313 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
315 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
317 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
319 cb_hdr
->hdr
.it_present
= cpu_to_le32(
320 (1 << IEEE80211_RADIOTAP_RATE
) |
321 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
323 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
324 cb_hdr
->tx_flags
= 0x0004;
326 skb2
->dev
= wilc_wfi_mon
;
327 skb_set_mac_header(skb2
, 0);
328 skb2
->ip_summed
= CHECKSUM_UNNECESSARY
;
329 skb2
->pkt_type
= PACKET_OTHERHOST
;
330 skb2
->protocol
= htons(ETH_P_802_2
);
331 memset(skb2
->cb
, 0, sizeof(skb2
->cb
));
337 skb
->dev
= mon_priv
->real_ndev
;
339 PRINT_INFO(HOSTAPD_DBG
, "Skipping the radiotap header\n");
343 /* actual deliver of data is device-specific, and not shown here */
344 PRINT_INFO(HOSTAPD_DBG
, "SKB netdevice name = %s\n", skb
->dev
->name
);
345 PRINT_INFO(HOSTAPD_DBG
, "MONITOR real dev name = %s\n", mon_priv
->real_ndev
->name
);
347 /* Identify if Ethernet or MAC header (data or mgmt) */
348 memcpy(srcAdd
, &skb
->data
[10], 6);
349 memcpy(bssid
, &skb
->data
[16], 6);
350 /* if source address and bssid fields are equal>>Mac header */
351 /*send it to mgmt frames handler */
352 if (!(memcmp(srcAdd
, bssid
, 6))) {
353 mon_mgmt_tx(mon_priv
->real_ndev
, skb
->data
, skb
->len
);
356 ret
= mac_xmit(skb
, mon_priv
->real_ndev
);
358 /* return NETDEV_TX_OK; */
362 static const struct net_device_ops wilc_wfi_netdev_ops
= {
363 .ndo_start_xmit
= WILC_WFI_mon_xmit
,
368 * @brief WILC_WFI_mon_setup
371 * @return int : Return 0 on Success
376 static void WILC_WFI_mon_setup(struct net_device
*dev
)
379 dev
->netdev_ops
= &wilc_wfi_netdev_ops
;
380 /* dev->destructor = free_netdev; */
381 PRINT_INFO(CORECONFIG_DBG
, "In Ethernet setup function\n");
383 dev
->priv_flags
|= IFF_NO_QUEUE
;
384 dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
385 eth_zero_addr(dev
->dev_addr
);
389 unsigned char mac_add
[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x8f};
390 /* priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
391 /* mac_add = (u8*)WILC_MALLOC(ETH_ALEN); */
392 /* status = host_int_get_MacAddress(priv->hWILCWFIDrv,mac_add); */
393 /* mac_add[ETH_ALEN-1]+=1; */
394 memcpy(dev
->dev_addr
, mac_add
, ETH_ALEN
);
400 * @brief WILC_WFI_init_mon_interface
403 * @return int : Return 0 on Success
408 struct net_device
*WILC_WFI_init_mon_interface(const char *name
, struct net_device
*real_dev
)
412 u32 ret
= WILC_SUCCESS
;
413 struct WILC_WFI_mon_priv
*priv
;
415 /*If monitor interface is already initialized, return it*/
420 wilc_wfi_mon
= alloc_etherdev(sizeof(struct WILC_WFI_mon_priv
));
422 PRINT_ER("failed to allocate memory\n");
427 wilc_wfi_mon
->type
= ARPHRD_IEEE80211_RADIOTAP
;
428 strncpy(wilc_wfi_mon
->name
, name
, IFNAMSIZ
);
429 wilc_wfi_mon
->name
[IFNAMSIZ
- 1] = 0;
430 wilc_wfi_mon
->netdev_ops
= &wilc_wfi_netdev_ops
;
432 ret
= register_netdevice(wilc_wfi_mon
);
434 PRINT_ER(" register_netdevice failed (%d)\n", ret
);
437 priv
= netdev_priv(wilc_wfi_mon
);
439 PRINT_ER("private structure is NULL\n");
443 priv
->real_ndev
= real_dev
;
449 * @brief WILC_WFI_deinit_mon_interface
452 * @return int : Return 0 on Success
457 int WILC_WFI_deinit_mon_interface(void)
459 bool rollback_lock
= false;
461 if (wilc_wfi_mon
!= NULL
) {
462 PRINT_D(HOSTAPD_DBG
, "In Deinit monitor interface\n");
463 PRINT_D(HOSTAPD_DBG
, "RTNL is being locked\n");
464 if (rtnl_is_locked()) {
466 rollback_lock
= true;
468 PRINT_D(HOSTAPD_DBG
, "Unregister netdev\n");
469 unregister_netdev(wilc_wfi_mon
);
470 /* free_netdev(wilc_wfi_mon); */
474 rollback_lock
= false;
481 #endif /* WILC_AP_EXTERNAL_MLME */