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 struct wilc_wfi_radiotap_hdr
{
15 struct ieee80211_radiotap_header hdr
;
19 struct wilc_wfi_radiotap_cb_hdr
{
20 struct ieee80211_radiotap_header hdr
;
26 static struct net_device
*wilc_wfi_mon
; /* global monitor netdev */
30 static u8 broadcast
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
32 * @brief WILC_WFI_monitor_rx
35 * @return int : Return 0 on Success
41 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
42 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive*/
43 #define IS_MANAGMEMENT 0x100
44 #define IS_MANAGMEMENT_CALLBACK 0x080
45 #define IS_MGMT_STATUS_SUCCES 0x040
46 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
48 void WILC_WFI_monitor_rx(u8
*buff
, u32 size
)
50 u32 header
, pkt_offset
;
51 struct sk_buff
*skb
= NULL
;
52 struct wilc_wfi_radiotap_hdr
*hdr
;
53 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
55 PRINT_INFO(HOSTAPD_DBG
, "In monitor interface receive function\n");
60 if (!netif_running(wilc_wfi_mon
)) {
61 PRINT_INFO(HOSTAPD_DBG
, "Monitor interface already RUNNING\n");
66 memcpy(&header
, (buff
- HOST_HDR_OFFSET
), HOST_HDR_OFFSET
);
68 /* The packet offset field conain info about what type of managment frame */
69 /* we are dealing with and ack status */
70 pkt_offset
= GET_PKT_OFFSET(header
);
72 if (pkt_offset
& IS_MANAGMEMENT_CALLBACK
) {
73 /* hostapd callback mgmt frame */
75 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
77 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
81 memcpy(skb_put(skb
, size
), buff
, size
);
83 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*)skb_push(skb
, sizeof(*cb_hdr
));
84 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
86 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
88 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
90 cb_hdr
->hdr
.it_present
= cpu_to_le32(
91 (1 << IEEE80211_RADIOTAP_RATE
) |
92 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
94 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
96 if (pkt_offset
& IS_MGMT_STATUS_SUCCES
) {
98 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_RTS
;
100 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_FAIL
;
104 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_hdr
));
107 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
111 memcpy(skb_put(skb
, size
), buff
, size
);
112 hdr
= (struct wilc_wfi_radiotap_hdr
*)skb_push(skb
, sizeof(*hdr
));
113 memset(hdr
, 0, sizeof(struct wilc_wfi_radiotap_hdr
));
114 hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
115 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_hdr
));
116 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len %d\n", hdr
->hdr
.it_len
);
117 hdr
->hdr
.it_present
= cpu_to_le32
118 (1 << IEEE80211_RADIOTAP_RATE
); /* | */
119 PRINT_INFO(HOSTAPD_DBG
, "Presentflags %d\n", hdr
->hdr
.it_present
);
120 hdr
->rate
= 5; /* txrate->bitrate / 5; */
123 skb
->dev
= wilc_wfi_mon
;
124 skb_set_mac_header(skb
, 0);
125 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
126 skb
->pkt_type
= PACKET_OTHERHOST
;
127 skb
->protocol
= htons(ETH_P_802_2
);
128 memset(skb
->cb
, 0, sizeof(skb
->cb
));
133 struct tx_complete_mon_data
{
138 static void mgmt_tx_complete(void *priv
, int status
)
140 struct tx_complete_mon_data
*pv_data
= (struct tx_complete_mon_data
*)priv
;
141 u8
*buf
= pv_data
->buff
;
144 if (INFO
|| buf
[0] == 0x10 || buf
[0] == 0xb0)
145 PRINT_INFO(HOSTAPD_DBG
, "Packet sent successfully - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
147 PRINT_INFO(HOSTAPD_DBG
, "Couldn't send packet - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
150 /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */
151 kfree(pv_data
->buff
);
156 static int mon_mgmt_tx(struct net_device
*dev
, const u8
*buf
, size_t len
)
158 struct tx_complete_mon_data
*mgmt_tx
= NULL
;
161 PRINT_D(HOSTAPD_DBG
, "ERROR: dev == NULL\n");
165 netif_stop_queue(dev
);
166 mgmt_tx
= kmalloc(sizeof(*mgmt_tx
), GFP_ATOMIC
);
168 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
172 mgmt_tx
->buff
= kmalloc(len
, GFP_ATOMIC
);
173 if (!mgmt_tx
->buff
) {
174 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
181 memcpy(mgmt_tx
->buff
, buf
, len
);
182 wilc_wlan_txq_add_mgmt_pkt(dev
, mgmt_tx
, mgmt_tx
->buff
, mgmt_tx
->size
,
185 netif_wake_queue(dev
);
190 * @brief WILC_WFI_mon_xmit
193 * @return int : Return 0 on Success
198 static netdev_tx_t
WILC_WFI_mon_xmit(struct sk_buff
*skb
,
199 struct net_device
*dev
)
201 u32 rtap_len
, i
, ret
= 0;
202 struct WILC_WFI_mon_priv
*mon_priv
;
204 struct sk_buff
*skb2
;
205 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
210 mon_priv
= netdev_priv(wilc_wfi_mon
);
213 PRINT_ER("Monitor interface private structure is NULL\n");
217 rtap_len
= ieee80211_get_radiotap_len(skb
->data
);
218 if (skb
->len
< rtap_len
) {
219 PRINT_ER("Error in radiotap header\n");
222 /* skip the radiotap header */
223 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len: %d\n", rtap_len
);
226 for (i
= 0; i
< rtap_len
; i
++)
227 PRINT_INFO(HOSTAPD_DBG
, "Radiotap_hdr[%d] %02x\n", i
, skb
->data
[i
]);
229 /* Skip the ratio tap header */
230 skb_pull(skb
, rtap_len
);
232 if (skb
->data
[0] == 0xc0)
233 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]);
235 if (skb
->data
[0] == 0xc0 && (!(memcmp(broadcast
, &skb
->data
[4], 6)))) {
236 skb2
= dev_alloc_skb(skb
->len
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
238 memcpy(skb_put(skb2
, skb
->len
), skb
->data
, skb
->len
);
240 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*)skb_push(skb2
, sizeof(*cb_hdr
));
241 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
243 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
245 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
247 cb_hdr
->hdr
.it_present
= cpu_to_le32(
248 (1 << IEEE80211_RADIOTAP_RATE
) |
249 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
251 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
252 cb_hdr
->tx_flags
= 0x0004;
254 skb2
->dev
= wilc_wfi_mon
;
255 skb_set_mac_header(skb2
, 0);
256 skb2
->ip_summed
= CHECKSUM_UNNECESSARY
;
257 skb2
->pkt_type
= PACKET_OTHERHOST
;
258 skb2
->protocol
= htons(ETH_P_802_2
);
259 memset(skb2
->cb
, 0, sizeof(skb2
->cb
));
265 skb
->dev
= mon_priv
->real_ndev
;
267 PRINT_INFO(HOSTAPD_DBG
, "Skipping the radiotap header\n");
269 /* actual deliver of data is device-specific, and not shown here */
270 PRINT_INFO(HOSTAPD_DBG
, "SKB netdevice name = %s\n", skb
->dev
->name
);
271 PRINT_INFO(HOSTAPD_DBG
, "MONITOR real dev name = %s\n", mon_priv
->real_ndev
->name
);
273 /* Identify if Ethernet or MAC header (data or mgmt) */
274 memcpy(srcAdd
, &skb
->data
[10], 6);
275 memcpy(bssid
, &skb
->data
[16], 6);
276 /* if source address and bssid fields are equal>>Mac header */
277 /*send it to mgmt frames handler */
278 if (!(memcmp(srcAdd
, bssid
, 6))) {
279 mon_mgmt_tx(mon_priv
->real_ndev
, skb
->data
, skb
->len
);
282 ret
= wilc_mac_xmit(skb
, mon_priv
->real_ndev
);
288 static const struct net_device_ops wilc_wfi_netdev_ops
= {
289 .ndo_start_xmit
= WILC_WFI_mon_xmit
,
294 * @brief WILC_WFI_init_mon_interface
297 * @return int : Return 0 on Success
302 struct net_device
*WILC_WFI_init_mon_interface(const char *name
, struct net_device
*real_dev
)
305 struct WILC_WFI_mon_priv
*priv
;
307 /*If monitor interface is already initialized, return it*/
312 wilc_wfi_mon
= alloc_etherdev(sizeof(struct WILC_WFI_mon_priv
));
314 PRINT_ER("failed to allocate memory\n");
318 wilc_wfi_mon
->type
= ARPHRD_IEEE80211_RADIOTAP
;
319 strncpy(wilc_wfi_mon
->name
, name
, IFNAMSIZ
);
320 wilc_wfi_mon
->name
[IFNAMSIZ
- 1] = 0;
321 wilc_wfi_mon
->netdev_ops
= &wilc_wfi_netdev_ops
;
323 ret
= register_netdevice(wilc_wfi_mon
);
325 PRINT_ER(" register_netdevice failed (%d)\n", ret
);
328 priv
= netdev_priv(wilc_wfi_mon
);
330 PRINT_ER("private structure is NULL\n");
334 priv
->real_ndev
= real_dev
;
340 * @brief WILC_WFI_deinit_mon_interface
343 * @return int : Return 0 on Success
348 int WILC_WFI_deinit_mon_interface(void)
350 bool rollback_lock
= false;
353 PRINT_D(HOSTAPD_DBG
, "In Deinit monitor interface\n");
354 PRINT_D(HOSTAPD_DBG
, "RTNL is being locked\n");
355 if (rtnl_is_locked()) {
357 rollback_lock
= true;
359 PRINT_D(HOSTAPD_DBG
, "Unregister netdev\n");
360 unregister_netdev(wilc_wfi_mon
);
364 rollback_lock
= false;