Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ppp_service_if.h
00001 /* 00002 * Copyright (c) 2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef PPP_SERVICE_IF_H 00019 #define PPP_SERVICE_IF_H 00020 00021 #include "nsapi_types.h" 00022 00023 #include <stdint.h> 00024 00025 typedef uint8_t u8_t; 00026 typedef int8_t s8_t; 00027 typedef uint16_t u16_t; 00028 typedef int16_t s16_t; 00029 typedef uint32_t u32_t; 00030 typedef int32_t s32_t; 00031 00032 typedef s8_t err_t; 00033 00034 #include <inttypes.h> 00035 #ifndef X8_F 00036 #define X8_F "02" PRIx8 00037 #endif 00038 #ifndef U16_F 00039 #define U16_F PRIu16 00040 #endif 00041 #ifndef S16_F 00042 #define S16_F PRId16 00043 #endif 00044 #ifndef X16_F 00045 #define X16_F PRIx16 00046 #endif 00047 #ifndef U32_F 00048 #define U32_F PRIu32 00049 #endif 00050 #ifndef S32_F 00051 #define S32_F PRId32 00052 #endif 00053 #ifndef X32_F 00054 #define X32_F PRIx32 00055 #endif 00056 #ifndef SZT_F 00057 #define SZT_F PRIuPTR 00058 #endif 00059 00060 struct netif; 00061 00062 typedef enum { 00063 /** No error, everything OK. */ 00064 ERR_OK = 0, 00065 /** Out of memory error. */ 00066 ERR_MEM = -1, 00067 /** Buffer error. */ 00068 ERR_BUF = -2, 00069 /** Timeout. */ 00070 ERR_TIMEOUT = -3, 00071 /** Routing problem. */ 00072 ERR_RTE = -4, 00073 /** Operation in progress */ 00074 ERR_INPROGRESS = -5, 00075 /** Illegal value. */ 00076 ERR_VAL = -6, 00077 /** Operation would block. */ 00078 ERR_WOULDBLOCK = -7, 00079 /** Address in use. */ 00080 ERR_USE = -8, 00081 /** Already connecting. */ 00082 ERR_ALREADY = -9, 00083 /** Conn already established.*/ 00084 ERR_ISCONN = -10, 00085 /** Not connected. */ 00086 ERR_CONN = -11, 00087 /** Low-level netif error */ 00088 ERR_IF = -12, 00089 00090 /** Connection aborted. */ 00091 ERR_ABRT = -13, 00092 /** Connection reset. */ 00093 ERR_RST = -14, 00094 /** Connection closed. */ 00095 ERR_CLSD = -15, 00096 /** Illegal argument. */ 00097 ERR_ARG = -16 00098 } err_enum_t; 00099 00100 /** Eliminates compiler warning about unused arguments */ 00101 #ifndef PPP_UNUSED_ARG 00102 #define PPP_UNUSED_ARG(x) (void)x 00103 #endif /* PPP_UNUSED_ARG */ 00104 00105 #define PPP_MAX(x , y) (((x) > (y)) ? (x) : (y)) 00106 #define PPP_MIN(x , y) (((x) < (y)) ? (x) : (y)) 00107 00108 typedef nsapi_addr_t ip4_addr_t; 00109 typedef nsapi_addr_t ip6_addr_t; 00110 typedef nsapi_addr_t ip_addr_t; 00111 00112 #define IPADDR_STRLEN_MAX 46 00113 00114 #define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0) 00115 #define IP_CLASSA_NET 0xff000000 00116 #define IP_CLASSA_NSHIFT 24 00117 #define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET) 00118 #define IP_CLASSA_MAX 128 00119 00120 #define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL) 00121 #define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */ 00122 #define IP_CLASSD_NSHIFT 28 /* net and host fields, but */ 00123 #define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 00124 #define IP_MULTICAST(a) IP_CLASSD(a) 00125 00126 #define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) 00127 00128 #define IP_LOOPBACKNET 127 /* official! */ 00129 00130 #define ip4_addr_set_u32(dest_ipaddr, src_u32) \ 00131 ppp_ip4_addr_set((nsapi_addr_t *)dest_ipaddr, &src_u32) 00132 00133 #define ip_addr_set_ip4_u32_val(ipaddr, val) \ 00134 ppp_ip4_addr_set((nsapi_addr_t *)&ipaddr, &val) 00135 00136 struct pbuf { 00137 struct pbuf *next; // Next buffer on the chain 00138 void *memory_manager; // Memory manager used to allocate buffer 00139 void *buffer; // Buffer allocated by memory manager 00140 void *payload; // Pointer to payload of the first buffer on the chain (payload_start + headroom) 00141 void *payload_start; // Pointer to payload start of the first buffer on the chain 00142 uint16_t len; // Length of the first buffer on the chain (equals to total length on alloc) 00143 uint16_t tot_len; // Total length of the first buffer on the chain 00144 }; 00145 00146 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); 00147 #if PPP_IPV4_SUPPORT 00148 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, 00149 const ip4_addr_t *ipaddr); 00150 #endif 00151 #if PPP_IPV6_SUPPORT 00152 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, 00153 const ip6_addr_t *ipaddr); 00154 #endif 00155 typedef err_t (*netif_init_fn)(struct netif *netif); 00156 00157 struct netif { 00158 /** Pointer to PPP Service */ 00159 void *service_ptr; 00160 /** Pointer to memory manager */ 00161 void *memory_manager; 00162 /** Pointer to memory stream */ 00163 void *stream; 00164 /** This function is called by the PPP service 00165 * to pass a packet up the TCP/IP stack. */ 00166 netif_input_fn input; 00167 #if PPP_IPV4_SUPPORT 00168 /** This function is called by the IP module when it wants 00169 * to send a packet on the interface. */ 00170 netif_output_fn output; 00171 nsapi_addr_t ipv4_addr; 00172 nsapi_addr_t ipv4_netmask; 00173 nsapi_addr_t ipv4_gateway; 00174 nsapi_addr_t ipv4_dns_server[2]; 00175 u8_t ipv4_up; 00176 #endif /* PPP_IPV4_SUPPORT */ 00177 #if PPP_IPV6_SUPPORT 00178 /** This function is called by the IPv6 module when it wants 00179 * to send a packet on the interface. */ 00180 netif_output_ip6_fn output_ip6; 00181 nsapi_addr_t ipv6_addr; 00182 u8_t ipv6_up; 00183 #endif /* PPP_IPV6_SUPPORT */ 00184 /** This field can be set by the PPP protocol and could point 00185 * to state information for the protocol. */ 00186 void *state; 00187 /** maximum transfer unit (in bytes) */ 00188 u16_t mtu; 00189 #if PPP_DEBUG 00190 u8_t num; 00191 #endif 00192 }; 00193 00194 #define netif_set_link_up(netif) ppp_netif_set_link_up(netif) 00195 #define netif_set_link_down(netif) ppp_netif_set_link_down(netif) 00196 00197 #define PPP_MEMPOOL_PROTOTYPE(name) 00198 #define PPP_MEMPOOL_INIT(name) 00199 #define PPP_MEMPOOL_ALLOC(name) 1 00200 #define PPP_MEMPOOL_FREE(name, x) 00201 00202 #define PPP_MEMPOOL_DECLARE(name,num,size,desc) \ 00203 uint32_t name = size; 00204 00205 #define PBUF_RAW 1 00206 #define PBUF_POOL 2 00207 #define PBUF_RAM 2 00208 00209 typedef enum { 00210 PPP_BUF_HEAP = 0, 00211 PPP_BUF_POOL 00212 } ppp_buf_type_e; 00213 00214 #define MEMPOOL_ALLOC(size) \ 00215 malloc(size) 00216 00217 #define MEMPOOL_FREE(x, ptr) \ 00218 free(ptr) 00219 00220 #define pbuf_remove_header(buf, size) \ 00221 ppp_memory_buffer_remove_header(buf, size) 00222 00223 #define pbuf_add_header(buf, size) \ 00224 ppp_memory_buffer_add_header(buf, size) 00225 00226 #define LINK_STATS_INC(x) 00227 #define MIB2_STATS_NETIF_INC(n, x) 00228 #define MIB2_INIT_NETIF(netif, type, speed) 00229 #define MIB2_STATS_NETIF_ADD(n, x, val) 00230 00231 #define PPP_ASSERT(message, assertion) 00232 00233 typedef int sys_prot_t; 00234 00235 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev 00236 #define SYS_ARCH_PROTECT(lev) lev = ppp_sys_arch_protect(ppp->netif->service_ptr) 00237 #define SYS_ARCH_UNPROTECT(lev) ppp_sys_arch_unprotect(ppp->netif->service_ptr, lev) 00238 00239 #define PPPOS_DECL_PROTECT(lev) SYS_ARCH_DECL_PROTECT(lev) 00240 #define PPPOS_PROTECT(lev) SYS_ARCH_PROTECT(lev) 00241 #define PPPOS_UNPROTECT(lev) SYS_ARCH_UNPROTECT(lev) 00242 00243 #include <ctype.h> 00244 #define ppp_isdigit(c) isdigit((unsigned char)(c)) 00245 00246 #define sys_now ppp_sys_now 00247 #define sys_jiffies() ppp_sys_jiffies(); 00248 00249 #define TIMEOUT(f, a, t) do { ppp_sys_untimeout((f), (a)); ppp_sys_timeout(pcb->netif->service_ptr, (t)*1000, (f), (a)); } while(0) 00250 #define TIMEOUTMS(f, a, t) do { ppp_sys_untimeout((f), (a)); ppp_sys_timeout(pcb->netif->service_ptr, (t), (f), (a)); } while(0) 00251 #define UNTIMEOUT(f, a) do { ppp_sys_untimeout((f), (a)); } while(0) 00252 00253 #define sys_timeout(msecs, handler, arg) ppp_sys_timeout(pcb->netif->service_ptr, msecs, (ppp_sys_timeout_handler) handler, (void *) arg) 00254 #define sys_untimeout(handler, arg) ppp_sys_untimeout(handler, (void *) arg) 00255 00256 #define OUTPUT_BUFFER 0 00257 #define INPUT_BUFFER 1 00258 00259 #if defined(__arm__) && defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 6010050) 00260 /* Keil uVision4 tools */ 00261 #define PACK_STRUCT_BEGIN __packed 00262 #define PACK_STRUCT_STRUCT 00263 #define PACK_STRUCT_END 00264 #define PACK_STRUCT_FIELD(fld) fld 00265 #define ALIGNED(n) __align(n) 00266 #elif defined (__IAR_SYSTEMS_ICC__) 00267 /* IAR Embedded Workbench tools */ 00268 #define PACK_STRUCT_BEGIN __packed 00269 #define PACK_STRUCT_STRUCT 00270 #define PACK_STRUCT_END 00271 #define PACK_STRUCT_FIELD(fld) fld 00272 #define IAR_STR(a) #a 00273 #define ALIGNED(n) _Pragma(IAR_STR(data_alignment= ## n ##)) 00274 #else 00275 /* GCC tools (CodeSourcery) */ 00276 #define PACK_STRUCT_BEGIN 00277 #define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) 00278 #define PACK_STRUCT_END 00279 #define PACK_STRUCT_FIELD(fld) fld 00280 #define ALIGNED(n) __attribute__((aligned (n))) 00281 #endif 00282 00283 /** 00284 * MEMCPY: override this if you have a faster implementation at hand than the 00285 * one included in your C library 00286 */ 00287 #if !defined MEMCPY 00288 #define MEMCPY(dst,src,len) memcpy(dst,src,len) 00289 #endif 00290 00291 #define UNUSED_ARG(x) (void)x 00292 00293 #ifdef __cplusplus 00294 extern "C" { 00295 #endif 00296 00297 struct pbuf *ppp_memory_buffer_allocate(void *memory_manager, uint16_t size, ppp_buf_type_e type); 00298 void ppp_memory_buffer_free(struct pbuf *buffer); 00299 uint16_t ppp_memory_buffer_pool_alloc_unit_get(void *memory_manager); 00300 void ppp_memory_buffer_cat(void *memory_manager, struct pbuf *to_buf, struct pbuf *cat_buf); 00301 void ppp_memory_buffer_set_len(void *memory_manager, struct pbuf *buf, uint16_t len); 00302 uint8_t ppp_memory_buffer_remove_header(struct pbuf *buffer, uint16_t header_len); 00303 uint8_t ppp_memory_buffer_add_header(struct pbuf *buffer, uint16_t header_len); 00304 00305 struct pbuf *ppp_memory_buffer_convert_to(void *memory_manager, void *mem_buf); 00306 void *ppp_memory_buffer_convert_from(struct pbuf *pbuf); 00307 00308 struct netif *ppp_netif_add(struct netif *netif, void *state, netif_init_fn init); 00309 #define ppp_netif_remove(param) 00310 err_t ppp_ip_input(struct pbuf *p, struct netif *inp); 00311 void ppp_ip4_addr_set(nsapi_addr_t *addr, uint32_t *src); 00312 00313 void ppp_set_link_up(struct netif *netif); 00314 void ppp_set_link_down(struct netif *netif); 00315 00316 typedef void ppp_service_cb(void *arg); 00317 err_t ppp_call_callback(void *service_ptr, ppp_service_cb callback, void *arg); 00318 00319 sys_prot_t ppp_sys_arch_protect(void *service_ptr); 00320 void ppp_sys_arch_unprotect(void *service_ptr, sys_prot_t p); 00321 00322 typedef void (*ppp_sys_timeout_handler)(void *arg); 00323 void ppp_sys_timeout(void *service_ptr, u32_t msecs, ppp_sys_timeout_handler handler, void *arg); 00324 void ppp_sys_untimeout(ppp_sys_timeout_handler handler, void *arg); 00325 00326 uint32_t ppp_sys_now(void); 00327 uint32_t ppp_sys_jiffies(void); 00328 00329 void ppp_trace_to_ascii_hex_dump(int output, int len, char *data); 00330 void ppp_trace_to_ascii_hex_dump_print(int output); 00331 00332 #ifdef __cplusplus 00333 } 00334 #endif 00335 00336 #endif /* PPP_SERVICE_IF_H */
Generated on Tue Jul 12 2022 13:54:42 by
