1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright(c) 2004 Intel Corporation. All rights reserved. 4 * 5 * Portions of this file are based on the WEP enablement code provided by the 6 * Host AP project hostap-drivers v0.1.3 7 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 8 * <jkmaline@cc.hut.fi> 9 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 10 * 11 * Contact Information: 12 * James P. Ketrenos <ipw2100-admin@linux.intel.com> 13 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 14 */ 15 16 #include <linux/compiler.h> 17 #include <linux/errno.h> 18 #include <linux/if_arp.h> 19 #include <linux/in6.h> 20 #include <linux/in.h> 21 #include <linux/ip.h> 22 #include <linux/kernel.h> 23 #include <linux/module.h> 24 #include <linux/netdevice.h> 25 #include <linux/pci.h> 26 #include <linux/proc_fs.h> 27 #include <linux/skbuff.h> 28 #include <linux/slab.h> 29 #include <linux/tcp.h> 30 #include <linux/types.h> 31 #include <linux/wireless.h> 32 #include <linux/etherdevice.h> 33 #include <linux/uaccess.h> 34 #include <net/arp.h> 35 #include "rtllib.h" 36 37 u32 rt_global_debug_component = COMP_ERR; 38 EXPORT_SYMBOL(rt_global_debug_component); 39 40 static inline int rtllib_networks_allocate(struct rtllib_device *ieee) 41 { 42 if (ieee->networks) 43 return 0; 44 45 ieee->networks = kcalloc(MAX_NETWORK_COUNT, 46 sizeof(struct rtllib_network), GFP_KERNEL); 47 if (!ieee->networks) 48 return -ENOMEM; 49 50 return 0; 51 } 52 53 static inline void rtllib_networks_free(struct rtllib_device *ieee) 54 { 55 if (!ieee->networks) 56 return; 57 kfree(ieee->networks); 58 ieee->networks = NULL; 59 } 60 61 static inline void rtllib_networks_initialize(struct rtllib_device *ieee) 62 { 63 int i; 64 65 INIT_LIST_HEAD(&ieee->network_free_list); 66 INIT_LIST_HEAD(&ieee->network_list); 67 for (i = 0; i < MAX_NETWORK_COUNT; i++) 68 list_add_tail(&ieee->networks[i].list, 69 &ieee->network_free_list); 70 } 71 72 struct net_device *alloc_rtllib(int sizeof_priv) 73 { 74 struct rtllib_device *ieee = NULL; 75 struct net_device *dev; 76 int i, err; 77 78 pr_debug("rtllib: Initializing...\n"); 79 80 dev = alloc_etherdev(sizeof(struct rtllib_device) + sizeof_priv); 81 if (!dev) { 82 pr_err("Unable to allocate net_device.\n"); 83 return NULL; 84 } 85 ieee = (struct rtllib_device *)netdev_priv_rsl(dev); 86 ieee->dev = dev; 87 88 err = rtllib_networks_allocate(ieee); 89 if (err) { 90 pr_err("Unable to allocate beacon storage: %d\n", err); 91 goto free_netdev; 92 } 93 rtllib_networks_initialize(ieee); 94 95 /* Default fragmentation threshold is maximum payload size */ 96 ieee->fts = DEFAULT_FTS; 97 ieee->scan_age = DEFAULT_MAX_SCAN_AGE; 98 ieee->open_wep = 1; 99 100 ieee->ieee802_1x = 1; /* Default to supporting 802.1x */ 101 102 ieee->rtllib_ap_sec_type = rtllib_ap_sec_type; 103 104 spin_lock_init(&ieee->lock); 105 spin_lock_init(&ieee->wpax_suitlist_lock); 106 spin_lock_init(&ieee->reorder_spinlock); 107 atomic_set(&ieee->atm_swbw, 0); 108 109 /* SAM FIXME */ 110 lib80211_crypt_info_init(&ieee->crypt_info, "RTLLIB", &ieee->lock); 111 112 ieee->wpa_enabled = 0; 113 ieee->tkip_countermeasures = 0; 114 ieee->drop_unencrypted = 0; 115 ieee->privacy_invoked = 0; 116 ieee->ieee802_1x = 1; 117 ieee->raw_tx = 0; 118 ieee->hwsec_active = 0; 119 120 memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32); 121 err = rtllib_softmac_init(ieee); 122 if (err) 123 goto free_crypt_info; 124 125 ieee->ht_info = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL); 126 if (!ieee->ht_info) 127 goto free_softmac; 128 129 HTUpdateDefaultSetting(ieee); 130 HTInitializeHTInfo(ieee); 131 TSInitialize(ieee); 132 for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++) 133 INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]); 134 135 for (i = 0; i < 17; i++) { 136 ieee->last_rxseq_num[i] = -1; 137 ieee->last_rxfrag_num[i] = -1; 138 ieee->last_packet_time[i] = 0; 139 } 140 141 return dev; 142 143 free_softmac: 144 rtllib_softmac_free(ieee); 145 free_crypt_info: 146 lib80211_crypt_info_free(&ieee->crypt_info); 147 rtllib_networks_free(ieee); 148 free_netdev: 149 free_netdev(dev); 150 151 return NULL; 152 } 153 EXPORT_SYMBOL(alloc_rtllib); 154 155 void free_rtllib(struct net_device *dev) 156 { 157 struct rtllib_device *ieee = (struct rtllib_device *) 158 netdev_priv_rsl(dev); 159 160 kfree(ieee->ht_info); 161 rtllib_softmac_free(ieee); 162 163 lib80211_crypt_info_free(&ieee->crypt_info); 164 165 rtllib_networks_free(ieee); 166 free_netdev(dev); 167 } 168 EXPORT_SYMBOL(free_rtllib); 169 170 static int __init rtllib_init(void) 171 { 172 return 0; 173 } 174 175 static void __exit rtllib_exit(void) 176 { 177 } 178 179 module_init(rtllib_init); 180 module_exit(rtllib_exit); 181 182 MODULE_LICENSE("GPL"); 183