User | Revision | Line number | New contents of line |
mbed714 |
0:d616ece2d859
|
1
|
|
mbed714 |
0:d616ece2d859
|
2
|
/*
|
mbed714 |
0:d616ece2d859
|
3
|
Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
|
mbed714 |
0:d616ece2d859
|
4
|
|
mbed714 |
0:d616ece2d859
|
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
mbed714 |
0:d616ece2d859
|
6
|
of this software and associated documentation files (the "Software"), to deal
|
mbed714 |
0:d616ece2d859
|
7
|
in the Software without restriction, including without limitation the rights
|
mbed714 |
0:d616ece2d859
|
8
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
mbed714 |
0:d616ece2d859
|
9
|
copies of the Software, and to permit persons to whom the Software is
|
mbed714 |
0:d616ece2d859
|
10
|
furnished to do so, subject to the following conditions:
|
mbed714 |
0:d616ece2d859
|
11
|
|
mbed714 |
0:d616ece2d859
|
12
|
The above copyright notice and this permission notice shall be included in
|
mbed714 |
0:d616ece2d859
|
13
|
all copies or substantial portions of the Software.
|
mbed714 |
0:d616ece2d859
|
14
|
|
mbed714 |
0:d616ece2d859
|
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
mbed714 |
0:d616ece2d859
|
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
mbed714 |
0:d616ece2d859
|
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
mbed714 |
0:d616ece2d859
|
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
mbed714 |
0:d616ece2d859
|
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
mbed714 |
0:d616ece2d859
|
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
mbed714 |
0:d616ece2d859
|
21
|
THE SOFTWARE.
|
mbed714 |
0:d616ece2d859
|
22
|
*/
|
mbed714 |
0:d616ece2d859
|
23
|
|
mbed714 |
0:d616ece2d859
|
24
|
/** \file
|
mbed714 |
0:d616ece2d859
|
25
|
PPP Generic network interface header file
|
mbed714 |
0:d616ece2d859
|
26
|
*/
|
mbed714 |
0:d616ece2d859
|
27
|
|
mbed714 |
0:d616ece2d859
|
28
|
//This is a backend for PPP, using lwIP
|
mbed714 |
0:d616ece2d859
|
29
|
|
mbed714 |
0:d616ece2d859
|
30
|
#ifndef PPPNETIF_H
|
mbed714 |
0:d616ece2d859
|
31
|
#define PPPNETIF_H
|
mbed714 |
0:d616ece2d859
|
32
|
|
mbed714 |
0:d616ece2d859
|
33
|
#include "mbed.h"
|
mbed714 |
0:d616ece2d859
|
34
|
|
mbed714 |
0:d616ece2d859
|
35
|
//For now, only a GPRS Modem is supported,
|
mbed714 |
0:d616ece2d859
|
36
|
//but we could easily split this class into a base class + two derived classes
|
mbed714 |
0:d616ece2d859
|
37
|
// (PPP over GPRS + PPP over Serial Modem)
|
mbed714 |
0:d616ece2d859
|
38
|
#include "drv/gprs/GPRSModem.h"
|
mbed714 |
0:d616ece2d859
|
39
|
#include "if/lwip/LwipNetIf.h"
|
mbed714 |
0:d616ece2d859
|
40
|
|
mbed714 |
0:d616ece2d859
|
41
|
///PPP connection error codes
|
mbed714 |
0:d616ece2d859
|
42
|
enum PPPErr
|
mbed714 |
0:d616ece2d859
|
43
|
{
|
mbed714 |
0:d616ece2d859
|
44
|
__PPP_MIN = -0xFFFF,
|
mbed714 |
0:d616ece2d859
|
45
|
PPP_MODEM, ///<AT error returned
|
mbed714 |
0:d616ece2d859
|
46
|
PPP_NETWORK, ///<Network is down
|
mbed714 |
0:d616ece2d859
|
47
|
PPP_PROTOCOL, ///<PPP Protocol error
|
mbed714 |
0:d616ece2d859
|
48
|
PPP_CLOSED, ///<Connection is closed
|
mbed714 |
0:d616ece2d859
|
49
|
PPP_OK = 0 ///<Success
|
mbed714 |
0:d616ece2d859
|
50
|
};
|
mbed714 |
0:d616ece2d859
|
51
|
|
mbed714 |
0:d616ece2d859
|
52
|
enum PPPStatus
|
mbed714 |
0:d616ece2d859
|
53
|
{
|
mbed714 |
0:d616ece2d859
|
54
|
PPP_CONNECTING,
|
mbed714 |
0:d616ece2d859
|
55
|
PPP_CONNECTED,
|
mbed714 |
0:d616ece2d859
|
56
|
PPP_DISCONNECTED,
|
mbed714 |
0:d616ece2d859
|
57
|
};
|
mbed714 |
0:d616ece2d859
|
58
|
|
mbed714 |
0:d616ece2d859
|
59
|
class PPPNetIf : public LwipNetIf
|
mbed714 |
0:d616ece2d859
|
60
|
{
|
mbed714 |
0:d616ece2d859
|
61
|
public:
|
mbed714 |
0:d616ece2d859
|
62
|
PPPNetIf(GPRSModem* pIf);
|
mbed714 |
0:d616ece2d859
|
63
|
virtual ~PPPNetIf();
|
mbed714 |
0:d616ece2d859
|
64
|
|
mbed714 |
0:d616ece2d859
|
65
|
#if 0
|
mbed714 |
0:d616ece2d859
|
66
|
PPPErr open(Serial* pSerial);
|
mbed714 |
0:d616ece2d859
|
67
|
#endif
|
mbed714 |
0:d616ece2d859
|
68
|
|
mbed714 |
0:d616ece2d859
|
69
|
PPPErr GPRSConnect(const char* apn, const char* userId, const char* password); //Connect using GPRS
|
mbed714 |
0:d616ece2d859
|
70
|
PPPErr ATConnect(const char* number); //Connect using a "classic" voice modem or GSM
|
mbed714 |
0:d616ece2d859
|
71
|
|
mbed714 |
0:d616ece2d859
|
72
|
virtual void poll();
|
mbed714 |
0:d616ece2d859
|
73
|
|
mbed714 |
0:d616ece2d859
|
74
|
PPPErr disconnect();
|
mbed714 |
0:d616ece2d859
|
75
|
|
mbed714 |
0:d616ece2d859
|
76
|
#if 0
|
mbed714 |
0:d616ece2d859
|
77
|
PPPErr close();
|
mbed714 |
0:d616ece2d859
|
78
|
#endif
|
mbed714 |
0:d616ece2d859
|
79
|
|
mbed714 |
0:d616ece2d859
|
80
|
protected:
|
mbed714 |
0:d616ece2d859
|
81
|
GPRSModem* m_pIf;
|
mbed714 |
0:d616ece2d859
|
82
|
|
mbed714 |
0:d616ece2d859
|
83
|
private:
|
mbed714 |
0:d616ece2d859
|
84
|
void pppCallback(int errCode, void *arg);
|
mbed714 |
0:d616ece2d859
|
85
|
|
mbed714 |
0:d616ece2d859
|
86
|
static void sPppCallback(void *ctx, int errCode, void *arg) //Callback from ppp.c
|
mbed714 |
0:d616ece2d859
|
87
|
{ return ((PPPNetIf*)ctx)->pppCallback(errCode, arg); }
|
mbed714 |
0:d616ece2d859
|
88
|
|
mbed714 |
0:d616ece2d859
|
89
|
bool m_connected;
|
mbed714 |
0:d616ece2d859
|
90
|
/*bool m_open;*/
|
mbed714 |
0:d616ece2d859
|
91
|
volatile PPPStatus m_status;
|
mbed714 |
0:d616ece2d859
|
92
|
volatile int m_fd; //PPP Session descriptor
|
mbed714 |
0:d616ece2d859
|
93
|
|
mbed714 |
0:d616ece2d859
|
94
|
//int m_id;
|
mbed714 |
0:d616ece2d859
|
95
|
|
mbed714 |
0:d616ece2d859
|
96
|
uint8_t* m_buf;
|
mbed714 |
0:d616ece2d859
|
97
|
|
mbed714 |
0:d616ece2d859
|
98
|
};
|
mbed714 |
0:d616ece2d859
|
99
|
|
mbed714 |
0:d616ece2d859
|
100
|
#endif
|