00001 /**************************************************************************** 00002 * This file is part of the WLAN-Ethernut device driver. 00003 * 00004 * Copyright (c) 2004 by Michael Fischer. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 3. Neither the name of the author nor the names of its contributors may 00016 * be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00022 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00023 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00024 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00025 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00026 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00028 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00029 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 * 00032 **************************************************************************** 00033 * History: 00034 * 00035 * 27.01.04 mifi First Version 00036 ****************************************************************************/ 00037 #define __WLAN_C__ 00038 00039 #include <compiler.h> 00040 #include <stdio.h> 00041 #include <stddef.h> 00042 #include <string.h> 00043 00044 #include <sys/heap.h> 00045 #include <sys/timer.h> 00046 00047 #include <netinet/if_ether.h> 00048 #include <net/ether.h> 00049 #include <net/if_var.h> 00050 00051 #include <dev/wlantypes.h> 00052 #include <dev/wlan.h> 00053 #include <dev/wlandrv.h> 00054 00055 /*==========================================================*/ 00056 /* DEFINE: All Structures and Common Constants */ 00057 /*==========================================================*/ 00058 #define ERROR -1 00059 #define OK 0 00060 00061 /*==========================================================*/ 00062 /* DEFINE: Prototypes */ 00063 /*==========================================================*/ 00064 00065 /*==========================================================*/ 00066 /* DEFINE: Prototypes */ 00067 /*==========================================================*/ 00068 00069 /* 00070 * Network interface information structure. 00071 * 00072 * Used to call. 00073 */ 00074 static IFNET ifn_eth0 = { 00075 IFT_ETHER, 00076 0, 00077 {0, 0, 0, 0, 0, 0}, 00078 0, 00079 0, 00080 0, 00081 ETHERMTU, 00082 0, 00083 0, 00084 0, 00085 NutEtherInput, 00086 WlanOutput, 00087 NutEtherOutput 00088 }; 00089 00090 /*==========================================================*/ 00091 /* DEFINE: Definition of all global Data */ 00092 /*==========================================================*/ 00093 00094 /* 00095 * Device information structure. 00096 * 00097 * A pointer to this structure must be passed to NutRegisterDevice() 00098 * to bind this Ethernet device driver to the Nut/OS kernel. 00099 * An application may then call NutNetIfConfig() with the name \em eth0 00100 * of this driver to initialize the network interface. 00101 * 00102 */ 00103 NUTDEVICE devWlan = { 00104 0, /* Pointer to next device. */ 00105 {'w', 'l', 'a', 'n', '0', 0, 0, 0, 0}, /* Unique device name. */ 00106 IFTYP_NET, /* Type of device. */ 00107 0, /* Base address. */ 00108 0, /* First interrupt number. */ 00109 &ifn_eth0, /* Interface control block. */ 00110 0, /* Driver control block. */ 00111 WlanInit, /* Driver initialization routine. */ 00112 WlanIOCtl, /* Driver specific control function. */ 00113 0, /* Read from device. */ 00114 0, /* Write to device. */ 00115 0, /* Write from program space data to device. */ 00116 0, /* Open a device or file. */ 00117 0, /* Close a device or file. */ 00118 0 /* Request file size. */ 00119 }; 00120 00121 /*==========================================================*/ 00122 /* DEFINE: Definition of all local Procedures */ 00123 /*==========================================================*/ 00124 00125 /*==========================================================*/ 00126 /* DEFINE: All code exported */ 00127 /*==========================================================*/ 00128 /************************************************************/ 00129 /* WlanInit */ 00130 /* */ 00131 /* Initialize Ethernet hardware. */ 00132 /* */ 00133 /* Resets the WLAN Ethernet controller, */ 00134 /* initializes all required hardware registers and starts */ 00135 /* a background thread for incoming Ethernet traffic. */ 00136 /* */ 00137 /* Applications should do not directly call this function. */ 00138 /* It is automatically executed during device registration */ 00139 /* by NutRegisterDevice(). */ 00140 /* */ 00141 /* In : dev Identifies the device to initialize */ 00142 /* Out : none */ 00143 /* Return: 0 on success, -1 in case of any errors */ 00144 /************************************************************/ 00145 int WlanInit(NUTDEVICE * dev) 00146 { 00147 int nError = ERROR; 00148 00149 /* 00150 * Check if this is the first call. 00151 * Only one init allowed. 00152 */ 00153 if (dev->dev_dcb == NULL) { 00154 dev->dev_dcb = NutHeapAlloc(sizeof(WI_SOFTC)); 00155 /* 00156 * Have we got the memory ? 00157 */ 00158 if (dev->dev_dcb != NULL) { 00159 /* 00160 * Clear NICINFO structure. 00161 */ 00162 memset(dev->dev_dcb, 0, sizeof(WI_SOFTC)); 00163 00164 /* 00165 * Check if a card is available 00166 */ 00167 nError = wlandrv_ProbeDevice(); 00168 if (nError == OK) { 00169 /* 00170 * Check if we can attach the card 00171 */ 00172 if (wlandrv_Attach(dev) != OK) { 00173 nError = ERROR; 00174 } else { 00175 /* 00176 * Now we have all the information, 00177 * and can start the device. 00178 */ 00179 wlandrv_Init(dev); 00180 } /* endif wi_attach(dev->dev_dcb) != OK */ 00181 } /* HardwareReset() */ 00182 } /* endif dev->dev_dcb != NULL */ 00183 } /* check first call, dev->dev_dcb == NULL */ 00184 return (nError); 00185 } 00186 00187 /************************************************************/ 00188 /* WlanIOCtl */ 00189 /* */ 00190 /* Perform WLAN control functions. */ 00191 /* */ 00192 /* reg May be set to one of the following constants: */ 00193 /* */ 00194 /* In : dev Identifies the device to use. */ 00195 /* reg Requested control function. */ 00196 /* conf Points to a buffer that contains any data */ 00197 /* required for the given control function or */ 00198 /* receives data from that function. */ 00199 /* Out : none */ 00200 /* Return: 0 on success, -1 in case of any errors */ 00201 /************************************************************/ 00202 int WlanIOCtl(NUTDEVICE * dev, int req, void *conf) 00203 { 00204 int nError; 00205 00206 nError = wlandrv_IOCTL(dev, req, conf); 00207 00208 return (nError); 00209 } 00210 00211 /************************************************************/ 00212 /* WlanOutput */ 00213 /* */ 00214 /* Send Ethernet packet. */ 00215 /* */ 00216 /* In : dev Identifies the device to use. */ 00217 /* nb Network buffer structure containing the */ 00218 /* packet to be sent. The structure must have */ 00219 /* been allocated by a previous call */ 00220 /* NutNetBufAlloc(). */ 00221 /* Out : none */ 00222 /* Return: 0 on success, -1 in case of any errors */ 00223 /************************************************************/ 00224 int WlanOutput(NUTDEVICE * dev, NETBUF * nb) 00225 { 00226 int nError = ERROR; 00227 00228 nError = wlandrv_PutPacket(dev, nb); 00229 00230 return (nError); 00231 }