-
Notifications
You must be signed in to change notification settings - Fork 17
/
chap_api_ppp.tex
257 lines (186 loc) · 9.23 KB
/
chap_api_ppp.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
\section{Point-to-Point Protocol (PPP)}
PPP consists in a family of data-link protocols, providing link control,
configuration and authentication over a point-to-point link. In a connected
embedded system, it is often used to access dial-up modems over serial lines.
This module supports GSM modem configuration by implementing part of ETSI TS 127 007.
From the picoTCP perspective, each PPP capable device may be abstracted into its own instance
that can be created using \texttt{pico\_ppp\_create}.
Any GSM/GPRS/3G/HSDPA module, exporting a non-blocking serial interface, such as SPI or UART,
can be connected to the ppp device abstraction, using \texttt{pico\_ppp\_set\_serial\_read},
\texttt{pico\_ppp\_set\_serial\_write}, \texttt{pico\_ppp\_set\_serial\_set\_speed}.
Once the physical interface is attached, the access to the remote access point gateway
can be configured using \texttt{pico\_ppp\_set\_apn}, \texttt{pico\_ppp\_set\_username} and
\texttt{pico\_ppp\_set\_password}.
When the interface is configured, the connection may be established using
\texttt{pico\_ppp\_connect}. Even if the peer disconnects, the connection will be brought up
again automatically afterwords.
To interrupt the connection and stop the automatic reconnection, \texttt{pico\_ppp\_disconnect}
can be called.
\subsection{pico\_ppp\_create}
\subsubsection*{Description}
This function will create a new device association to be used with the ppp driver. The driver
must then afterwards be associated with lower-level serial functions in order to be used.
\subsubsection*{Function prototype}
\texttt{struct pico\_device *pico\_ppp\_create(void);}
\subsubsection*{Return value}
A new pico\_device is allocated and returned if the device is successfully created.
\subsubsection*{Example}
\begin{verbatim}
ppp = pico_ppp_create();
\end{verbatim}
\subsection{pico\_ppp\_set\_serial\_read}
\subsubsection*{Description}
This function will associate the read function from an external source (e.g. a UART device API)
to the read functionality of the PPP driver. Setting up a proper read/write interface is necessary
for the PPP driver to work properly.
The function associated with the read must be non-blocking, no matter the execution model of the system.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_set\_serial\_read(struct pico\_device *dev, int (*sread)(struct pico\_device *, void *, int))}
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\item \texttt{sread} - a pointer to a function of type \texttt{int fn(struct pico\_device *, void *, int)}
specifying the target serial read function. The function prototype will be called with the device pointer,
a buffer to be filled with serial data, and the maximum lenght of the usable buffer.
\end{itemize}
\subsubsection*{Return value}
0 returned if the serial read function is successfully associated.
\subsubsection*{Example}
\begin{verbatim}
static int my_serial_read(struct pico_device *dev, void *buf, int len)
{
return nonblock_uart_read(buf, len);
}
pico_ppp_set_serial_read(ppp, my_serial_read);
\end{verbatim}
\subsection{pico\_ppp\_set\_serial\_write}
\subsubsection*{Description}
This function will associate the write function from an external source (e.g. a UART device API)
to the write functionality of the PPP driver. Setting up a proper read/write interface is necessary
for the PPP driver to work properly.
The function associated with the write must be non-blocking, no matter the execution model of the system.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_set\_serial\_write(struct pico\_device *dev, int (*swrite)(struct pico\_device *, const void *, int))}
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\item \texttt{swrite} - a pointer to a function of type \texttt{int fn(struct pico\_device *, const void *, int)}
specifying the target serial write function. The function prototype will be called with the device pointer,
a buffer to be filled with serial data, and the maximum lenght of the usable buffer.
\end{itemize}
\subsubsection*{Return value}
0 returned if the serial write function is successfully associated.
\subsubsection*{Example}
\begin{verbatim}
static int my_serial_write(struct pico_device *dev, const void *buf, int len)
{
return nonblock_uart_write(buf, len);
}
pico_ppp_set_serial_write(ppp, my_serial_write);
\end{verbatim}
\subsection{pico\_ppp\_set\_serial\_set\_speed}
\subsubsection*{Description}
This function will associate the set\_speed function from an external source (e.g. a UART device API)
to dynamically set the UART speed for the interface with the PPP driver.
Calling this function is not mandatory for the PPP UART interface to work.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_set\_serial\_set\_speed(struct pico\_device *dev, int (*sset\_speed)(struct pico\_device *, uint32\_t))}
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\item \texttt{sset\_speed} - a pointer to a function of type \texttt{int fn(struct pico\_device *, uint32\_t speed)}
specifying the target serial set\_speed function. The function prototype will be called with the device pointer and
the speed at which the UART should be configured by PPP.
\end{itemize}
\subsubsection*{Return value}
0 returned if the serial set\_speed function is successfully associated.
\subsubsection*{Example}
\begin{verbatim}
static int my_serial_set_speed(struct pico_device *dev, uint32_t speed)
{
return uart_set_speed(speed);
}
pico_ppp_set_serial_set_speed(ppp, my_serial_set_speed);
\end{verbatim}
\subsection{pico\_ppp\_set\_apn}
\subsubsection*{Description}
This function allows the configuration of the APN name in order for PPP to correctly establish the connection
to the remote Access Point gateway.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_set\_apn(struct pico\_device *dev, const char *apn);}
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\item \texttt{apn} - a string containing the Access Point Name.
\end{itemize}
\subsubsection*{Return value}
0 returned if the APN is correctly configured.
\subsubsection*{Example}
\begin{verbatim}
ret = pico_ppp_set_apn(dev, "internet.apn.name");
\end{verbatim}
\subsection{pico\_ppp\_set\_username}
\subsubsection*{Description}
This function will set an username for the PAP/CHAP authentication mechanism.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_set\_username(struct pico\_device *dev, const char *username); }
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\item \texttt{username} - a string specifying the desired username.
\end{itemize}
\subsubsection*{Return value}
0 returned if the username is successfully configured.
\subsubsection*{Example}
\begin{verbatim}
ret = pico_ppp_set_username(dev, "john");
\end{verbatim}
\subsection{pico\_ppp\_set\_password}
\subsubsection*{Description}
This function will set the password for the PAP/CHAP authentication mechanism.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_set\_password(struct pico\_device *dev, const char *password); }
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\item \texttt{username} - a string specifying the desired password.
\end{itemize}
\subsubsection*{Return value}
0 returned if the password is successfully configured.
\subsubsection*{Example}
\begin{verbatim}
ret = pico_ppp_set_password(dev, "secret");
\end{verbatim}
\subsection{pico\_ppp\_connect}
\subsubsection*{Description}
This function will enable the PPP connection, by triggering the startup of the handshakes
required at all levels. If the connection is dropped, the system will try to reconnect by restarting
the handshakes, until \texttt{pico\_ppp\_disconnect} is finally called.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_connect(struct pico\_device *ppp)}
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\end{itemize}
\subsubsection*{Return value}
0 returned if the device is successfully connecting.
\subsubsection*{Example}
\begin{verbatim}
ret = pico_ppp_connect(dev);
\end{verbatim}
\subsection{pico\_ppp\_disconnect}
\subsubsection*{Description}
This function will disable the PPP connection, by triggering a disconnection, and by disabling the
reconnect feature, if enabled.
\subsubsection*{Function prototype}
\texttt{int pico\_ppp\_disconnect(struct pico\_device *ppp)}
\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{dev} - a pointer to a struct \texttt{pico\_device} specifying the target interface.
\end{itemize}
\subsubsection*{Return value}
0 returned if the device is successfully put in disconnected state.
\subsubsection*{Example}
\begin{verbatim}
ret = pico_ppp_disconnect(dev);
\end{verbatim}