Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
ppp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7
8#ifndef ZEPHYR_INCLUDE_NET_PPP_H_
9#define ZEPHYR_INCLUDE_NET_PPP_H_
10
11#include <net/net_if.h>
12#include <net/net_pkt.h>
13#include <net/net_stats.h>
14#include <net/net_mgmt.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
28#define PPP_MRU CONFIG_NET_PPP_MTU_MRU
29
31#define PPP_MTU PPP_MRU
32
34#define PPP_MAX_TERMINATE_REASON_LEN 32
35
37#define PPP_INTERFACE_IDENTIFIER_LEN 8
38
40struct ppp_api {
45 struct net_if_api iface_api;
46
48 int (*start)(const struct device *dev);
49
51 int (*stop)(const struct device *dev);
52
54 int (*send)(const struct device *dev, struct net_pkt *pkt);
55
56#if defined(CONFIG_NET_STATISTICS_PPP)
61 struct net_stats_ppp *(*get_stats)(const struct device *dev);
62#endif
63};
64
65/* Make sure that the network interface API is properly setup inside
66 * PPP API struct (it is the first one).
67 */
68BUILD_ASSERT(offsetof(struct ppp_api, iface_api) == 0);
69
76 PPP_IP = 0x0021,
77 PPP_IPV6 = 0x0057,
78 PPP_IPCP = 0x8021,
79 PPP_ECP = 0x8053,
80 PPP_IPV6CP = 0x8057,
81 PPP_CCP = 0x80FD,
82 PPP_LCP = 0xc021,
83 PPP_PAP = 0xc023,
84 PPP_CHAP = 0xc223,
85 PPP_EAP = 0xc227,
86};
87
104};
105
121
136 PPP_DISCARD_REQ = 11
138
144
147
150
153
156
159
162
165} __packed;
166
172
175
178
181
182 /* RFC 1877 */
183
186
189
192
195} __packed;
196
202
205} __packed;
206
216 size_t user_data_len);
217
218struct ppp_my_option_data;
219struct ppp_my_option_info;
220
224struct ppp_fsm {
227
228 struct {
230 int (*config_info_ack)(struct ppp_fsm *fsm,
231 struct net_pkt *pkt,
232 uint16_t length);
233
235 struct net_pkt *(*config_info_add)(struct ppp_fsm *fsm);
236
238 int (*config_info_len)(struct ppp_fsm *fsm);
239
241 int (*config_info_nack)(struct ppp_fsm *fsm,
242 struct net_pkt *pkt,
243 uint16_t length,
244 bool rejected);
245
247 int (*config_info_req)(struct ppp_fsm *fsm,
248 struct net_pkt *pkt,
249 uint16_t length,
250 struct net_pkt *ret_pkt);
251
253 int (*config_info_rej)(struct ppp_fsm *fsm,
254 struct net_pkt *pkt,
255 uint16_t length);
256
259
261 void (*up)(struct ppp_fsm *fsm);
262
264 void (*down)(struct ppp_fsm *fsm);
265
267 void (*starting)(struct ppp_fsm *fsm);
268
270 void (*finished)(struct ppp_fsm *fsm);
271
273 void (*proto_reject)(struct ppp_fsm *fsm);
274
276 void (*retransmit)(struct ppp_fsm *fsm);
277
281 enum net_verdict (*proto_extension)(struct ppp_fsm *fsm,
282 enum ppp_packet_type code,
283 uint8_t id,
284 struct net_pkt *pkt);
285 } cb;
286
287 struct {
289 const struct ppp_my_option_info *info;
290
293
295 size_t count;
297
300;
303
306
309
312
315
318
320 const char *name;
321
324
327
330};
331
332#define PPP_MY_OPTION_ACKED BIT(0)
333#define PPP_MY_OPTION_REJECTED BIT(1)
334
337};
338
342
345
348
351};
352
353#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
354#define LCP_NUM_MY_OPTIONS 1
355#endif
356
362};
363
364#define IPCP_NUM_MY_OPTIONS 3
365
369};
370
371#define IPV6CP_NUM_MY_OPTIONS 1
372
375};
376
383
386
394
395 struct {
397 struct ppp_fsm fsm;
398
401
404
407#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
408 struct ppp_my_option_data my_options_data[LCP_NUM_MY_OPTIONS];
409#endif
411
412#if defined(CONFIG_NET_IPV4)
413 struct {
415 struct ppp_fsm fsm;
416
419
422
424 struct ppp_my_option_data my_options_data[IPCP_NUM_MY_OPTIONS];
425 } ipcp;
426#endif
427
428#if defined(CONFIG_NET_IPV6)
429 struct {
431 struct ppp_fsm fsm;
432
435
438
440 struct ppp_my_option_data my_options_data[IPV6CP_NUM_MY_OPTIONS];
441 } ipv6cp;
442#endif
443
444#if defined(CONFIG_NET_L2_PPP_PAP)
445 struct {
447 struct ppp_fsm fsm;
448 } pap;
449#endif
450
451#if defined(CONFIG_NET_SHELL)
452 struct {
453 struct {
457
459 void *user_data;
460
462 size_t user_data_len;
463 } echo_reply;
464
466 struct k_sem wait_echo_reply;
467
469 uint32_t echo_req_data;
470
472 uint32_t echo_reply_data;
473 } shell;
474#endif
475
477 struct net_if *iface;
478
481
484
487
490
493
496
499
502
505
508
511
514
517
520
523};
524
531void net_ppp_carrier_on(struct net_if *iface);
532
539void net_ppp_carrier_off(struct net_if *iface);
540
546void net_ppp_init(struct net_if *iface);
547
548/* Management API for PPP */
549
552#define PPP_L2_CTX_TYPE struct ppp_context
553
554#define _NET_PPP_LAYER NET_MGMT_LAYER_L2
555#define _NET_PPP_CODE 0x209
556#define _NET_PPP_BASE (NET_MGMT_IFACE_BIT | \
557 NET_MGMT_LAYER(_NET_PPP_LAYER) | \
558 NET_MGMT_LAYER_CODE(_NET_PPP_CODE))
559#define _NET_PPP_EVENT (_NET_PPP_BASE | NET_MGMT_EVENT_BIT)
560
561enum net_event_ppp_cmd {
562 NET_EVENT_PPP_CMD_CARRIER_ON = 1,
563 NET_EVENT_PPP_CMD_CARRIER_OFF,
564 NET_EVENT_PPP_CMD_PHASE_RUNNING,
565 NET_EVENT_PPP_CMD_PHASE_DEAD,
566};
567
568#define NET_EVENT_PPP_CARRIER_ON \
569 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_ON)
570
571#define NET_EVENT_PPP_CARRIER_OFF \
572 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_OFF)
573
574#define NET_EVENT_PPP_PHASE_RUNNING \
575 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_RUNNING)
576
577#define NET_EVENT_PPP_PHASE_DEAD \
578 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_DEAD)
579
580struct net_if;
581
589#if defined(CONFIG_NET_L2_PPP_MGMT)
590void ppp_mgmt_raise_carrier_on_event(struct net_if *iface);
591#else
592static inline void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
593{
594 ARG_UNUSED(iface);
595}
596#endif
597
603#if defined(CONFIG_NET_L2_PPP_MGMT)
604void ppp_mgmt_raise_carrier_off_event(struct net_if *iface);
605#else
606static inline void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
607{
608 ARG_UNUSED(iface);
609}
610#endif
611
617#if defined(CONFIG_NET_L2_PPP_MGMT)
619#else
620static inline void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
621{
622 ARG_UNUSED(iface);
623}
624#endif
625
631#if defined(CONFIG_NET_L2_PPP_MGMT)
632void ppp_mgmt_raise_phase_dead_event(struct net_if *iface);
633#else
634static inline void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
635{
636 ARG_UNUSED(iface);
637}
638#endif
639
650#if defined(CONFIG_NET_L2_PPP)
651int net_ppp_ping(int idx, int32_t timeout);
652#else
653static inline int net_ppp_ping(int idx, int32_t timeout)
654{
655 ARG_UNUSED(idx);
656 ARG_UNUSED(timeout);
657
658 return -ENOTSUP;
659}
660#endif
661
670#if defined(CONFIG_NET_L2_PPP) && defined(CONFIG_NET_SHELL)
671struct ppp_context *net_ppp_context_get(int idx);
672#else
673static inline struct ppp_context *net_ppp_context_get(int idx)
674{
675 ARG_UNUSED(idx);
676
677 return NULL;
678}
679#endif
680
681#ifdef __cplusplus
682}
683#endif
684
689#endif /* ZEPHYR_INCLUDE_NET_PPP_H_ */
int atomic_t
Definition: atomic.h:21
ZTEST_BMEM int timeout
Definition: main.c:31
void
Definition: eswifi_shell.c:15
net_verdict
Net Verdict.
Definition: net_core.h:97
net_l2_flags
Definition: net_l2.h:33
ipcp_option_type
Definition: ppp.h:170
static void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
Raise CARRIER_ON event when PPP is connected.
Definition: ppp.h:592
void(* net_ppp_lcp_echo_reply_cb_t)(void *user_data, size_t user_data_len)
A callback function that can be called if a Echo-Reply needs to be received.
Definition: ppp.h:215
ppp_phase
Definition: ppp.h:91
void net_ppp_carrier_on(struct net_if *iface)
Inform PPP L2 driver that carrier is detected. This happens when cable is connected etc.
#define PPP_MAX_TERMINATE_REASON_LEN
Definition: ppp.h:34
ppp_packet_type
Definition: ppp.h:125
ppp_flags
Definition: ppp.h:373
static struct ppp_context * net_ppp_context_get(int idx)
Get PPP context information. This is only used by net-shell to print information about PPP.
Definition: ppp.h:673
#define IPV6CP_NUM_MY_OPTIONS
Definition: ppp.h:371
ppp_state
Definition: ppp.h:109
static void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
Raise PHASE_RUNNING event when PPP reaching RUNNING phase.
Definition: ppp.h:620
void net_ppp_carrier_off(struct net_if *iface)
Inform PPP L2 driver that carrier was lost. This happens when cable is disconnected etc.
ppp_protocol_type
Definition: ppp.h:75
static int net_ppp_ping(int idx, int32_t timeout)
Send PPP Echo-Request to peer. We expect to receive Echo-Reply back.
Definition: ppp.h:653
void net_ppp_init(struct net_if *iface)
Initialize PPP L2 stack for a given interface.
#define PPP_INTERFACE_IDENTIFIER_LEN
Definition: ppp.h:37
lcp_option_type
Definition: ppp.h:142
static void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
Raise PHASE_DEAD event when PPP reaching DEAD phase.
Definition: ppp.h:634
static void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
Raise CARRIER_OFF event when PPP is disconnected.
Definition: ppp.h:606
#define IPCP_NUM_MY_OPTIONS
Definition: ppp.h:364
ipv6cp_option_type
Definition: ppp.h:200
@ IPCP_OPTION_IP_ADDRESS
Definition: ppp.h:180
@ IPCP_OPTION_DNS2
Definition: ppp.h:191
@ IPCP_OPTION_IP_COMP_PROTO
Definition: ppp.h:177
@ IPCP_OPTION_NBNS2
Definition: ppp.h:194
@ IPCP_OPTION_RESERVED
Definition: ppp.h:171
@ IPCP_OPTION_NBNS1
Definition: ppp.h:188
@ IPCP_OPTION_IP_ADDRESSES
Definition: ppp.h:174
@ IPCP_OPTION_DNS1
Definition: ppp.h:185
@ PPP_AUTH
Definition: ppp.h:97
@ PPP_RUNNING
Definition: ppp.h:101
@ PPP_NETWORK
Definition: ppp.h:99
@ PPP_ESTABLISH
Definition: ppp.h:95
@ PPP_DEAD
Definition: ppp.h:93
@ PPP_TERMINATE
Definition: ppp.h:103
@ PPP_CONFIGURE_NACK
Definition: ppp.h:128
@ PPP_TERMINATE_REQ
Definition: ppp.h:130
@ PPP_CODE_REJ
Definition: ppp.h:132
@ PPP_ECHO_REPLY
Definition: ppp.h:135
@ PPP_TERMINATE_ACK
Definition: ppp.h:131
@ PPP_CONFIGURE_ACK
Definition: ppp.h:127
@ PPP_DISCARD_REQ
Definition: ppp.h:136
@ PPP_CONFIGURE_REQ
Definition: ppp.h:126
@ PPP_CONFIGURE_REJ
Definition: ppp.h:129
@ PPP_PROTOCOL_REJ
Definition: ppp.h:133
@ PPP_ECHO_REQ
Definition: ppp.h:134
@ PPP_CARRIER_UP
Definition: ppp.h:374
@ PPP_CLOSED
Definition: ppp.h:112
@ PPP_CLOSING
Definition: ppp.h:114
@ PPP_OPENED
Definition: ppp.h:119
@ PPP_REQUEST_SENT
Definition: ppp.h:116
@ PPP_STARTING
Definition: ppp.h:111
@ PPP_STOPPED
Definition: ppp.h:113
@ PPP_INITIAL
Definition: ppp.h:110
@ PPP_STOPPING
Definition: ppp.h:115
@ PPP_ACK_RECEIVED
Definition: ppp.h:117
@ PPP_ACK_SENT
Definition: ppp.h:118
@ PPP_IPV6
Definition: ppp.h:77
@ PPP_IP
Definition: ppp.h:76
@ PPP_CHAP
Definition: ppp.h:84
@ PPP_LCP
Definition: ppp.h:82
@ PPP_IPCP
Definition: ppp.h:78
@ PPP_ECP
Definition: ppp.h:79
@ PPP_CCP
Definition: ppp.h:81
@ PPP_EAP
Definition: ppp.h:85
@ PPP_IPV6CP
Definition: ppp.h:80
@ PPP_PAP
Definition: ppp.h:83
@ LCP_OPTION_ASYNC_CTRL_CHAR_MAP
Definition: ppp.h:149
@ LCP_OPTION_ADDR_CTRL_COMPRESS
Definition: ppp.h:164
@ LCP_OPTION_QUALITY_PROTO
Definition: ppp.h:155
@ LCP_OPTION_MAGIC_NUMBER
Definition: ppp.h:158
@ LCP_OPTION_RESERVED
Definition: ppp.h:143
@ LCP_OPTION_PROTO_COMPRESS
Definition: ppp.h:161
@ LCP_OPTION_MRU
Definition: ppp.h:146
@ LCP_OPTION_AUTH_PROTO
Definition: ppp.h:152
@ IPV6CP_OPTION_INTERFACE_IDENTIFIER
Definition: ppp.h:204
@ IPV6CP_OPTION_RESERVED
Definition: ppp.h:201
#define ENOTSUP
Definition: errno.h:115
Public API for network interface.
Network Management API public header.
Network packet buffer descriptor API.
Network statistics.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
Definition: net_ip.h:148
Definition: ppp.h:357
struct in_addr address
Definition: ppp.h:359
struct in_addr dns2_address
Definition: ppp.h:361
struct in_addr dns1_address
Definition: ppp.h:360
Definition: ppp.h:366
uint8_t iid[8]
Definition: ppp.h:368
A structure used to submit work after a delay.
Definition: kernel.h:3651
A structure used to submit work.
Definition: kernel.h:3623
Definition: ppp.h:339
uint16_t mru
Definition: ppp.h:347
uint32_t async_map
Definition: ppp.h:344
uint16_t auth_proto
Definition: ppp.h:350
uint32_t magic
Definition: ppp.h:341
Network Interface structure.
Definition: net_if.h:468
Network packet.
Definition: net_pkt.h:62
All PPP specific statistics.
Definition: net_stats.h:464
Definition: ppp.h:40
int(* stop)(const struct device *dev)
Definition: ppp.h:51
int(* send)(const struct device *dev, struct net_pkt *pkt)
Definition: ppp.h:54
int(* start)(const struct device *dev)
Definition: ppp.h:48
struct net_if_api iface_api
Definition: ppp.h:45
Definition: ppp.h:378
enum net_l2_flags ppp_l2_flags
Definition: ppp.h:483
int network_protos_open
Definition: ppp.h:486
struct ppp_context::@178 lcp
struct lcp_options my_options
Definition: ppp.h:400
struct net_if * iface
Definition: ppp.h:477
uint16_t is_ready_to_serve
Definition: ppp.h:495
uint32_t magic
Definition: ppp.h:406
uint16_t is_pap_up
Definition: ppp.h:519
struct k_work_delayable startup
Definition: ppp.h:385
uint16_t is_net_carrier_up
Definition: ppp.h:492
struct k_work carrier_work
Definition: ppp.h:393
enum ppp_phase phase
Definition: ppp.h:480
atomic_t flags
Definition: ppp.h:382
uint16_t is_ipv6cp_up
Definition: ppp.h:513
uint16_t is_ipcp_open
Definition: ppp.h:510
uint16_t is_enabled
Definition: ppp.h:498
uint16_t is_pap_open
Definition: ppp.h:522
struct lcp_options peer_options
Definition: ppp.h:403
uint16_t is_ipcp_up
Definition: ppp.h:507
uint16_t is_startup_pending
Definition: ppp.h:501
int network_protos_up
Definition: ppp.h:489
uint16_t is_ipv6cp_open
Definition: ppp.h:516
struct ppp_fsm fsm
Definition: ppp.h:397
uint16_t is_enable_done
Definition: ppp.h:504
Definition: ppp.h:224
char terminate_reason[32]
Definition: ppp.h:311
int(* config_info_len)(struct ppp_fsm *fsm)
Definition: ppp.h:238
uint32_t nack_loops
Definition: ppp.h:305
const struct ppp_my_option_info * info
Definition: ppp.h:289
uint16_t protocol
Definition: ppp.h:314
void(* down)(struct ppp_fsm *fsm)
Definition: ppp.h:264
uint32_t retransmits
Definition: ppp.h:302
uint8_t ack_received
Definition: ppp.h:329
int(* config_info_ack)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length)
Definition: ppp.h:230
uint32_t flags
Definition: ppp.h:299
uint32_t recv_nack_loops
Definition: ppp.h:308
struct ppp_fsm::@177 my_options
struct ppp_my_option_data * data
Definition: ppp.h:292
size_t count
Definition: ppp.h:295
uint8_t id
Definition: ppp.h:323
uint8_t req_id
Definition: ppp.h:326
int(* config_info_rej)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length)
Definition: ppp.h:253
const char * name
Definition: ppp.h:320
void(* up)(struct ppp_fsm *fsm)
Definition: ppp.h:261
enum net_verdict(* proto_extension)(struct ppp_fsm *fsm, enum ppp_packet_type code, uint8_t id, struct net_pkt *pkt)
Definition: ppp.h:281
int(* config_info_req)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length, struct net_pkt *ret_pkt)
Definition: ppp.h:247
enum ppp_state state
Definition: ppp.h:317
int(* config_info_nack)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length, bool rejected)
Definition: ppp.h:241
void(* starting)(struct ppp_fsm *fsm)
Definition: ppp.h:267
struct ppp_fsm::@176 cb
struct k_work_delayable timer
Definition: ppp.h:226
void(* retransmit)(struct ppp_fsm *fsm)
Definition: ppp.h:276
void(* proto_reject)(struct ppp_fsm *fsm)
Definition: ppp.h:273
void(* finished)(struct ppp_fsm *fsm)
Definition: ppp.h:270
void(* config_info_reset)(struct ppp_fsm *fsm)
Definition: ppp.h:258
Definition: ppp.h:335
uint32_t flags
Definition: ppp.h:336
Shell instance internals.
Definition: shell.h:720
static const intptr_t user_data[5]
Definition: main.c:590