Embed:
(wiki syntax)
Show/hide line numbers
ZG2100NetIf.h
Go to the documentation of this file.
00001 00002 /* 00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 /** \file 00025 ZG2100 Wi-Fi Module network interface header file 00026 */ 00027 00028 #ifndef ZG2100NETIF_H 00029 #define ZG2100NETIF_H 00030 00031 struct netif; 00032 00033 #include "mbed.h" 00034 00035 #include "if/lwip/LwipNetIf.h" 00036 #include "core/net.h" 00037 00038 #include "drv/zg2100/zg_defs.h" 00039 #include "drv/zg2100/zg_err.h" 00040 00041 ///ZG2100 Wi-Fi Module network interface error codes 00042 typedef zg_err ZG2100Err; 00043 00044 ///ZG2100 Wi-Fi Module network interface 00045 /** 00046 This class provides Wi-Fi connectivity to the stack 00047 */ 00048 class ZG2100NetIf : public LwipNetIf 00049 { 00050 public: 00051 ///Instantiates the Interface and register it against the stack, DHCP will be used 00052 ZG2100NetIf( PinName mosi, PinName miso, PinName sclk, PinName cs, PinName intp, PinName nrst ); //W/ DHCP 00053 ///Instantiates the Interface and register it against the stack, DHCP will not be used 00054 /** 00055 IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address. 00056 */ 00057 ZG2100NetIf( PinName mosi, PinName miso, PinName sclk, PinName cs, PinName intp, PinName nrst, 00058 IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns ); //W/o DHCP 00059 virtual ~ZG2100NetIf(); 00060 00061 ///Initializes module 00062 void init(); 00063 00064 ///Sets network's SSID 00065 void setSsid(const char* ssid); 00066 00067 ///Sets network's WEP key 00068 void setWepKey(const byte* key, int len); 00069 00070 ///Sets network's WPA passphrase (can last up to 30s) 00071 void setWpaPass(const char* pass); 00072 00073 ///Sets network's PSK key (preferred when using WPA to avoid computing it each time) 00074 void setPskKey(const byte* key, int len); 00075 00076 ///Connects to network 00077 ZG2100Err connect(ZG_BSS_TYPE type, ZG_SECURITY security); 00078 00079 ///Disconnects from network 00080 void disconnect(); 00081 00082 ///Brings the interface up (must be connected to a network first) 00083 /** 00084 Uses DHCP if necessary 00085 @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s 00086 @return : ZG_OK on success or ZG_TIMEOUT on timeout 00087 */ 00088 ZG2100Err setup(int timeout_ms = 15000); 00089 00090 virtual void poll(); 00091 00092 private: 00093 void waitReady(); 00094 00095 SPI m_spi; 00096 DigitalOut m_cs; 00097 /*InterruptIn*/ DigitalIn m_intp; 00098 DigitalOut m_nrst; 00099 00100 Timer m_ethArpTimer; 00101 Timer m_dhcpCoarseTimer; 00102 Timer m_dhcpFineTimer; 00103 Timer m_igmpTimer; 00104 00105 bool m_useDhcp; 00106 00107 netif* m_pNetIf; 00108 00109 IpAddr m_netmask; 00110 IpAddr m_gateway; 00111 00112 const char* m_hostname; 00113 00114 }; 00115 00116 #endif 00117
Generated on Tue Jul 12 2022 13:17:37 by 1.7.2