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 /* Default to enabling full open WEP with host based encrypt/decrypt */ 101 ieee->host_encrypt = 1; 102 ieee->host_decrypt = 1; 103 ieee->ieee802_1x = 1; /* Default to supporting 802.1x */ 104 105 ieee->rtllib_ap_sec_type = rtllib_ap_sec_type; 106 107 spin_lock_init(&ieee->lock); 108 spin_lock_init(&ieee->wpax_suitlist_lock); 109 spin_lock_init(&ieee->reorder_spinlock); 110 atomic_set(&(ieee->atm_swbw), 0); 111 112 /* SAM FIXME */ 113 lib80211_crypt_info_init(&ieee->crypt_info, "RTLLIB", &ieee->lock); 114 115 ieee->wpa_enabled = 0; 116 ieee->tkip_countermeasures = 0; 117 ieee->drop_unencrypted = 0; 118 ieee->privacy_invoked = 0; 119 ieee->ieee802_1x = 1; 120 ieee->raw_tx = 0; 121 ieee->hwsec_active = 0; 122 123 memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32); 124 err = rtllib_softmac_init(ieee); 125 if (err) 126 goto free_crypt_info; 127 128 ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL); 129 if (!ieee->pHTInfo) 130 goto free_softmac; 131 132 HTUpdateDefaultSetting(ieee); 133 HTInitializeHTInfo(ieee); 134 TSInitialize(ieee); 135 for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++) 136 INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]); 137 138 for (i = 0; i < 17; i++) { 139 ieee->last_rxseq_num[i] = -1; 140 ieee->last_rxfrag_num[i] = -1; 141 ieee->last_packet_time[i] = 0; 142 } 143 144 return dev; 145 146 free_softmac: 147 rtllib_softmac_free(ieee); 148 free_crypt_info: 149 lib80211_crypt_info_free(&ieee->crypt_info); 150 rtllib_networks_free(ieee); 151 free_netdev: 152 free_netdev(dev); 153 154 return NULL; 155 } 156 EXPORT_SYMBOL(alloc_rtllib); 157 158 void free_rtllib(struct net_device *dev) 159 { 160 struct rtllib_device *ieee = (struct rtllib_device *) 161 netdev_priv_rsl(dev); 162 163 kfree(ieee->pHTInfo); 164 rtllib_softmac_free(ieee); 165 166 lib80211_crypt_info_free(&ieee->crypt_info); 167 168 rtllib_networks_free(ieee); 169 free_netdev(dev); 170 } 171 EXPORT_SYMBOL(free_rtllib); 172 173 static int __init rtllib_init(void) 174 { 175 return 0; 176 } 177 178 static void __exit rtllib_exit(void) 179 { 180 } 181 182 module_init(rtllib_init); 183 module_exit(rtllib_exit); 184 185 MODULE_LICENSE("GPL"); 186