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, 0, 0, 0, 0, 0}, 00077 0, 00078 0, 00079 0, 00080 ETHERMTU, 00081 0, 00082 0, 00083 0, 00084 NutEtherInput, 00085 WlanOutput, 00086 NutEtherOutput 00087 }; 00088 00089 /*==========================================================*/ 00090 /* DEFINE: Definition of all global Data */ 00091 /*==========================================================*/ 00092 00093 /* 00094 * Device information structure. 00095 * 00096 * A pointer to this structure must be passed to NutRegisterDevice() 00097 * to bind this Ethernet device driver to the Nut/OS kernel. 00098 * An application may then call NutNetIfConfig() with the name \em eth0 00099 * of this driver to initialize the network interface. 00100 * 00101 */ 00102 NUTDEVICE devWlan = { 00103 0, /* Pointer to next device. */ 00104 {'w', 'l', 'a', 'n', '0', 0, 0, 0, 0}, /* Unique device name. */ 00105 IFTYP_NET, /* Type of device. */ 00106 0, /* Base address. */ 00107 0, /* First interrupt number. */ 00108 &ifn_eth0, /* Interface control block. */ 00109 0, /* Driver control block. */ 00110 WlanInit, /* Driver initialization routine. */ 00111 WlanIOCtl, /* Driver specific control function. */ 00112 0, /* Read from device. */ 00113 0, /* Write to device. */ 00114 0, /* Write from program space data to device. */ 00115 0, /* Open a device or file. */ 00116 0, /* Close a device or file. */ 00117 0 /* Request file size. */ 00118 }; 00119 00120 /*==========================================================*/ 00121 /* DEFINE: Definition of all local Procedures */ 00122 /*==========================================================*/ 00123 00124 /*==========================================================*/ 00125 /* DEFINE: All code exported */ 00126 /*==========================================================*/ 00127 /************************************************************/ 00128 /* WlanInit */ 00129 /* */ 00130 /* Initialize Ethernet hardware. */ 00131 /* */ 00132 /* Resets the WLAN Ethernet controller, */ 00133 /* initializes all required hardware registers and starts */ 00134 /* a background thread for incoming Ethernet traffic. */ 00135 /* */ 00136 /* Applications should do not directly call this function. */ 00137 /* It is automatically executed during device registration */ 00138 /* by NutRegisterDevice(). */ 00139 /* */ 00140 /* In : dev Identifies the device to initialize */ 00141 /* Out : none */ 00142 /* Return: 0 on success, -1 in case of any errors */ 00143 /************************************************************/ 00144 int WlanInit(NUTDEVICE * dev) 00145 { 00146 int nError = ERROR; 00147 00148 /* 00149 * Check if this is the first call. 00150 * Only one init allowed. 00151 */ 00152 if (dev->dev_dcb == NULL) { 00153 dev->dev_dcb = NutHeapAlloc(sizeof(WI_SOFTC)); 00154 /* 00155 * Have we got the memory ? 00156 */ 00157 if (dev->dev_dcb != NULL) { 00158 /* 00159 * Clear NICINFO structure. 00160 */ 00161 memset(dev->dev_dcb, 0, sizeof(WI_SOFTC)); 00162 00163 /* 00164 * Check if a card is available 00165 */ 00166 nError = wlandrv_ProbeDevice(); 00167 if (nError == OK) { 00168 /* 00169 * Check if we can attach the card 00170 */ 00171 if (wlandrv_Attach(dev) != OK) { 00172 nError = ERROR; 00173 } else { 00174 /* 00175 * Now we have all the information, 00176 * and can start the device. 00177 */ 00178 wlandrv_Init(dev); 00179 } /* endif wi_attach(dev->dev_dcb) != OK */ 00180 } /* HardwareReset() */ 00181 } /* endif dev->dev_dcb != NULL */ 00182 } /* check first call, dev->dev_dcb == NULL */ 00183 return (nError); 00184 } 00185 00186 /************************************************************/ 00187 /* WlanIOCtl */ 00188 /* */ 00189 /* Perform WLAN control functions. */ 00190 /* */ 00191 /* reg May be set to one of the following constants: */ 00192 /* */ 00193 /* In : dev Identifies the device to use. */ 00194 /* reg Requested control function. */ 00195 /* conf Points to a buffer that contains any data */ 00196 /* required for the given control function or */ 00197 /* receives data from that function. */ 00198 /* Out : none */ 00199 /* Return: 0 on success, -1 in case of any errors */ 00200 /************************************************************/ 00201 int WlanIOCtl(NUTDEVICE * dev, int req, void *conf) 00202 { 00203 int nError; 00204 00205 nError = wlandrv_IOCTL(dev, req, conf); 00206 00207 return (nError); 00208 } 00209 00210 /************************************************************/ 00211 /* WlanOutput */ 00212 /* */ 00213 /* Send Ethernet packet. */ 00214 /* */ 00215 /* In : dev Identifies the device to use. */ 00216 /* nb Network buffer structure containing the */ 00217 /* packet to be sent. The structure must have */ 00218 /* been allocated by a previous call */ 00219 /* NutNetBufAlloc(). */ 00220 /* Out : none */ 00221 /* Return: 0 on success, -1 in case of any errors */ 00222 /************************************************************/ 00223 int WlanOutput(NUTDEVICE * dev, NETBUF * nb) 00224 { 00225 int nError = ERROR; 00226 00227 nError = wlandrv_PutPacket(dev, nb); 00228 00229 return (nError); 00230 }