Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 <zephyr/net/net_if.h>
12#include <zephyr/net/net_pkt.h>
14#include <zephyr/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
215typedef void (*net_ppp_lcp_echo_reply_cb_t)(void *user_data,
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
258 void (*config_info_reset)(struct ppp_fsm *fsm);
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
387 struct {
389 struct ppp_fsm fsm;
390
392 struct lcp_options my_options;
393
395 struct lcp_options peer_options;
396
399#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
400 struct ppp_my_option_data my_options_data[LCP_NUM_MY_OPTIONS];
401#endif
403
404#if defined(CONFIG_NET_IPV4)
405 struct {
407 struct ppp_fsm fsm;
408
410 struct ipcp_options my_options;
411
413 struct ipcp_options peer_options;
414
416 struct ppp_my_option_data my_options_data[IPCP_NUM_MY_OPTIONS];
417 } ipcp;
418#endif
419
420#if defined(CONFIG_NET_IPV6)
421 struct {
423 struct ppp_fsm fsm;
424
426 struct ipv6cp_options my_options;
427
429 struct ipv6cp_options peer_options;
430
432 struct ppp_my_option_data my_options_data[IPV6CP_NUM_MY_OPTIONS];
433 } ipv6cp;
434#endif
435
436#if defined(CONFIG_NET_L2_PPP_PAP)
437 struct {
439 struct ppp_fsm fsm;
440 } pap;
441#endif
442
443#if defined(CONFIG_NET_SHELL)
444 struct {
445 struct {
449
451 void *user_data;
452
454 size_t user_data_len;
455 } echo_reply;
456
458 struct k_sem wait_echo_reply;
459
461 uint32_t echo_req_data;
462
464 uint32_t echo_reply_data;
465 } shell;
466#endif
467
469 struct net_if *iface;
470
473
476
479
482
485
488
491
494
497
500
503
506
509
512};
513
519void net_ppp_init(struct net_if *iface);
520
521/* Management API for PPP */
522
525#define PPP_L2_CTX_TYPE struct ppp_context
526
527#define _NET_PPP_LAYER NET_MGMT_LAYER_L2
528#define _NET_PPP_CODE 0x209
529#define _NET_PPP_BASE (NET_MGMT_IFACE_BIT | \
530 NET_MGMT_LAYER(_NET_PPP_LAYER) | \
531 NET_MGMT_LAYER_CODE(_NET_PPP_CODE))
532#define _NET_PPP_EVENT (_NET_PPP_BASE | NET_MGMT_EVENT_BIT)
533
534enum net_event_ppp_cmd {
535 NET_EVENT_PPP_CMD_CARRIER_ON = 1,
536 NET_EVENT_PPP_CMD_CARRIER_OFF,
537 NET_EVENT_PPP_CMD_PHASE_RUNNING,
538 NET_EVENT_PPP_CMD_PHASE_DEAD,
539};
540
541#define NET_EVENT_PPP_CARRIER_ON \
542 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_ON)
543
544#define NET_EVENT_PPP_CARRIER_OFF \
545 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_OFF)
546
547#define NET_EVENT_PPP_PHASE_RUNNING \
548 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_RUNNING)
549
550#define NET_EVENT_PPP_PHASE_DEAD \
551 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_DEAD)
552
553struct net_if;
554
562#if defined(CONFIG_NET_L2_PPP_MGMT)
563void ppp_mgmt_raise_carrier_on_event(struct net_if *iface);
564#else
565static inline void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
566{
567 ARG_UNUSED(iface);
568}
569#endif
570
576#if defined(CONFIG_NET_L2_PPP_MGMT)
577void ppp_mgmt_raise_carrier_off_event(struct net_if *iface);
578#else
579static inline void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
580{
581 ARG_UNUSED(iface);
582}
583#endif
584
590#if defined(CONFIG_NET_L2_PPP_MGMT)
592#else
593static inline void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
594{
595 ARG_UNUSED(iface);
596}
597#endif
598
604#if defined(CONFIG_NET_L2_PPP_MGMT)
605void ppp_mgmt_raise_phase_dead_event(struct net_if *iface);
606#else
607static inline void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
608{
609 ARG_UNUSED(iface);
610}
611#endif
612
623#if defined(CONFIG_NET_L2_PPP)
624int net_ppp_ping(int idx, int32_t timeout);
625#else
626static inline int net_ppp_ping(int idx, int32_t timeout)
627{
628 ARG_UNUSED(idx);
629 ARG_UNUSED(timeout);
630
631 return -ENOTSUP;
632}
633#endif
634
643#if defined(CONFIG_NET_L2_PPP) && defined(CONFIG_NET_SHELL)
644struct ppp_context *net_ppp_context_get(int idx);
645#else
646static inline struct ppp_context *net_ppp_context_get(int idx)
647{
648 ARG_UNUSED(idx);
649
650 return NULL;
651}
652#endif
653
654#ifdef __cplusplus
655}
656#endif
657
662#endif /* ZEPHYR_INCLUDE_NET_PPP_H_ */
long atomic_t
Definition: atomic.h:22
net_verdict
Net Verdict.
Definition: net_core.h:98
net_l2_flags
L2 flags.
Definition: net_l2.h:34
ipcp_option_type
IPCP option types from RFC 1332.
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:565
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
PPP phases.
Definition: ppp.h:91
#define PPP_MAX_TERMINATE_REASON_LEN
Max length of terminate description string.
Definition: ppp.h:34
ppp_packet_type
PPP protocol operations from RFC 1661.
Definition: ppp.h:125
ppp_flags
Definition: ppp.h:373
static struct ppp_context * net_ppp_context_get(int idx)
Get PPP context information.
Definition: ppp.h:646
#define IPV6CP_NUM_MY_OPTIONS
Definition: ppp.h:371
ppp_state
PPP states, RFC 1661 ch.
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:593
ppp_protocol_type
PPP protocol types.
Definition: ppp.h:75
static int net_ppp_ping(int idx, int32_t timeout)
Send PPP Echo-Request to peer.
Definition: ppp.h:626
void net_ppp_init(struct net_if *iface)
Initialize PPP L2 stack for a given interface.
#define PPP_INTERFACE_IDENTIFIER_LEN
Length of network interface identifier.
Definition: ppp.h:37
lcp_option_type
LCP option types from RFC 1661 ch.
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:607
static void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
Raise CARRIER_OFF event when PPP is disconnected.
Definition: ppp.h:579
#define IPCP_NUM_MY_OPTIONS
Definition: ppp.h:364
ipv6cp_option_type
IPV6CP option types from RFC 5072.
Definition: ppp.h:200
@ IPCP_OPTION_IP_ADDRESS
IP Address.
Definition: ppp.h:180
@ IPCP_OPTION_DNS2
Secondary DNS Server Address.
Definition: ppp.h:191
@ IPCP_OPTION_IP_COMP_PROTO
IP Compression Protocol.
Definition: ppp.h:177
@ IPCP_OPTION_NBNS2
Secondary NBNS Server Address.
Definition: ppp.h:194
@ IPCP_OPTION_RESERVED
Definition: ppp.h:171
@ IPCP_OPTION_NBNS1
Primary NBNS Server Address.
Definition: ppp.h:188
@ IPCP_OPTION_IP_ADDRESSES
IP Addresses.
Definition: ppp.h:174
@ IPCP_OPTION_DNS1
Primary DNS Server Address.
Definition: ppp.h:185
@ PPP_AUTH
Link authentication with peer.
Definition: ppp.h:97
@ PPP_RUNNING
Network running.
Definition: ppp.h:101
@ PPP_NETWORK
Network connection establishment.
Definition: ppp.h:99
@ PPP_ESTABLISH
Link is being established.
Definition: ppp.h:95
@ PPP_DEAD
Physical-layer not ready.
Definition: ppp.h:93
@ PPP_TERMINATE
Link termination.
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
RFC 5072.
Definition: ppp.h:77
@ PPP_IP
RFC 1332.
Definition: ppp.h:76
@ PPP_CHAP
RFC 1334.
Definition: ppp.h:84
@ PPP_LCP
RFC 1661.
Definition: ppp.h:82
@ PPP_IPCP
RFC 1332.
Definition: ppp.h:78
@ PPP_ECP
RFC 1968.
Definition: ppp.h:79
@ PPP_CCP
RFC 1962.
Definition: ppp.h:81
@ PPP_EAP
RFC 2284.
Definition: ppp.h:85
@ PPP_IPV6CP
RFC 5072.
Definition: ppp.h:80
@ PPP_PAP
RFC 1334.
Definition: ppp.h:83
@ LCP_OPTION_ASYNC_CTRL_CHAR_MAP
Async-Control-Character-Map.
Definition: ppp.h:149
@ LCP_OPTION_ADDR_CTRL_COMPRESS
Address-and-Control-Field-Compression.
Definition: ppp.h:164
@ LCP_OPTION_QUALITY_PROTO
Quality-Protocol.
Definition: ppp.h:155
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition: ppp.h:158
@ LCP_OPTION_RESERVED
Definition: ppp.h:143
@ LCP_OPTION_PROTO_COMPRESS
Protocol-Field-Compression.
Definition: ppp.h:161
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition: ppp.h:146
@ LCP_OPTION_AUTH_PROTO
Authentication-Protocol.
Definition: ppp.h:152
@ IPV6CP_OPTION_INTERFACE_IDENTIFIER
Interface identifier.
Definition: ppp.h:204
@ IPV6CP_OPTION_RESERVED
Definition: ppp.h:201
#define ENOTSUP
Unsupported value.
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:90
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:381
IPv4 address struct.
Definition: net_ip.h:151
Definition: ppp.h:357
struct in_addr address
IPv4 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]
Interface identifier.
Definition: ppp.h:368
A structure used to submit work after a delay.
Definition: kernel.h:3893
Definition: ppp.h:339
uint16_t mru
Maximum Receive Unit value.
Definition: ppp.h:347
uint32_t async_map
Async char map.
Definition: ppp.h:344
uint16_t auth_proto
Which authentication protocol was negotiated (0 means none)
Definition: ppp.h:350
uint32_t magic
Magic number.
Definition: ppp.h:341
Network Interface structure.
Definition: net_if.h:595
Network Management event callback structure Used to register a callback into the network management e...
Definition: net_mgmt.h:123
Network packet.
Definition: net_pkt.h:63
All PPP specific statistics.
Definition: net_stats.h:465
PPP L2 API.
Definition: ppp.h:40
int(* stop)(const struct device *dev)
Stop the device.
Definition: ppp.h:51
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition: ppp.h:54
int(* start)(const struct device *dev)
Start the device.
Definition: ppp.h:48
struct net_if_api iface_api
The net_if_api must be placed in first position in this struct so that we are compatible with network...
Definition: ppp.h:45
PPP L2 context specific to certain network interface.
Definition: ppp.h:378
struct net_mgmt_event_callback mgmt_evt_cb
Network management callback structure.
Definition: ppp.h:472
enum net_l2_flags ppp_l2_flags
This tells what features the PPP supports.
Definition: ppp.h:478
int network_protos_open
This tells how many network protocols are open.
Definition: ppp.h:481
struct net_if * iface
Network interface related to this PPP connection.
Definition: ppp.h:469
uint16_t is_ready_to_serve
Is PPP ready to receive packets.
Definition: ppp.h:487
uint32_t magic
Magic-Number value.
Definition: ppp.h:398
uint16_t is_pap_up
PAP status (up / down)
Definition: ppp.h:508
struct k_work_delayable startup
PPP startup worker.
Definition: ppp.h:385
enum ppp_phase phase
Current phase of PPP link.
Definition: ppp.h:475
atomic_t flags
Flags representing PPP state, which are accessed from multiple threads.
Definition: ppp.h:382
uint16_t is_ipv6cp_up
IPV6CP status (up / down)
Definition: ppp.h:502
uint16_t is_ipcp_open
IPCP open status (open / closed)
Definition: ppp.h:499
uint16_t is_enabled
Is PPP L2 enabled or not.
Definition: ppp.h:490
uint16_t is_pap_open
PAP open status (open / closed)
Definition: ppp.h:511
uint16_t is_ipcp_up
IPCP status (up / down)
Definition: ppp.h:496
int network_protos_up
This tells how many network protocols are up.
Definition: ppp.h:484
uint16_t is_ipv6cp_open
IPV6CP open status (open / closed)
Definition: ppp.h:505
uint16_t is_enable_done
PPP enable pending.
Definition: ppp.h:493
struct ppp_context::@313 lcp
Generic PPP Finite State Machine.
Definition: ppp.h:224
char terminate_reason[32]
Reason for closing protocol.
Definition: ppp.h:311
uint32_t nack_loops
Number of NACK loops since last ACK.
Definition: ppp.h:305
const struct ppp_my_option_info * info
Options information.
Definition: ppp.h:289
uint16_t protocol
PPP protocol number for this FSM.
Definition: ppp.h:314
uint32_t retransmits
Number of re-transmissions left.
Definition: ppp.h:302
uint8_t ack_received
Have received valid Ack, Nack or Reject to a Request.
Definition: ppp.h:329
uint32_t flags
Option bits.
Definition: ppp.h:299
uint32_t recv_nack_loops
Number of NACKs received.
Definition: ppp.h:308
struct ppp_my_option_data * data
Options negotiation data.
Definition: ppp.h:292
struct ppp_fsm::@311 cb
size_t count
Number of negotiated options.
Definition: ppp.h:295
uint8_t id
Current id.
Definition: ppp.h:323
uint8_t req_id
Current request id.
Definition: ppp.h:326
const char * name
Protocol/layer name of this FSM (for debugging)
Definition: ppp.h:320
struct ppp_fsm::@312 my_options
enum ppp_state state
Current state of PPP link.
Definition: ppp.h:317
struct k_work_delayable timer
Timeout timer.
Definition: ppp.h:226
Definition: ppp.h:335
uint32_t flags
Definition: ppp.h:336
Shell instance internals.
Definition: shell.h:848