Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright(c) 2004 Intel Corporation. All rights reserved.
0004  *
0005  * Portions of this file are based on the WEP enablement code provided by the
0006  * Host AP project hostap-drivers v0.1.3
0007  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
0008  * <jkmaline@cc.hut.fi>
0009  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
0010  *
0011  * Contact Information:
0012  * James P. Ketrenos <ipw2100-admin@linux.intel.com>
0013  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
0014  */
0015 
0016 #include <linux/compiler.h>
0017 #include <linux/errno.h>
0018 #include <linux/if_arp.h>
0019 #include <linux/in6.h>
0020 #include <linux/in.h>
0021 #include <linux/ip.h>
0022 #include <linux/kernel.h>
0023 #include <linux/module.h>
0024 #include <linux/netdevice.h>
0025 #include <linux/pci.h>
0026 #include <linux/proc_fs.h>
0027 #include <linux/skbuff.h>
0028 #include <linux/slab.h>
0029 #include <linux/tcp.h>
0030 #include <linux/types.h>
0031 #include <linux/wireless.h>
0032 #include <linux/etherdevice.h>
0033 #include <linux/uaccess.h>
0034 #include <net/arp.h>
0035 #include "rtllib.h"
0036 
0037 u32 rt_global_debug_component = COMP_ERR;
0038 EXPORT_SYMBOL(rt_global_debug_component);
0039 
0040 static inline int rtllib_networks_allocate(struct rtllib_device *ieee)
0041 {
0042     if (ieee->networks)
0043         return 0;
0044 
0045     ieee->networks = kcalloc(MAX_NETWORK_COUNT,
0046                  sizeof(struct rtllib_network), GFP_KERNEL);
0047     if (!ieee->networks)
0048         return -ENOMEM;
0049 
0050     return 0;
0051 }
0052 
0053 static inline void rtllib_networks_free(struct rtllib_device *ieee)
0054 {
0055     if (!ieee->networks)
0056         return;
0057     kfree(ieee->networks);
0058     ieee->networks = NULL;
0059 }
0060 
0061 static inline void rtllib_networks_initialize(struct rtllib_device *ieee)
0062 {
0063     int i;
0064 
0065     INIT_LIST_HEAD(&ieee->network_free_list);
0066     INIT_LIST_HEAD(&ieee->network_list);
0067     for (i = 0; i < MAX_NETWORK_COUNT; i++)
0068         list_add_tail(&ieee->networks[i].list,
0069                   &ieee->network_free_list);
0070 }
0071 
0072 struct net_device *alloc_rtllib(int sizeof_priv)
0073 {
0074     struct rtllib_device *ieee = NULL;
0075     struct net_device *dev;
0076     int i, err;
0077 
0078     pr_debug("rtllib: Initializing...\n");
0079 
0080     dev = alloc_etherdev(sizeof(struct rtllib_device) + sizeof_priv);
0081     if (!dev) {
0082         pr_err("Unable to allocate net_device.\n");
0083         return NULL;
0084     }
0085     ieee = (struct rtllib_device *)netdev_priv_rsl(dev);
0086     ieee->dev = dev;
0087 
0088     err = rtllib_networks_allocate(ieee);
0089     if (err) {
0090         pr_err("Unable to allocate beacon storage: %d\n", err);
0091         goto free_netdev;
0092     }
0093     rtllib_networks_initialize(ieee);
0094 
0095     /* Default fragmentation threshold is maximum payload size */
0096     ieee->fts = DEFAULT_FTS;
0097     ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
0098     ieee->open_wep = 1;
0099 
0100     /* Default to enabling full open WEP with host based encrypt/decrypt */
0101     ieee->host_encrypt = 1;
0102     ieee->host_decrypt = 1;
0103     ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
0104 
0105     ieee->rtllib_ap_sec_type = rtllib_ap_sec_type;
0106 
0107     spin_lock_init(&ieee->lock);
0108     spin_lock_init(&ieee->wpax_suitlist_lock);
0109     spin_lock_init(&ieee->reorder_spinlock);
0110     atomic_set(&(ieee->atm_swbw), 0);
0111 
0112     /* SAM FIXME */
0113     lib80211_crypt_info_init(&ieee->crypt_info, "RTLLIB", &ieee->lock);
0114 
0115     ieee->wpa_enabled = 0;
0116     ieee->tkip_countermeasures = 0;
0117     ieee->drop_unencrypted = 0;
0118     ieee->privacy_invoked = 0;
0119     ieee->ieee802_1x = 1;
0120     ieee->raw_tx = 0;
0121     ieee->hwsec_active = 0;
0122 
0123     memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
0124     err = rtllib_softmac_init(ieee);
0125     if (err)
0126         goto free_crypt_info;
0127 
0128     ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
0129     if (!ieee->pHTInfo)
0130         goto free_softmac;
0131 
0132     HTUpdateDefaultSetting(ieee);
0133     HTInitializeHTInfo(ieee);
0134     TSInitialize(ieee);
0135     for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++)
0136         INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
0137 
0138     for (i = 0; i < 17; i++) {
0139         ieee->last_rxseq_num[i] = -1;
0140         ieee->last_rxfrag_num[i] = -1;
0141         ieee->last_packet_time[i] = 0;
0142     }
0143 
0144     return dev;
0145 
0146 free_softmac:
0147     rtllib_softmac_free(ieee);
0148 free_crypt_info:
0149     lib80211_crypt_info_free(&ieee->crypt_info);
0150     rtllib_networks_free(ieee);
0151 free_netdev:
0152     free_netdev(dev);
0153 
0154     return NULL;
0155 }
0156 EXPORT_SYMBOL(alloc_rtllib);
0157 
0158 void free_rtllib(struct net_device *dev)
0159 {
0160     struct rtllib_device *ieee = (struct rtllib_device *)
0161                       netdev_priv_rsl(dev);
0162 
0163     kfree(ieee->pHTInfo);
0164     rtllib_softmac_free(ieee);
0165 
0166     lib80211_crypt_info_free(&ieee->crypt_info);
0167 
0168     rtllib_networks_free(ieee);
0169     free_netdev(dev);
0170 }
0171 EXPORT_SYMBOL(free_rtllib);
0172 
0173 static int __init rtllib_init(void)
0174 {
0175     return 0;
0176 }
0177 
0178 static void __exit rtllib_exit(void)
0179 {
0180 }
0181 
0182 module_init(rtllib_init);
0183 module_exit(rtllib_exit);
0184 
0185 MODULE_LICENSE("GPL");