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
;
19 } __attribute__((packed
));
21 struct wilc_wfi_radiotap_cb_hdr
{
22 struct ieee80211_radiotap_header hdr
;
26 } __attribute__((packed
));
28 extern linux_wlan_t
*g_linux_wlan
;
30 static struct net_device
*wilc_wfi_mon
; /* global monitor netdev */
32 extern int mac_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
37 u8 broadcast
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
39 * @brief WILC_WFI_monitor_rx
42 * @return int : Return 0 on Success
48 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
49 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive*/
50 #define IS_MANAGMEMENT 0x100
51 #define IS_MANAGMEMENT_CALLBACK 0x080
52 #define IS_MGMT_STATUS_SUCCES 0x040
53 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
55 void WILC_WFI_monitor_rx(u8
*buff
, u32 size
)
57 u32 header
, pkt_offset
;
58 struct sk_buff
*skb
= NULL
;
59 struct wilc_wfi_radiotap_hdr
*hdr
;
60 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
62 PRINT_INFO(HOSTAPD_DBG
, "In monitor interface receive function\n");
65 if (wilc_wfi_mon
== NULL
)
68 if (!netif_running(wilc_wfi_mon
)) {
69 PRINT_INFO(HOSTAPD_DBG
, "Monitor interface already RUNNING\n");
74 memcpy(&header
, (buff
- HOST_HDR_OFFSET
), HOST_HDR_OFFSET
);
76 /* The packet offset field conain info about what type of managment frame */
77 /* we are dealing with and ack status */
78 pkt_offset
= GET_PKT_OFFSET(header
);
80 if (pkt_offset
& IS_MANAGMEMENT_CALLBACK
) {
82 /* hostapd callback mgmt frame */
84 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
86 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
90 memcpy(skb_put(skb
, size
), buff
, size
);
92 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*) skb_push(skb
, sizeof(*cb_hdr
));
93 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
95 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
97 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
99 cb_hdr
->hdr
.it_present
= cpu_to_le32(
100 (1 << IEEE80211_RADIOTAP_RATE
) |
101 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
103 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
105 if (pkt_offset
& IS_MGMT_STATUS_SUCCES
) {
107 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_RTS
;
109 cb_hdr
->tx_flags
= IEEE80211_RADIOTAP_F_TX_FAIL
;
114 skb
= dev_alloc_skb(size
+ sizeof(struct wilc_wfi_radiotap_hdr
));
117 PRINT_INFO(HOSTAPD_DBG
, "Monitor if : No memory to allocate skb");
121 memcpy(skb_put(skb
, size
), buff
, size
);
122 hdr
= (struct wilc_wfi_radiotap_hdr
*) skb_push(skb
, sizeof(*hdr
));
123 memset(hdr
, 0, sizeof(struct wilc_wfi_radiotap_hdr
));
124 hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
125 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_hdr
));
126 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len %d\n", hdr
->hdr
.it_len
);
127 hdr
->hdr
.it_present
= cpu_to_le32
128 (1 << IEEE80211_RADIOTAP_RATE
); /* | */
129 PRINT_INFO(HOSTAPD_DBG
, "Presentflags %d\n", hdr
->hdr
.it_present
);
130 hdr
->rate
= 5; /* txrate->bitrate / 5; */
136 skb
->dev
= wilc_wfi_mon
;
137 skb_set_mac_header(skb
, 0);
138 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
139 skb
->pkt_type
= PACKET_OTHERHOST
;
140 skb
->protocol
= htons(ETH_P_802_2
);
141 memset(skb
->cb
, 0, sizeof(skb
->cb
));
148 struct tx_complete_mon_data
{
153 static void mgmt_tx_complete(void *priv
, int status
)
156 struct tx_complete_mon_data
*pv_data
= (struct tx_complete_mon_data
*)priv
;
157 u8
*buf
= pv_data
->buff
;
162 if (INFO
|| buf
[0] == 0x10 || buf
[0] == 0xb0)
163 PRINT_INFO(HOSTAPD_DBG
, "Packet sent successfully - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
165 PRINT_INFO(HOSTAPD_DBG
, "Couldn't send packet - Size = %d - Address = %p.\n", pv_data
->size
, pv_data
->buff
);
170 /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */
171 kfree(pv_data
->buff
);
175 static int mon_mgmt_tx(struct net_device
*dev
, const u8
*buf
, size_t len
)
177 struct tx_complete_mon_data
*mgmt_tx
= NULL
;
180 PRINT_D(HOSTAPD_DBG
, "ERROR: dev == NULL\n");
184 netif_stop_queue(dev
);
185 mgmt_tx
= kmalloc(sizeof(struct tx_complete_mon_data
), GFP_ATOMIC
);
186 if (mgmt_tx
== NULL
) {
187 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
191 mgmt_tx
->buff
= kmalloc(len
, GFP_ATOMIC
);
192 if (mgmt_tx
->buff
== NULL
) {
193 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
201 memcpy(mgmt_tx
->buff
, buf
, len
);
202 g_linux_wlan
->oup
.wlan_add_mgmt_to_tx_que(mgmt_tx
, mgmt_tx
->buff
, mgmt_tx
->size
, mgmt_tx_complete
);
204 netif_wake_queue(dev
);
209 * @brief WILC_WFI_mon_xmit
212 * @return int : Return 0 on Success
217 static netdev_tx_t
WILC_WFI_mon_xmit(struct sk_buff
*skb
,
218 struct net_device
*dev
)
220 u32 rtap_len
, i
, ret
= 0;
221 struct WILC_WFI_mon_priv
*mon_priv
;
223 struct sk_buff
*skb2
;
224 struct wilc_wfi_radiotap_cb_hdr
*cb_hdr
;
227 if (wilc_wfi_mon
== NULL
)
230 mon_priv
= netdev_priv(wilc_wfi_mon
);
232 if (mon_priv
== NULL
) {
233 PRINT_ER("Monitor interface private structure is NULL\n");
238 rtap_len
= ieee80211_get_radiotap_len(skb
->data
);
239 if (skb
->len
< rtap_len
) {
240 PRINT_ER("Error in radiotap header\n");
243 /* skip the radiotap header */
244 PRINT_INFO(HOSTAPD_DBG
, "Radiotap len: %d\n", rtap_len
);
247 for (i
= 0; i
< rtap_len
; i
++)
248 PRINT_INFO(HOSTAPD_DBG
, "Radiotap_hdr[%d] %02x\n", i
, skb
->data
[i
]);
250 /* Skip the ratio tap header */
251 skb_pull(skb
, rtap_len
);
253 if (skb
->data
[0] == 0xc0)
254 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]);
256 if (skb
->data
[0] == 0xc0 && (!(memcmp(broadcast
, &skb
->data
[4], 6)))) {
257 skb2
= dev_alloc_skb(skb
->len
+ sizeof(struct wilc_wfi_radiotap_cb_hdr
));
259 memcpy(skb_put(skb2
, skb
->len
), skb
->data
, skb
->len
);
261 cb_hdr
= (struct wilc_wfi_radiotap_cb_hdr
*) skb_push(skb2
, sizeof(*cb_hdr
));
262 memset(cb_hdr
, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr
));
264 cb_hdr
->hdr
.it_version
= 0; /* PKTHDR_RADIOTAP_VERSION; */
266 cb_hdr
->hdr
.it_len
= cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr
));
268 cb_hdr
->hdr
.it_present
= cpu_to_le32(
269 (1 << IEEE80211_RADIOTAP_RATE
) |
270 (1 << IEEE80211_RADIOTAP_TX_FLAGS
));
272 cb_hdr
->rate
= 5; /* txrate->bitrate / 5; */
273 cb_hdr
->tx_flags
= 0x0004;
275 skb2
->dev
= wilc_wfi_mon
;
276 skb_set_mac_header(skb2
, 0);
277 skb2
->ip_summed
= CHECKSUM_UNNECESSARY
;
278 skb2
->pkt_type
= PACKET_OTHERHOST
;
279 skb2
->protocol
= htons(ETH_P_802_2
);
280 memset(skb2
->cb
, 0, sizeof(skb2
->cb
));
286 skb
->dev
= mon_priv
->real_ndev
;
288 PRINT_INFO(HOSTAPD_DBG
, "Skipping the radiotap header\n");
292 /* actual deliver of data is device-specific, and not shown here */
293 PRINT_INFO(HOSTAPD_DBG
, "SKB netdevice name = %s\n", skb
->dev
->name
);
294 PRINT_INFO(HOSTAPD_DBG
, "MONITOR real dev name = %s\n", mon_priv
->real_ndev
->name
);
296 /* Identify if Ethernet or MAC header (data or mgmt) */
297 memcpy(srcAdd
, &skb
->data
[10], 6);
298 memcpy(bssid
, &skb
->data
[16], 6);
299 /* if source address and bssid fields are equal>>Mac header */
300 /*send it to mgmt frames handler */
301 if (!(memcmp(srcAdd
, bssid
, 6))) {
302 mon_mgmt_tx(mon_priv
->real_ndev
, skb
->data
, skb
->len
);
305 ret
= mac_xmit(skb
, mon_priv
->real_ndev
);
310 static const struct net_device_ops wilc_wfi_netdev_ops
= {
311 .ndo_start_xmit
= WILC_WFI_mon_xmit
,
316 * @brief WILC_WFI_mon_setup
319 * @return int : Return 0 on Success
324 static void WILC_WFI_mon_setup(struct net_device
*dev
)
327 dev
->netdev_ops
= &wilc_wfi_netdev_ops
;
328 PRINT_INFO(CORECONFIG_DBG
, "In Ethernet setup function\n");
330 dev
->priv_flags
|= IFF_NO_QUEUE
;
331 dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
332 eth_zero_addr(dev
->dev_addr
);
335 unsigned char mac_add
[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x8f};
336 memcpy(dev
->dev_addr
, mac_add
, ETH_ALEN
);
342 * @brief WILC_WFI_init_mon_interface
345 * @return int : Return 0 on Success
350 struct net_device
*WILC_WFI_init_mon_interface(const char *name
, struct net_device
*real_dev
)
355 struct WILC_WFI_mon_priv
*priv
;
357 /*If monitor interface is already initialized, return it*/
362 wilc_wfi_mon
= alloc_etherdev(sizeof(struct WILC_WFI_mon_priv
));
364 PRINT_ER("failed to allocate memory\n");
369 wilc_wfi_mon
->type
= ARPHRD_IEEE80211_RADIOTAP
;
370 strncpy(wilc_wfi_mon
->name
, name
, IFNAMSIZ
);
371 wilc_wfi_mon
->name
[IFNAMSIZ
- 1] = 0;
372 wilc_wfi_mon
->netdev_ops
= &wilc_wfi_netdev_ops
;
374 ret
= register_netdevice(wilc_wfi_mon
);
376 PRINT_ER(" register_netdevice failed (%d)\n", ret
);
379 priv
= netdev_priv(wilc_wfi_mon
);
381 PRINT_ER("private structure is NULL\n");
385 priv
->real_ndev
= real_dev
;
391 * @brief WILC_WFI_deinit_mon_interface
394 * @return int : Return 0 on Success
399 int WILC_WFI_deinit_mon_interface(void)
401 bool rollback_lock
= false;
403 if (wilc_wfi_mon
!= NULL
) {
404 PRINT_D(HOSTAPD_DBG
, "In Deinit monitor interface\n");
405 PRINT_D(HOSTAPD_DBG
, "RTNL is being locked\n");
406 if (rtnl_is_locked()) {
408 rollback_lock
= true;
410 PRINT_D(HOSTAPD_DBG
, "Unregister netdev\n");
411 unregister_netdev(wilc_wfi_mon
);
415 rollback_lock
= false;
422 #endif /* WILC_AP_EXTERNAL_MLME */