3 * @brief File Operations OS wrapper functionality
5 * @sa wilc_wfi_netdevice.h
9 #include "wilc_wfi_cfgoperations.h"
10 #include "wilc_wlan_if.h"
11 #include "wilc_wlan.h"
13 struct wilc_wfi_radiotap_hdr {
14 struct ieee80211_radiotap_header hdr;
18 struct wilc_wfi_radiotap_cb_hdr {
19 struct ieee80211_radiotap_header hdr;
25 static struct net_device *wilc_wfi_mon; /* global monitor netdev */
29 static u8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
31 * @brief WILC_WFI_monitor_rx
34 * @return int : Return 0 on Success
40 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
41 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive*/
42 #define IS_MANAGMEMENT 0x100
43 #define IS_MANAGMEMENT_CALLBACK 0x080
44 #define IS_MGMT_STATUS_SUCCES 0x040
45 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
47 void WILC_WFI_monitor_rx(u8 *buff, u32 size)
49 u32 header, pkt_offset;
50 struct sk_buff *skb = NULL;
51 struct wilc_wfi_radiotap_hdr *hdr;
52 struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
57 if (!netif_running(wilc_wfi_mon))
61 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
63 * The packet offset field contain info about what type of management
64 * the frame we are dealing with and ack status
66 pkt_offset = GET_PKT_OFFSET(header);
68 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
69 /* hostapd callback mgmt frame */
71 skb = dev_alloc_skb(size + sizeof(struct wilc_wfi_radiotap_cb_hdr));
75 skb_put_data(skb, buff, size);
77 cb_hdr = skb_push(skb, sizeof(*cb_hdr));
78 memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
80 cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
82 cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr));
84 cb_hdr->hdr.it_present = cpu_to_le32(
85 (1 << IEEE80211_RADIOTAP_RATE) |
86 (1 << IEEE80211_RADIOTAP_TX_FLAGS));
88 cb_hdr->rate = 5; /* txrate->bitrate / 5; */
90 if (pkt_offset & IS_MGMT_STATUS_SUCCES) {
92 cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_RTS;
94 cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_FAIL;
98 skb = dev_alloc_skb(size + sizeof(struct wilc_wfi_radiotap_hdr));
103 skb_put_data(skb, buff, size);
104 hdr = skb_push(skb, sizeof(*hdr));
105 memset(hdr, 0, sizeof(struct wilc_wfi_radiotap_hdr));
106 hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
107 hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_hdr));
108 hdr->hdr.it_present = cpu_to_le32
109 (1 << IEEE80211_RADIOTAP_RATE); /* | */
110 hdr->rate = 5; /* txrate->bitrate / 5; */
113 skb->dev = wilc_wfi_mon;
114 skb_reset_mac_header(skb);
115 skb->ip_summed = CHECKSUM_UNNECESSARY;
116 skb->pkt_type = PACKET_OTHERHOST;
117 skb->protocol = htons(ETH_P_802_2);
118 memset(skb->cb, 0, sizeof(skb->cb));
123 struct tx_complete_mon_data {
128 static void mgmt_tx_complete(void *priv, int status)
130 struct tx_complete_mon_data *pv_data = priv;
132 * in case of fully hosting mode, the freeing will be done
133 * in response to the cfg packet
135 kfree(pv_data->buff);
140 static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len)
142 struct tx_complete_mon_data *mgmt_tx = NULL;
147 netif_stop_queue(dev);
148 mgmt_tx = kmalloc(sizeof(*mgmt_tx), GFP_ATOMIC);
152 mgmt_tx->buff = kmalloc(len, GFP_ATOMIC);
153 if (!mgmt_tx->buff) {
160 memcpy(mgmt_tx->buff, buf, len);
161 wilc_wlan_txq_add_mgmt_pkt(dev, mgmt_tx, mgmt_tx->buff, mgmt_tx->size,
164 netif_wake_queue(dev);
169 * @brief WILC_WFI_mon_xmit
172 * @return int : Return 0 on Success
177 static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
178 struct net_device *dev)
180 u32 rtap_len, ret = 0;
181 struct WILC_WFI_mon_priv *mon_priv;
183 struct sk_buff *skb2;
184 struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
189 mon_priv = netdev_priv(wilc_wfi_mon);
192 rtap_len = ieee80211_get_radiotap_len(skb->data);
193 if (skb->len < rtap_len)
196 skb_pull(skb, rtap_len);
198 if (skb->data[0] == 0xc0 && (!(memcmp(broadcast, &skb->data[4], 6)))) {
199 skb2 = dev_alloc_skb(skb->len + sizeof(struct wilc_wfi_radiotap_cb_hdr));
203 skb_put_data(skb2, skb->data, skb->len);
205 cb_hdr = skb_push(skb2, sizeof(*cb_hdr));
206 memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
208 cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
210 cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr));
212 cb_hdr->hdr.it_present = cpu_to_le32(
213 (1 << IEEE80211_RADIOTAP_RATE) |
214 (1 << IEEE80211_RADIOTAP_TX_FLAGS));
216 cb_hdr->rate = 5; /* txrate->bitrate / 5; */
217 cb_hdr->tx_flags = 0x0004;
219 skb2->dev = wilc_wfi_mon;
220 skb_reset_mac_header(skb2);
221 skb2->ip_summed = CHECKSUM_UNNECESSARY;
222 skb2->pkt_type = PACKET_OTHERHOST;
223 skb2->protocol = htons(ETH_P_802_2);
224 memset(skb2->cb, 0, sizeof(skb2->cb));
230 skb->dev = mon_priv->real_ndev;
232 /* Identify if Ethernet or MAC header (data or mgmt) */
233 memcpy(srcadd, &skb->data[10], 6);
234 memcpy(bssid, &skb->data[16], 6);
235 /* if source address and bssid fields are equal>>Mac header */
236 /*send it to mgmt frames handler */
237 if (!(memcmp(srcadd, bssid, 6))) {
238 ret = mon_mgmt_tx(mon_priv->real_ndev, skb->data, skb->len);
240 netdev_err(dev, "fail to mgmt tx\n");
243 ret = wilc_mac_xmit(skb, mon_priv->real_ndev);
249 static const struct net_device_ops wilc_wfi_netdev_ops = {
250 .ndo_start_xmit = WILC_WFI_mon_xmit,
255 * @brief WILC_WFI_init_mon_interface
258 * @return int : Return 0 on Success
263 struct net_device *WILC_WFI_init_mon_interface(const char *name,
264 struct net_device *real_dev)
267 struct WILC_WFI_mon_priv *priv;
269 /*If monitor interface is already initialized, return it*/
273 wilc_wfi_mon = alloc_etherdev(sizeof(struct WILC_WFI_mon_priv));
276 wilc_wfi_mon->type = ARPHRD_IEEE80211_RADIOTAP;
277 strncpy(wilc_wfi_mon->name, name, IFNAMSIZ);
278 wilc_wfi_mon->name[IFNAMSIZ - 1] = 0;
279 wilc_wfi_mon->netdev_ops = &wilc_wfi_netdev_ops;
281 ret = register_netdevice(wilc_wfi_mon);
283 netdev_err(real_dev, "register_netdevice failed\n");
286 priv = netdev_priv(wilc_wfi_mon);
290 priv->real_ndev = real_dev;
296 * @brief WILC_WFI_deinit_mon_interface
299 * @return int : Return 0 on Success
304 int WILC_WFI_deinit_mon_interface(void)
306 bool rollback_lock = false;
309 if (rtnl_is_locked()) {
311 rollback_lock = true;
313 unregister_netdev(wilc_wfi_mon);
317 rollback_lock = false;