User | Revision | Line number | New contents of line |
donatien |
3:e02ec42cf9c8
|
1
|
|
donatien |
3:e02ec42cf9c8
|
2
|
/*
|
donatien |
3:e02ec42cf9c8
|
3
|
Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
|
donatien |
3:e02ec42cf9c8
|
4
|
|
donatien |
3:e02ec42cf9c8
|
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
donatien |
3:e02ec42cf9c8
|
6
|
of this software and associated documentation files (the "Software"), to deal
|
donatien |
3:e02ec42cf9c8
|
7
|
in the Software without restriction, including without limitation the rights
|
donatien |
3:e02ec42cf9c8
|
8
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
donatien |
3:e02ec42cf9c8
|
9
|
copies of the Software, and to permit persons to whom the Software is
|
donatien |
3:e02ec42cf9c8
|
10
|
furnished to do so, subject to the following conditions:
|
donatien |
3:e02ec42cf9c8
|
11
|
|
donatien |
3:e02ec42cf9c8
|
12
|
The above copyright notice and this permission notice shall be included in
|
donatien |
3:e02ec42cf9c8
|
13
|
all copies or substantial portions of the Software.
|
donatien |
3:e02ec42cf9c8
|
14
|
|
donatien |
3:e02ec42cf9c8
|
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
donatien |
3:e02ec42cf9c8
|
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
donatien |
3:e02ec42cf9c8
|
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
donatien |
3:e02ec42cf9c8
|
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
donatien |
3:e02ec42cf9c8
|
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
donatien |
3:e02ec42cf9c8
|
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
donatien |
3:e02ec42cf9c8
|
21
|
THE SOFTWARE.
|
donatien |
3:e02ec42cf9c8
|
22
|
*/
|
donatien |
3:e02ec42cf9c8
|
23
|
|
donatien |
3:e02ec42cf9c8
|
24
|
/** \file
|
donatien |
3:e02ec42cf9c8
|
25
|
ZG2100 Wi-Fi Module network interface header file
|
donatien |
3:e02ec42cf9c8
|
26
|
*/
|
donatien |
3:e02ec42cf9c8
|
27
|
|
donatien |
3:e02ec42cf9c8
|
28
|
#ifndef ZG2100NETIF_H
|
donatien |
3:e02ec42cf9c8
|
29
|
#define ZG2100NETIF_H
|
donatien |
3:e02ec42cf9c8
|
30
|
|
donatien |
3:e02ec42cf9c8
|
31
|
struct netif;
|
donatien |
3:e02ec42cf9c8
|
32
|
|
donatien |
3:e02ec42cf9c8
|
33
|
#include "mbed.h"
|
donatien |
3:e02ec42cf9c8
|
34
|
|
donatien |
3:e02ec42cf9c8
|
35
|
#include "if/lwip/LwipNetIf.h"
|
donatien |
3:e02ec42cf9c8
|
36
|
#include "core/net.h"
|
donatien |
3:e02ec42cf9c8
|
37
|
|
donatien |
3:e02ec42cf9c8
|
38
|
#include "drv/zg2100/zg_defs.h"
|
donatien |
3:e02ec42cf9c8
|
39
|
#include "drv/zg2100/zg_err.h"
|
donatien |
3:e02ec42cf9c8
|
40
|
|
donatien |
3:e02ec42cf9c8
|
41
|
///ZG2100 Wi-Fi Module network interface error codes
|
donatien |
3:e02ec42cf9c8
|
42
|
typedef zg_err ZG2100Err;
|
donatien |
3:e02ec42cf9c8
|
43
|
|
donatien |
3:e02ec42cf9c8
|
44
|
///ZG2100 Wi-Fi Module network interface
|
donatien |
3:e02ec42cf9c8
|
45
|
/**
|
donatien |
3:e02ec42cf9c8
|
46
|
This class provides Wi-Fi connectivity to the stack
|
donatien |
3:e02ec42cf9c8
|
47
|
*/
|
donatien |
3:e02ec42cf9c8
|
48
|
class ZG2100NetIf : public LwipNetIf
|
donatien |
3:e02ec42cf9c8
|
49
|
{
|
donatien |
3:e02ec42cf9c8
|
50
|
public:
|
donatien |
3:e02ec42cf9c8
|
51
|
///Instantiates the Interface and register it against the stack, DHCP will be used
|
donatien |
3:e02ec42cf9c8
|
52
|
ZG2100NetIf( PinName mosi, PinName miso, PinName sclk, PinName cs, PinName intp, PinName nrst ); //W/ DHCP
|
donatien |
3:e02ec42cf9c8
|
53
|
///Instantiates the Interface and register it against the stack, DHCP will not be used
|
donatien |
3:e02ec42cf9c8
|
54
|
/**
|
donatien |
3:e02ec42cf9c8
|
55
|
IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address.
|
donatien |
3:e02ec42cf9c8
|
56
|
*/
|
donatien |
3:e02ec42cf9c8
|
57
|
ZG2100NetIf( PinName mosi, PinName miso, PinName sclk, PinName cs, PinName intp, PinName nrst,
|
donatien |
3:e02ec42cf9c8
|
58
|
IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns ); //W/o DHCP
|
donatien |
3:e02ec42cf9c8
|
59
|
virtual ~ZG2100NetIf();
|
donatien |
3:e02ec42cf9c8
|
60
|
|
donatien |
3:e02ec42cf9c8
|
61
|
///Initializes module
|
donatien |
3:e02ec42cf9c8
|
62
|
void init();
|
donatien |
3:e02ec42cf9c8
|
63
|
|
donatien |
3:e02ec42cf9c8
|
64
|
///Sets network's SSID
|
donatien |
3:e02ec42cf9c8
|
65
|
void setSsid(const char* ssid);
|
donatien |
3:e02ec42cf9c8
|
66
|
|
donatien |
3:e02ec42cf9c8
|
67
|
///Sets network's WEP key
|
donatien |
3:e02ec42cf9c8
|
68
|
void setWepKey(const byte* key, int len);
|
donatien |
3:e02ec42cf9c8
|
69
|
|
donatien |
3:e02ec42cf9c8
|
70
|
///Sets network's WPA passphrase (can last up to 30s)
|
donatien |
3:e02ec42cf9c8
|
71
|
void setWpaPass(const char* pass);
|
donatien |
3:e02ec42cf9c8
|
72
|
|
donatien |
3:e02ec42cf9c8
|
73
|
///Sets network's PSK key (preferred when using WPA to avoid computing it each time)
|
donatien |
3:e02ec42cf9c8
|
74
|
void setPskKey(const byte* key, int len);
|
donatien |
3:e02ec42cf9c8
|
75
|
|
donatien |
3:e02ec42cf9c8
|
76
|
///Connects to network
|
donatien |
3:e02ec42cf9c8
|
77
|
ZG2100Err connect(ZG_BSS_TYPE type, ZG_SECURITY security);
|
donatien |
3:e02ec42cf9c8
|
78
|
|
donatien |
3:e02ec42cf9c8
|
79
|
///Disconnects from network
|
donatien |
3:e02ec42cf9c8
|
80
|
void disconnect();
|
donatien |
3:e02ec42cf9c8
|
81
|
|
donatien |
3:e02ec42cf9c8
|
82
|
///Brings the interface up (must be connected to a network first)
|
donatien |
3:e02ec42cf9c8
|
83
|
/**
|
donatien |
3:e02ec42cf9c8
|
84
|
Uses DHCP if necessary
|
donatien |
3:e02ec42cf9c8
|
85
|
@param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s
|
donatien |
3:e02ec42cf9c8
|
86
|
@return : ZG_OK on success or ZG_TIMEOUT on timeout
|
donatien |
3:e02ec42cf9c8
|
87
|
*/
|
donatien |
3:e02ec42cf9c8
|
88
|
ZG2100Err setup(int timeout_ms = 15000);
|
donatien |
3:e02ec42cf9c8
|
89
|
|
donatien |
3:e02ec42cf9c8
|
90
|
virtual void poll();
|
donatien |
3:e02ec42cf9c8
|
91
|
|
donatien |
3:e02ec42cf9c8
|
92
|
private:
|
donatien |
3:e02ec42cf9c8
|
93
|
void waitReady();
|
donatien |
3:e02ec42cf9c8
|
94
|
|
donatien |
3:e02ec42cf9c8
|
95
|
SPI m_spi;
|
donatien |
3:e02ec42cf9c8
|
96
|
DigitalOut m_cs;
|
donatien |
3:e02ec42cf9c8
|
97
|
/*InterruptIn*/ DigitalIn m_intp;
|
donatien |
3:e02ec42cf9c8
|
98
|
DigitalOut m_nrst;
|
donatien |
3:e02ec42cf9c8
|
99
|
|
donatien |
3:e02ec42cf9c8
|
100
|
Timer m_ethArpTimer;
|
donatien |
3:e02ec42cf9c8
|
101
|
Timer m_dhcpCoarseTimer;
|
donatien |
3:e02ec42cf9c8
|
102
|
Timer m_dhcpFineTimer;
|
donatien |
3:e02ec42cf9c8
|
103
|
Timer m_igmpTimer;
|
donatien |
3:e02ec42cf9c8
|
104
|
|
donatien |
3:e02ec42cf9c8
|
105
|
bool m_useDhcp;
|
donatien |
3:e02ec42cf9c8
|
106
|
|
donatien |
3:e02ec42cf9c8
|
107
|
netif* m_pNetIf;
|
donatien |
3:e02ec42cf9c8
|
108
|
|
donatien |
3:e02ec42cf9c8
|
109
|
IpAddr m_netmask;
|
donatien |
3:e02ec42cf9c8
|
110
|
IpAddr m_gateway;
|
donatien |
3:e02ec42cf9c8
|
111
|
|
donatien |
3:e02ec42cf9c8
|
112
|
const char* m_hostname;
|
donatien |
3:e02ec42cf9c8
|
113
|
|
donatien |
3:e02ec42cf9c8
|
114
|
};
|
donatien |
3:e02ec42cf9c8
|
115
|
|
donatien |
3:e02ec42cf9c8
|
116
|
#endif
|
donatien |
3:e02ec42cf9c8
|
117
|
|