Mistake on this page?
Report an issue in GitHub or email us
ppp_service_if.h
1 /*
2  * Copyright (c) 2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef PPP_SERVICE_IF_H
19 #define PPP_SERVICE_IF_H
20 
21 #include "nsapi_types.h"
22 
23 #include <stdint.h>
24 
25 typedef uint8_t u8_t;
26 typedef int8_t s8_t;
27 typedef uint16_t u16_t;
28 typedef int16_t s16_t;
29 typedef uint32_t u32_t;
30 typedef int32_t s32_t;
31 
32 typedef s8_t err_t;
33 
34 #include <inttypes.h>
35 #ifndef X8_F
36 #define X8_F "02" PRIx8
37 #endif
38 #ifndef U16_F
39 #define U16_F PRIu16
40 #endif
41 #ifndef S16_F
42 #define S16_F PRId16
43 #endif
44 #ifndef X16_F
45 #define X16_F PRIx16
46 #endif
47 #ifndef U32_F
48 #define U32_F PRIu32
49 #endif
50 #ifndef S32_F
51 #define S32_F PRId32
52 #endif
53 #ifndef X32_F
54 #define X32_F PRIx32
55 #endif
56 #ifndef SZT_F
57 #define SZT_F PRIuPTR
58 #endif
59 
60 struct netif;
61 
62 typedef enum {
63  /** No error, everything OK. */
64  ERR_OK = 0,
65  /** Out of memory error. */
66  ERR_MEM = -1,
67  /** Buffer error. */
68  ERR_BUF = -2,
69  /** Timeout. */
71  /** Routing problem. */
72  ERR_RTE = -4,
73  /** Operation in progress */
75  /** Illegal value. */
76  ERR_VAL = -6,
77  /** Operation would block. */
79  /** Address in use. */
80  ERR_USE = -8,
81  /** Already connecting. */
83  /** Conn already established.*/
84  ERR_ISCONN = -10,
85  /** Not connected. */
86  ERR_CONN = -11,
87  /** Low-level netif error */
88  ERR_IF = -12,
89 
90  /** Connection aborted. */
91  ERR_ABRT = -13,
92  /** Connection reset. */
93  ERR_RST = -14,
94  /** Connection closed. */
95  ERR_CLSD = -15,
96  /** Illegal argument. */
97  ERR_ARG = -16
98 } err_enum_t;
99 
100 /** Eliminates compiler warning about unused arguments */
101 #ifndef PPP_UNUSED_ARG
102 #define PPP_UNUSED_ARG(x) (void)x
103 #endif /* PPP_UNUSED_ARG */
104 
105 #define PPP_MAX(x , y) (((x) > (y)) ? (x) : (y))
106 #define PPP_MIN(x , y) (((x) < (y)) ? (x) : (y))
107 
108 typedef nsapi_addr_t ip4_addr_t;
109 typedef nsapi_addr_t ip6_addr_t;
110 typedef nsapi_addr_t ip_addr_t;
111 
112 #define IPADDR_STRLEN_MAX 46
113 
114 #define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
115 #define IP_CLASSA_NET 0xff000000
116 #define IP_CLASSA_NSHIFT 24
117 #define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
118 #define IP_CLASSA_MAX 128
119 
120 #define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
121 #define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
122 #define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
123 #define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
124 #define IP_MULTICAST(a) IP_CLASSD(a)
125 
126 #define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
127 
128 #define IP_LOOPBACKNET 127 /* official! */
129 
130 #define ip4_addr_set_u32(dest_ipaddr, src_u32) \
131  ppp_ip4_addr_set((nsapi_addr_t *)dest_ipaddr, &src_u32)
132 
133 #define ip_addr_set_ip4_u32_val(ipaddr, val) \
134  ppp_ip4_addr_set((nsapi_addr_t *)&ipaddr, &val)
135 
136 struct pbuf {
137  struct pbuf *next; // Next buffer on the chain
138  void *memory_manager; // Memory manager used to allocate buffer
139  void *buffer; // Buffer allocated by memory manager
140  void *payload; // Pointer to payload of the first buffer on the chain (payload_start + headroom)
141  void *payload_start; // Pointer to payload start of the first buffer on the chain
142  uint16_t len; // Length of the first buffer on the chain (equals to total length on alloc)
143  uint16_t tot_len; // Total length of the first buffer on the chain
144 };
145 
146 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
147 #if PPP_IPV4_SUPPORT
148 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
149  const ip4_addr_t *ipaddr);
150 #endif
151 #if PPP_IPV6_SUPPORT
152 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
153  const ip6_addr_t *ipaddr);
154 #endif
155 typedef err_t (*netif_init_fn)(struct netif *netif);
156 
157 struct netif {
158  /** Pointer to PPP Service */
159  void *service_ptr;
160  /** Pointer to memory manager */
162  /** Pointer to memory stream */
163  void *stream;
164  /** This function is called by the PPP service
165  * to pass a packet up the TCP/IP stack. */
167 #if PPP_IPV4_SUPPORT
168  /** This function is called by the IP module when it wants
169  * to send a packet on the interface. */
170  netif_output_fn output;
171  nsapi_addr_t ipv4_addr;
172  nsapi_addr_t ipv4_netmask;
173  nsapi_addr_t ipv4_gateway;
174  nsapi_addr_t ipv4_dns_server[2];
175  u8_t ipv4_up;
176 #endif /* PPP_IPV4_SUPPORT */
177 #if PPP_IPV6_SUPPORT
178  /** This function is called by the IPv6 module when it wants
179  * to send a packet on the interface. */
180  netif_output_ip6_fn output_ip6;
181  nsapi_addr_t ipv6_addr;
182  u8_t ipv6_up;
183 #endif /* PPP_IPV6_SUPPORT */
184  /** This field can be set by the PPP protocol and could point
185  * to state information for the protocol. */
186  void *state;
187  /** maximum transfer unit (in bytes) */
188  u16_t mtu;
189 #if PPP_DEBUG
190  u8_t num;
191 #endif
192 };
193 
194 #define netif_set_link_up(netif) ppp_netif_set_link_up(netif)
195 #define netif_set_link_down(netif) ppp_netif_set_link_down(netif)
196 
197 #define PPP_MEMPOOL_PROTOTYPE(name)
198 #define PPP_MEMPOOL_INIT(name)
199 #define PPP_MEMPOOL_ALLOC(name) 1
200 #define PPP_MEMPOOL_FREE(name, x)
201 
202 #define PPP_MEMPOOL_DECLARE(name,num,size,desc) \
203  uint32_t name = size;
204 
205 #define PBUF_RAW 1
206 #define PBUF_POOL 2
207 #define PBUF_RAM 2
208 
209 typedef enum {
210  PPP_BUF_HEAP = 0,
211  PPP_BUF_POOL
212 } ppp_buf_type_e;
213 
214 #define MEMPOOL_ALLOC(size) \
215  malloc(size)
216 
217 #define MEMPOOL_FREE(x, ptr) \
218  free(ptr)
219 
220 #define pbuf_remove_header(buf, size) \
221  ppp_memory_buffer_remove_header(buf, size)
222 
223 #define pbuf_add_header(buf, size) \
224  ppp_memory_buffer_add_header(buf, size)
225 
226 #define LINK_STATS_INC(x)
227 #define MIB2_STATS_NETIF_INC(n, x)
228 #define MIB2_INIT_NETIF(netif, type, speed)
229 #define MIB2_STATS_NETIF_ADD(n, x, val)
230 
231 #define PPP_ASSERT(message, assertion)
232 
233 typedef int sys_prot_t;
234 
235 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
236 #define SYS_ARCH_PROTECT(lev) lev = ppp_sys_arch_protect(ppp->netif->service_ptr)
237 #define SYS_ARCH_UNPROTECT(lev) ppp_sys_arch_unprotect(ppp->netif->service_ptr, lev)
238 
239 #define PPPOS_DECL_PROTECT(lev) SYS_ARCH_DECL_PROTECT(lev)
240 #define PPPOS_PROTECT(lev) SYS_ARCH_PROTECT(lev)
241 #define PPPOS_UNPROTECT(lev) SYS_ARCH_UNPROTECT(lev)
242 
243 #include <ctype.h>
244 #define ppp_isdigit(c) isdigit((unsigned char)(c))
245 
246 #define sys_now ppp_sys_now
247 #define sys_jiffies() ppp_sys_jiffies();
248 
249 #define TIMEOUT(f, a, t) do { ppp_sys_untimeout((f), (a)); ppp_sys_timeout(pcb->netif->service_ptr, (t)*1000, (f), (a)); } while(0)
250 #define TIMEOUTMS(f, a, t) do { ppp_sys_untimeout((f), (a)); ppp_sys_timeout(pcb->netif->service_ptr, (t), (f), (a)); } while(0)
251 #define UNTIMEOUT(f, a) do { ppp_sys_untimeout((f), (a)); } while(0)
252 
253 #define sys_timeout(msecs, handler, arg) ppp_sys_timeout(pcb->netif->service_ptr, msecs, (ppp_sys_timeout_handler) handler, (void *) arg)
254 #define sys_untimeout(handler, arg) ppp_sys_untimeout(handler, (void *) arg)
255 
256 #define OUTPUT_BUFFER 0
257 #define INPUT_BUFFER 1
258 
259 #if defined (__IAR_SYSTEMS_ICC__)
260 /* IAR Embedded Workbench tools */
261 #define PACK_STRUCT_BEGIN __packed
262 #define PACK_STRUCT_STRUCT
263 #define PACK_STRUCT_END
264 #define PACK_STRUCT_FIELD(fld) fld
265 #define IAR_STR(a) #a
266 #define ALIGNED(n) _Pragma(IAR_STR(data_alignment= ## n ##))
267 #else
268 /* GCC tools (CodeSourcery) */
269 #define PACK_STRUCT_BEGIN
270 #define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
271 #define PACK_STRUCT_END
272 #define PACK_STRUCT_FIELD(fld) fld
273 #define ALIGNED(n) __attribute__((aligned (n)))
274 #endif
275 
276 /**
277  * MEMCPY: override this if you have a faster implementation at hand than the
278  * one included in your C library
279  */
280 #if !defined MEMCPY
281 #define MEMCPY(dst,src,len) memcpy(dst,src,len)
282 #endif
283 
284 #define UNUSED_ARG(x) (void)x
285 
286 #ifdef __cplusplus
287 extern "C" {
288 #endif
289 
290 struct pbuf *ppp_memory_buffer_allocate(void *memory_manager, uint16_t size, ppp_buf_type_e type);
291 void ppp_memory_buffer_free(struct pbuf *buffer);
292 uint16_t ppp_memory_buffer_pool_alloc_unit_get(void *memory_manager);
293 void ppp_memory_buffer_cat(void *memory_manager, struct pbuf *to_buf, struct pbuf *cat_buf);
294 void ppp_memory_buffer_set_len(void *memory_manager, struct pbuf *buf, uint16_t len);
295 uint8_t ppp_memory_buffer_remove_header(struct pbuf *buffer, uint16_t header_len);
296 uint8_t ppp_memory_buffer_add_header(struct pbuf *buffer, uint16_t header_len);
297 
298 struct pbuf *ppp_memory_buffer_convert_to(void *memory_manager, void *mem_buf);
299 void *ppp_memory_buffer_convert_from(struct pbuf *pbuf);
300 
301 struct netif *ppp_netif_add(struct netif *netif, void *state, netif_init_fn init);
302 #define ppp_netif_remove(param)
303 err_t ppp_ip_input(struct pbuf *p, struct netif *inp);
304 void ppp_ip4_addr_set(nsapi_addr_t *addr, uint32_t *src);
305 
306 void ppp_set_link_up(struct netif *netif);
307 void ppp_set_link_down(struct netif *netif);
308 
309 typedef void ppp_service_cb(void *arg);
310 err_t ppp_call_callback(void *service_ptr, ppp_service_cb callback, void *arg);
311 
312 sys_prot_t ppp_sys_arch_protect(void *service_ptr);
313 void ppp_sys_arch_unprotect(void *service_ptr, sys_prot_t p);
314 
315 typedef void (*ppp_sys_timeout_handler)(void *arg);
316 void ppp_sys_timeout(void *service_ptr, u32_t msecs, ppp_sys_timeout_handler handler, void *arg);
317 void ppp_sys_untimeout(ppp_sys_timeout_handler handler, void *arg);
318 
319 uint32_t ppp_sys_now(void);
320 uint32_t ppp_sys_jiffies(void);
321 
322 void ppp_trace_to_ascii_hex_dump(int output, int len, char *data);
323 void ppp_trace_to_ascii_hex_dump_print(int output);
324 
325 #ifdef __cplusplus
326 }
327 #endif
328 
329 #endif /* PPP_SERVICE_IF_H */
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Function prototype for netif->input functions.
Definition: netif.h:179
void * state
This field can be set by the PPP protocol and could point to state information for the protocol...
Connection aborted.
void * payload
pointer to the actual data in the buffer
Buffer error.
void * memory_manager
Pointer to memory manager.
netif_input_fn input
This function is called by the PPP service to pass a packet up the TCP/IP stack.
u16_t mtu
maximum transfer unit (in bytes)
Operation in progress.
Out of memory error.
struct pbuf * next
next pbuf in singly linked pbuf chain
void * stream
Pointer to memory stream.
Connection closed.
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
Illegal argument.
Operation would block.
Main packet buffer struct.
Timeout.
Conn already established.
Generic data structure used for all lwIP network interfaces.
err_t(* netif_init_fn)(struct netif *netif)
Function prototype for netif init functions.
Definition: netif.h:169
Low-level netif error.
s8_t err_t
Define LWIP_ERR_T in cc.h if you want to use a different type for your platform (must be signed)...
Definition: err.h:96
Not connected.
err_enum_t
Definitions for error constants.
Definition: err.h:53
Connection reset.
Illegal value.
Already connecting.
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:235
No error, everything OK.
Address in use.
Routing problem.
void * service_ptr
Pointer to PPP Service.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.