Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | /*! |
| 2 | * @file linux_mon.c |
| 3 | * @brief File Operations OS wrapper functionality |
| 4 | * @author mdaftedar |
| 5 | * @sa wilc_wfi_netdevice.h |
| 6 | * @date 01 MAR 2012 |
| 7 | * @version 1.0 |
| 8 | */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 9 | #include "wilc_wfi_cfgoperations.h" |
| 10 | #include "linux_wlan_common.h" |
| 11 | #include "wilc_wlan_if.h" |
| 12 | #include "wilc_wlan.h" |
Tony Cho | 9690df3 | 2015-07-28 17:47:22 +0900 | [diff] [blame] | 13 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 14 | #ifdef WILC_AP_EXTERNAL_MLME |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 15 | |
| 16 | struct wilc_wfi_radiotap_hdr { |
| 17 | struct ieee80211_radiotap_header hdr; |
| 18 | u8 rate; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 19 | } __attribute__((packed)); |
| 20 | |
| 21 | struct wilc_wfi_radiotap_cb_hdr { |
| 22 | struct ieee80211_radiotap_header hdr; |
| 23 | u8 rate; |
| 24 | u8 dump; |
| 25 | u16 tx_flags; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 26 | } __attribute__((packed)); |
| 27 | |
| 28 | extern linux_wlan_t *g_linux_wlan; |
| 29 | |
| 30 | static struct net_device *wilc_wfi_mon; /* global monitor netdev */ |
| 31 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 32 | extern int mac_xmit(struct sk_buff *skb, struct net_device *dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 33 | |
| 34 | |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 35 | u8 srcAdd[6]; |
| 36 | u8 bssid[6]; |
| 37 | u8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 38 | /** |
| 39 | * @brief WILC_WFI_monitor_rx |
| 40 | * @details |
| 41 | * @param[in] |
| 42 | * @return int : Return 0 on Success |
| 43 | * @author mdaftedar |
| 44 | * @date 12 JUL 2012 |
| 45 | * @version 1.0 |
| 46 | */ |
| 47 | |
| 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) |
| 54 | |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 55 | void WILC_WFI_monitor_rx(u8 *buff, u32 size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 56 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 57 | u32 header, pkt_offset; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 58 | struct sk_buff *skb = NULL; |
| 59 | struct wilc_wfi_radiotap_hdr *hdr; |
| 60 | struct wilc_wfi_radiotap_cb_hdr *cb_hdr; |
| 61 | |
| 62 | PRINT_INFO(HOSTAPD_DBG, "In monitor interface receive function\n"); |
| 63 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 64 | /* Bug 4601 */ |
| 65 | if (wilc_wfi_mon == NULL) |
| 66 | return; |
| 67 | |
| 68 | if (!netif_running(wilc_wfi_mon)) { |
| 69 | PRINT_INFO(HOSTAPD_DBG, "Monitor interface already RUNNING\n"); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | /* Get WILC header */ |
| 74 | memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); |
| 75 | |
| 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); |
| 79 | |
| 80 | if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { |
| 81 | |
| 82 | /* hostapd callback mgmt frame */ |
| 83 | |
| 84 | skb = dev_alloc_skb(size + sizeof(struct wilc_wfi_radiotap_cb_hdr)); |
| 85 | if (skb == NULL) { |
| 86 | PRINT_INFO(HOSTAPD_DBG, "Monitor if : No memory to allocate skb"); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | memcpy(skb_put(skb, size), buff, size); |
| 91 | |
| 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)); |
| 94 | |
| 95 | cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */ |
| 96 | |
| 97 | cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr)); |
| 98 | |
| 99 | cb_hdr->hdr.it_present = cpu_to_le32( |
| 100 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 101 | (1 << IEEE80211_RADIOTAP_TX_FLAGS)); |
| 102 | |
| 103 | cb_hdr->rate = 5; /* txrate->bitrate / 5; */ |
| 104 | |
| 105 | if (pkt_offset & IS_MGMT_STATUS_SUCCES) { |
| 106 | /* success */ |
| 107 | cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_RTS; |
| 108 | } else { |
| 109 | cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_FAIL; |
| 110 | } |
| 111 | |
| 112 | } else { |
| 113 | |
| 114 | skb = dev_alloc_skb(size + sizeof(struct wilc_wfi_radiotap_hdr)); |
| 115 | |
| 116 | if (skb == NULL) { |
| 117 | PRINT_INFO(HOSTAPD_DBG, "Monitor if : No memory to allocate skb"); |
| 118 | return; |
| 119 | } |
| 120 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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; */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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); /* | */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 129 | PRINT_INFO(HOSTAPD_DBG, "Presentflags %d\n", hdr->hdr.it_present); |
| 130 | hdr->rate = 5; /* txrate->bitrate / 5; */ |
| 131 | |
| 132 | } |
| 133 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 134 | |
| 135 | |
| 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)); |
| 142 | |
| 143 | netif_rx(skb); |
| 144 | |
| 145 | |
| 146 | } |
| 147 | |
| 148 | struct tx_complete_mon_data { |
| 149 | int size; |
| 150 | void *buff; |
| 151 | }; |
| 152 | |
| 153 | static void mgmt_tx_complete(void *priv, int status) |
| 154 | { |
| 155 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 156 | struct tx_complete_mon_data *pv_data = (struct tx_complete_mon_data *)priv; |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 157 | u8 *buf = pv_data->buff; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 158 | |
| 159 | |
| 160 | |
| 161 | if (status == 1) { |
| 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); |
| 164 | } else { |
| 165 | PRINT_INFO(HOSTAPD_DBG, "Couldn't send packet - Size = %d - Address = %p.\n", pv_data->size, pv_data->buff); |
| 166 | } |
| 167 | |
| 168 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 169 | |
| 170 | /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 171 | kfree(pv_data->buff); |
| 172 | |
| 173 | kfree(pv_data); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 174 | } |
| 175 | static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len) |
| 176 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 177 | struct tx_complete_mon_data *mgmt_tx = NULL; |
| 178 | |
| 179 | if (dev == NULL) { |
| 180 | PRINT_D(HOSTAPD_DBG, "ERROR: dev == NULL\n"); |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 181 | return -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 182 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 183 | |
| 184 | netif_stop_queue(dev); |
Abdul Hussain | 25fe227 | 2015-06-17 04:48:23 +0000 | [diff] [blame] | 185 | mgmt_tx = kmalloc(sizeof(struct tx_complete_mon_data), GFP_ATOMIC); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 186 | if (mgmt_tx == NULL) { |
| 187 | PRINT_ER("Failed to allocate memory for mgmt_tx structure\n"); |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 188 | return -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 189 | } |
| 190 | |
ChengYi He | 30ef5c8 | 2015-06-16 03:04:59 +0800 | [diff] [blame] | 191 | mgmt_tx->buff = kmalloc(len, GFP_ATOMIC); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 192 | if (mgmt_tx->buff == NULL) { |
| 193 | PRINT_ER("Failed to allocate memory for mgmt_tx buff\n"); |
Tony Cho | f638dd3 | 2015-09-07 19:09:31 +0900 | [diff] [blame] | 194 | kfree(mgmt_tx); |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 195 | return -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 196 | |
| 197 | } |
| 198 | |
| 199 | mgmt_tx->size = len; |
| 200 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 201 | memcpy(mgmt_tx->buff, buf, len); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 202 | g_linux_wlan->oup.wlan_add_mgmt_to_tx_que(mgmt_tx, mgmt_tx->buff, mgmt_tx->size, mgmt_tx_complete); |
| 203 | |
| 204 | netif_wake_queue(dev); |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @brief WILC_WFI_mon_xmit |
| 210 | * @details |
| 211 | * @param[in] |
| 212 | * @return int : Return 0 on Success |
| 213 | * @author mdaftedar |
| 214 | * @date 12 JUL 2012 |
| 215 | * @version 1.0 |
| 216 | */ |
| 217 | static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb, |
| 218 | struct net_device *dev) |
| 219 | { |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 220 | u32 rtap_len, i, ret = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 221 | struct WILC_WFI_mon_priv *mon_priv; |
| 222 | |
| 223 | struct sk_buff *skb2; |
| 224 | struct wilc_wfi_radiotap_cb_hdr *cb_hdr; |
| 225 | |
| 226 | /* Bug 4601 */ |
| 227 | if (wilc_wfi_mon == NULL) |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 228 | return -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 229 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 230 | mon_priv = netdev_priv(wilc_wfi_mon); |
| 231 | |
| 232 | if (mon_priv == NULL) { |
| 233 | PRINT_ER("Monitor interface private structure is NULL\n"); |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 234 | return -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 235 | } |
| 236 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 237 | |
| 238 | rtap_len = ieee80211_get_radiotap_len(skb->data); |
| 239 | if (skb->len < rtap_len) { |
| 240 | PRINT_ER("Error in radiotap header\n"); |
| 241 | return -1; |
| 242 | } |
| 243 | /* skip the radiotap header */ |
| 244 | PRINT_INFO(HOSTAPD_DBG, "Radiotap len: %d\n", rtap_len); |
| 245 | |
| 246 | if (INFO) { |
| 247 | for (i = 0; i < rtap_len; i++) |
| 248 | PRINT_INFO(HOSTAPD_DBG, "Radiotap_hdr[%d] %02x\n", i, skb->data[i]); |
| 249 | } |
| 250 | /* Skip the ratio tap header */ |
| 251 | skb_pull(skb, rtap_len); |
| 252 | |
| 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]); |
| 255 | |
| 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)); |
| 258 | |
| 259 | memcpy(skb_put(skb2, skb->len), skb->data, skb->len); |
| 260 | |
| 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)); |
| 263 | |
| 264 | cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */ |
| 265 | |
| 266 | cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr)); |
| 267 | |
| 268 | cb_hdr->hdr.it_present = cpu_to_le32( |
| 269 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 270 | (1 << IEEE80211_RADIOTAP_TX_FLAGS)); |
| 271 | |
| 272 | cb_hdr->rate = 5; /* txrate->bitrate / 5; */ |
| 273 | cb_hdr->tx_flags = 0x0004; |
| 274 | |
| 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)); |
| 281 | |
| 282 | netif_rx(skb2); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | skb->dev = mon_priv->real_ndev; |
| 287 | |
| 288 | PRINT_INFO(HOSTAPD_DBG, "Skipping the radiotap header\n"); |
| 289 | |
| 290 | |
| 291 | |
| 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); |
| 295 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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); |
| 303 | dev_kfree_skb(skb); |
| 304 | } else |
| 305 | ret = mac_xmit(skb, mon_priv->real_ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 306 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | static const struct net_device_ops wilc_wfi_netdev_ops = { |
| 311 | .ndo_start_xmit = WILC_WFI_mon_xmit, |
| 312 | |
| 313 | }; |
| 314 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 315 | /** |
| 316 | * @brief WILC_WFI_mon_setup |
| 317 | * @details |
| 318 | * @param[in] |
| 319 | * @return int : Return 0 on Success |
| 320 | * @author mdaftedar |
| 321 | * @date 12 JUL 2012 |
| 322 | * @version 1.0 |
| 323 | */ |
| 324 | static void WILC_WFI_mon_setup(struct net_device *dev) |
| 325 | { |
| 326 | |
| 327 | dev->netdev_ops = &wilc_wfi_netdev_ops; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 328 | PRINT_INFO(CORECONFIG_DBG, "In Ethernet setup function\n"); |
| 329 | ether_setup(dev); |
Phil Sutter | 7d9e437 | 2015-08-18 10:30:47 +0200 | [diff] [blame] | 330 | dev->priv_flags |= IFF_NO_QUEUE; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 331 | dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Vaishali Thakkar | 8ca1b55 | 2015-06-21 10:56:21 +0530 | [diff] [blame] | 332 | eth_zero_addr(dev->dev_addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 333 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 334 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 335 | unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x8f}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 336 | memcpy(dev->dev_addr, mac_add, ETH_ALEN); |
| 337 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 338 | |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * @brief WILC_WFI_init_mon_interface |
| 343 | * @details |
| 344 | * @param[in] |
| 345 | * @return int : Return 0 on Success |
| 346 | * @author mdaftedar |
| 347 | * @date 12 JUL 2012 |
| 348 | * @version 1.0 |
| 349 | */ |
Arnd Bergmann | 057d1e9 | 2015-06-01 21:06:44 +0200 | [diff] [blame] | 350 | struct net_device *WILC_WFI_init_mon_interface(const char *name, struct net_device *real_dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 351 | { |
| 352 | |
| 353 | |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 354 | u32 ret = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 355 | struct WILC_WFI_mon_priv *priv; |
| 356 | |
| 357 | /*If monitor interface is already initialized, return it*/ |
| 358 | if (wilc_wfi_mon) { |
| 359 | return wilc_wfi_mon; |
| 360 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 361 | |
| 362 | wilc_wfi_mon = alloc_etherdev(sizeof(struct WILC_WFI_mon_priv)); |
| 363 | if (!wilc_wfi_mon) { |
| 364 | PRINT_ER("failed to allocate memory\n"); |
| 365 | return NULL; |
| 366 | |
| 367 | } |
| 368 | |
| 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; |
| 373 | |
| 374 | ret = register_netdevice(wilc_wfi_mon); |
| 375 | if (ret) { |
| 376 | PRINT_ER(" register_netdevice failed (%d)\n", ret); |
| 377 | return NULL; |
| 378 | } |
| 379 | priv = netdev_priv(wilc_wfi_mon); |
| 380 | if (priv == NULL) { |
| 381 | PRINT_ER("private structure is NULL\n"); |
| 382 | return NULL; |
| 383 | } |
| 384 | |
| 385 | priv->real_ndev = real_dev; |
| 386 | |
| 387 | return wilc_wfi_mon; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * @brief WILC_WFI_deinit_mon_interface |
| 392 | * @details |
| 393 | * @param[in] |
| 394 | * @return int : Return 0 on Success |
| 395 | * @author mdaftedar |
| 396 | * @date 12 JUL 2012 |
| 397 | * @version 1.0 |
| 398 | */ |
Chandra S Gorentla | a96c47e | 2015-08-05 22:11:55 +0530 | [diff] [blame] | 399 | int WILC_WFI_deinit_mon_interface(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 400 | { |
| 401 | bool rollback_lock = false; |
| 402 | |
| 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()) { |
| 407 | rtnl_unlock(); |
| 408 | rollback_lock = true; |
| 409 | } |
| 410 | PRINT_D(HOSTAPD_DBG, "Unregister netdev\n"); |
| 411 | unregister_netdev(wilc_wfi_mon); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 412 | |
| 413 | if (rollback_lock) { |
| 414 | rtnl_lock(); |
| 415 | rollback_lock = false; |
| 416 | } |
| 417 | wilc_wfi_mon = NULL; |
| 418 | } |
Leo Kim | e6e1266 | 2015-09-16 18:36:03 +0900 | [diff] [blame^] | 419 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 420 | |
| 421 | } |
| 422 | #endif /* WILC_AP_EXTERNAL_MLME */ |