Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
12#ifndef ZEPHYR_INCLUDE_NET_PPP_H_
13#define ZEPHYR_INCLUDE_NET_PPP_H_
14
15#include <zephyr/net/net_if.h>
16#include <zephyr/net/net_pkt.h>
18#include <zephyr/net/net_mgmt.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
32#define PPP_MRU CONFIG_NET_PPP_MTU_MRU
33
35#define PPP_MTU PPP_MRU
36
38#define PPP_MAX_TERMINATE_REASON_LEN 32
39
41#define PPP_INTERFACE_IDENTIFIER_LEN 8
42
44struct ppp_api {
49 struct net_if_api iface_api;
50
52 int (*start)(const struct device *dev);
53
55 int (*stop)(const struct device *dev);
56
58 int (*send)(const struct device *dev, struct net_pkt *pkt);
59
60#if defined(CONFIG_NET_STATISTICS_PPP)
65 struct net_stats_ppp *(*get_stats)(const struct device *dev);
66#endif
67};
68
69/* Make sure that the network interface API is properly setup inside
70 * PPP API struct (it is the first one).
71 */
72BUILD_ASSERT(offsetof(struct ppp_api, iface_api) == 0);
73
80 PPP_IP = 0x0021,
81 PPP_IPV6 = 0x0057,
82 PPP_IPCP = 0x8021,
83 PPP_ECP = 0x8053,
84 PPP_IPV6CP = 0x8057,
85 PPP_CCP = 0x80FD,
86 PPP_LCP = 0xc021,
87 PPP_PAP = 0xc023,
88 PPP_CHAP = 0xc223,
89 PPP_EAP = 0xc227,
90};
91
108};
109
115enum ppp_state {
116 PPP_INITIAL,
117 PPP_STARTING,
118 PPP_CLOSED,
119 PPP_STOPPED,
120 PPP_CLOSING,
121 PPP_STOPPING,
122 PPP_REQUEST_SENT,
123 PPP_ACK_RECEIVED,
124 PPP_ACK_SENT,
125 PPP_OPENED
126};
127
131enum ppp_packet_type {
132 PPP_CONFIGURE_REQ = 1,
133 PPP_CONFIGURE_ACK = 2,
134 PPP_CONFIGURE_NACK = 3,
135 PPP_CONFIGURE_REJ = 4,
136 PPP_TERMINATE_REQ = 5,
137 PPP_TERMINATE_ACK = 6,
138 PPP_CODE_REJ = 7,
139 PPP_PROTOCOL_REJ = 8,
140 PPP_ECHO_REQ = 9,
141 PPP_ECHO_REPLY = 10,
142 PPP_DISCARD_REQ = 11
143};
144
153
156
159
162
165
168
171
174} __packed;
175
182
185
188
191
192 /* RFC 1877 */
193
196
199
202
205} __packed;
206
213
216} __packed;
217
226typedef void (*net_ppp_lcp_echo_reply_cb_t)(void *user_data,
227 size_t user_data_len);
228
229struct ppp_my_option_data;
230struct ppp_my_option_info;
231
235struct ppp_fsm {
238
240 struct {
242 int (*config_info_ack)(struct ppp_fsm *fsm,
243 struct net_pkt *pkt,
244 uint16_t length);
245
247 struct net_pkt *(*config_info_add)(struct ppp_fsm *fsm);
248
250 int (*config_info_len)(struct ppp_fsm *fsm);
251
253 int (*config_info_nack)(struct ppp_fsm *fsm,
254 struct net_pkt *pkt,
255 uint16_t length,
256 bool rejected);
257
259 int (*config_info_req)(struct ppp_fsm *fsm,
260 struct net_pkt *pkt,
261 uint16_t length,
262 struct net_pkt *ret_pkt);
263
265 int (*config_info_rej)(struct ppp_fsm *fsm,
266 struct net_pkt *pkt,
267 uint16_t length);
268
270 void (*config_info_reset)(struct ppp_fsm *fsm);
271
273 void (*up)(struct ppp_fsm *fsm);
274
276 void (*down)(struct ppp_fsm *fsm);
277
279 void (*starting)(struct ppp_fsm *fsm);
280
282 void (*finished)(struct ppp_fsm *fsm);
283
285 void (*proto_reject)(struct ppp_fsm *fsm);
286
288 void (*retransmit)(struct ppp_fsm *fsm);
289
293 enum net_verdict (*proto_extension)(struct ppp_fsm *fsm,
294 enum ppp_packet_type code,
295 uint8_t id,
296 struct net_pkt *pkt);
297 } cb;
298
300 struct {
302 const struct ppp_my_option_info *info;
303
305 struct ppp_my_option_data *data;
306
308 size_t count;
310
313;
316
319
322
325
328
330 enum ppp_state state;
331
333 const char *name;
334
337
340
343};
344
347#define PPP_MY_OPTION_ACKED BIT(0)
348#define PPP_MY_OPTION_REJECTED BIT(1)
349
350struct ppp_my_option_data {
352};
353
354#define IPCP_NUM_MY_OPTIONS 3
355#define IPV6CP_NUM_MY_OPTIONS 1
356
357enum ppp_flags {
358 PPP_CARRIER_UP,
359};
360
367
370
373
376};
377
378#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
379#define LCP_NUM_MY_OPTIONS 1
380#endif
381
386
389
392};
393
398};
399
406
409
411 struct {
413 struct ppp_fsm fsm;
414
416 struct lcp_options my_options;
417
419 struct lcp_options peer_options;
420
423#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
424 struct ppp_my_option_data my_options_data[LCP_NUM_MY_OPTIONS];
425#endif
427
428#if defined(CONFIG_NET_IPV4)
430 struct {
432 struct ppp_fsm fsm;
433
435 struct ipcp_options my_options;
436
438 struct ipcp_options peer_options;
439
441 struct ppp_my_option_data my_options_data[IPCP_NUM_MY_OPTIONS];
442 } ipcp;
443#endif
444
445#if defined(CONFIG_NET_IPV6)
447 struct {
449 struct ppp_fsm fsm;
450
452 struct ipv6cp_options my_options;
453
455 struct ipv6cp_options peer_options;
456
458 struct ppp_my_option_data my_options_data[IPV6CP_NUM_MY_OPTIONS];
459 } ipv6cp;
460#endif
461
462#if defined(CONFIG_NET_L2_PPP_PAP)
464 struct {
466 struct ppp_fsm fsm;
467 } pap;
468#endif
469
470#if defined(CONFIG_NET_SHELL)
472 struct {
474 struct {
478
480 void *user_data;
481
483 size_t user_data_len;
484 } echo_reply;
485
487 struct k_sem wait_echo_reply;
488
490 uint32_t echo_req_data;
491
493 uint32_t echo_reply_data;
494 } shell;
495#endif
496
498 struct net_if *iface;
499
502
505
508
510 struct k_sem wait_ppp_link_down;
511
514
517
520
523
526
529
532
535
538
541
544
547};
548
554void net_ppp_init(struct net_if *iface);
555
556/* Management API for PPP */
557
560#define PPP_L2_CTX_TYPE struct ppp_context
561
562#define _NET_PPP_LAYER NET_MGMT_LAYER_L2
563#define _NET_PPP_CODE 0x209
564#define _NET_PPP_BASE (NET_MGMT_IFACE_BIT | \
565 NET_MGMT_LAYER(_NET_PPP_LAYER) | \
566 NET_MGMT_LAYER_CODE(_NET_PPP_CODE))
567#define _NET_PPP_EVENT (_NET_PPP_BASE | NET_MGMT_EVENT_BIT)
568
569enum net_event_ppp_cmd {
570 NET_EVENT_PPP_CMD_CARRIER_ON = 1,
571 NET_EVENT_PPP_CMD_CARRIER_OFF,
572 NET_EVENT_PPP_CMD_PHASE_RUNNING,
573 NET_EVENT_PPP_CMD_PHASE_DEAD,
574};
575
576struct net_if;
577
581#define NET_EVENT_PPP_CARRIER_ON \
582 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_ON)
583
585#define NET_EVENT_PPP_CARRIER_OFF \
586 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_OFF)
587
589#define NET_EVENT_PPP_PHASE_RUNNING \
590 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_RUNNING)
591
593#define NET_EVENT_PPP_PHASE_DEAD \
594 (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_DEAD)
595
601#if defined(CONFIG_NET_L2_PPP_MGMT)
602void ppp_mgmt_raise_carrier_on_event(struct net_if *iface);
603#else
604static inline void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
605{
606 ARG_UNUSED(iface);
607}
608#endif
609
615#if defined(CONFIG_NET_L2_PPP_MGMT)
616void ppp_mgmt_raise_carrier_off_event(struct net_if *iface);
617#else
618static inline void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
619{
620 ARG_UNUSED(iface);
621}
622#endif
623
629#if defined(CONFIG_NET_L2_PPP_MGMT)
631#else
632static inline void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
633{
634 ARG_UNUSED(iface);
635}
636#endif
637
643#if defined(CONFIG_NET_L2_PPP_MGMT)
644void ppp_mgmt_raise_phase_dead_event(struct net_if *iface);
645#else
646static inline void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
647{
648 ARG_UNUSED(iface);
649}
650#endif
651
662#if defined(CONFIG_NET_L2_PPP)
663int net_ppp_ping(int idx, int32_t timeout);
664#else
665static inline int net_ppp_ping(int idx, int32_t timeout)
666{
667 ARG_UNUSED(idx);
668 ARG_UNUSED(timeout);
669
670 return -ENOTSUP;
671}
672#endif
673
682#if defined(CONFIG_NET_L2_PPP) && defined(CONFIG_NET_SHELL)
683struct ppp_context *net_ppp_context_get(int idx);
684#else
685static inline struct ppp_context *net_ppp_context_get(int idx)
686{
687 ARG_UNUSED(idx);
688
689 return NULL;
690}
691#endif
692
693#ifdef __cplusplus
694}
695#endif
696
701#endif /* ZEPHYR_INCLUDE_NET_PPP_H_ */
long atomic_t
Definition: atomic_types.h:15
net_verdict
Net Verdict.
Definition: net_core.h:100
net_l2_flags
L2 flags.
Definition: net_l2.h:34
ipcp_option_type
IPCP option types from RFC 1332.
Definition: ppp.h:179
static void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
Raise CARRIER_ON event when PPP is connected.
Definition: ppp.h:604
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:226
ppp_phase
PPP phases.
Definition: ppp.h:95
#define PPP_MAX_TERMINATE_REASON_LEN
Max length of terminate description string.
Definition: ppp.h:38
static struct ppp_context * net_ppp_context_get(int idx)
Get PPP context information.
Definition: ppp.h:685
static void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
Raise PHASE_RUNNING event when PPP reaching RUNNING phase.
Definition: ppp.h:632
ppp_protocol_type
PPP protocol types.
Definition: ppp.h:79
static int net_ppp_ping(int idx, int32_t timeout)
Send PPP Echo-Request to peer.
Definition: ppp.h:665
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:41
lcp_option_type
LCP option types from RFC 1661 ch.
Definition: ppp.h:150
static void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
Raise PHASE_DEAD event when PPP reaching DEAD phase.
Definition: ppp.h:646
static void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
Raise CARRIER_OFF event when PPP is disconnected.
Definition: ppp.h:618
ipv6cp_option_type
IPV6CP option types from RFC 5072.
Definition: ppp.h:210
@ IPCP_OPTION_IP_ADDRESS
IP Address.
Definition: ppp.h:190
@ IPCP_OPTION_DNS2
Secondary DNS Server Address.
Definition: ppp.h:201
@ IPCP_OPTION_IP_COMP_PROTO
IP Compression Protocol.
Definition: ppp.h:187
@ IPCP_OPTION_NBNS2
Secondary NBNS Server Address.
Definition: ppp.h:204
@ IPCP_OPTION_RESERVED
Reserved IPCP option value (do not use)
Definition: ppp.h:181
@ IPCP_OPTION_NBNS1
Primary NBNS Server Address.
Definition: ppp.h:198
@ IPCP_OPTION_IP_ADDRESSES
IP Addresses.
Definition: ppp.h:184
@ IPCP_OPTION_DNS1
Primary DNS Server Address.
Definition: ppp.h:195
@ PPP_AUTH
Link authentication with peer.
Definition: ppp.h:101
@ PPP_RUNNING
Network running.
Definition: ppp.h:105
@ PPP_NETWORK
Network connection establishment.
Definition: ppp.h:103
@ PPP_ESTABLISH
Link is being established.
Definition: ppp.h:99
@ PPP_DEAD
Physical-layer not ready.
Definition: ppp.h:97
@ PPP_TERMINATE
Link termination.
Definition: ppp.h:107
@ PPP_IPV6
RFC 5072.
Definition: ppp.h:81
@ PPP_IP
RFC 1332.
Definition: ppp.h:80
@ PPP_CHAP
RFC 1334.
Definition: ppp.h:88
@ PPP_LCP
RFC 1661.
Definition: ppp.h:86
@ PPP_IPCP
RFC 1332.
Definition: ppp.h:82
@ PPP_ECP
RFC 1968.
Definition: ppp.h:83
@ PPP_CCP
RFC 1962.
Definition: ppp.h:85
@ PPP_EAP
RFC 2284.
Definition: ppp.h:89
@ PPP_IPV6CP
RFC 5072.
Definition: ppp.h:84
@ PPP_PAP
RFC 1334.
Definition: ppp.h:87
@ LCP_OPTION_ASYNC_CTRL_CHAR_MAP
Async-Control-Character-Map.
Definition: ppp.h:158
@ LCP_OPTION_ADDR_CTRL_COMPRESS
Address-and-Control-Field-Compression.
Definition: ppp.h:173
@ LCP_OPTION_QUALITY_PROTO
Quality-Protocol.
Definition: ppp.h:164
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition: ppp.h:167
@ LCP_OPTION_RESERVED
Reserved option value (do not use)
Definition: ppp.h:152
@ LCP_OPTION_PROTO_COMPRESS
Protocol-Field-Compression.
Definition: ppp.h:170
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition: ppp.h:155
@ LCP_OPTION_AUTH_PROTO
Authentication-Protocol.
Definition: ppp.h:161
@ IPV6CP_OPTION_INTERFACE_IDENTIFIER
Interface identifier.
Definition: ppp.h:215
@ IPV6CP_OPTION_RESERVED
Reserved IPV6CP option value (do not use)
Definition: ppp.h:212
#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.
flags
Definition: parser.h:96
__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:403
IPv4 address struct.
Definition: net_ip.h:151
IPv4 control protocol options.
Definition: ppp.h:383
struct in_addr address
IPv4 address.
Definition: ppp.h:385
struct in_addr dns2_address
Secondary DNS server address.
Definition: ppp.h:391
struct in_addr dns1_address
Primary DNS server address.
Definition: ppp.h:388
IPv6 control protocol options.
Definition: ppp.h:395
uint8_t iid[8]
Interface identifier.
Definition: ppp.h:397
A structure used to submit work after a delay.
Definition: kernel.h:3903
Link control protocol options.
Definition: ppp.h:364
uint16_t mru
Maximum Receive Unit value.
Definition: ppp.h:372
uint32_t async_map
Async char map.
Definition: ppp.h:369
uint16_t auth_proto
Which authentication protocol was negotiated (0 means none)
Definition: ppp.h:375
uint32_t magic
Magic number.
Definition: ppp.h:366
Network Interface structure.
Definition: net_if.h:678
Network Management event callback structure Used to register a callback into the network management e...
Definition: net_mgmt.h:143
Network packet.
Definition: net_pkt.h:67
All PPP specific statistics.
Definition: net_stats.h:575
PPP L2 API.
Definition: ppp.h:44
int(* stop)(const struct device *dev)
Stop the device.
Definition: ppp.h:55
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition: ppp.h:58
int(* start)(const struct device *dev)
Start the device.
Definition: ppp.h:52
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:49
PPP L2 context specific to certain network interface.
Definition: ppp.h:401
struct ppp_context::@356 lcp
LCP options.
struct net_mgmt_event_callback mgmt_evt_cb
Network management callback structure.
Definition: ppp.h:501
struct k_sem wait_ppp_link_terminated
Signal when PPP link is terminated.
Definition: ppp.h:507
enum net_l2_flags ppp_l2_flags
This tells what features the PPP supports.
Definition: ppp.h:513
int network_protos_open
This tells how many network protocols are open.
Definition: ppp.h:516
struct net_if * iface
Network interface related to this PPP connection.
Definition: ppp.h:498
uint16_t is_ready_to_serve
Is PPP ready to receive packets.
Definition: ppp.h:522
uint32_t magic
Magic-Number value.
Definition: ppp.h:422
uint16_t is_pap_up
PAP status (up / down)
Definition: ppp.h:543
struct k_work_delayable startup
PPP startup worker.
Definition: ppp.h:408
enum ppp_phase phase
Current phase of PPP link.
Definition: ppp.h:504
atomic_t flags
Flags representing PPP state, which are accessed from multiple threads.
Definition: ppp.h:405
uint16_t is_ipv6cp_up
IPV6CP status (up / down)
Definition: ppp.h:537
uint16_t is_ipcp_open
IPCP open status (open / closed)
Definition: ppp.h:534
uint16_t is_enabled
Is PPP L2 enabled or not.
Definition: ppp.h:525
uint16_t is_pap_open
PAP open status (open / closed)
Definition: ppp.h:546
uint16_t is_ipcp_up
IPCP status (up / down)
Definition: ppp.h:531
int network_protos_up
This tells how many network protocols are up.
Definition: ppp.h:519
uint16_t is_ipv6cp_open
IPV6CP open status (open / closed)
Definition: ppp.h:540
uint16_t is_enable_done
PPP enable pending.
Definition: ppp.h:528
struct k_sem wait_ppp_link_down
Signal when PPP link is down.
Definition: ppp.h:510
Generic PPP Finite State Machine.
Definition: ppp.h:235
char terminate_reason[32]
Reason for closing protocol.
Definition: ppp.h:324
uint32_t nack_loops
Number of NACK loops since last ACK.
Definition: ppp.h:318
const struct ppp_my_option_info * info
Options information.
Definition: ppp.h:302
uint16_t protocol
PPP protocol number for this FSM.
Definition: ppp.h:327
struct ppp_fsm::@355 my_options
My options.
uint32_t retransmits
Number of re-transmissions left.
Definition: ppp.h:315
uint8_t ack_received
Have received valid Ack, Nack or Reject to a Request.
Definition: ppp.h:342
uint32_t flags
Option bits.
Definition: ppp.h:312
uint32_t recv_nack_loops
Number of NACKs received.
Definition: ppp.h:321
struct ppp_fsm::@354 cb
FSM callbacks.
struct ppp_my_option_data * data
Options negotiation data.
Definition: ppp.h:305
size_t count
Number of negotiated options.
Definition: ppp.h:308
uint8_t id
Current id.
Definition: ppp.h:336
uint8_t req_id
Current request id.
Definition: ppp.h:339
const char * name
Protocol/layer name of this FSM (for debugging)
Definition: ppp.h:333
enum ppp_state state
Current state of PPP link.
Definition: ppp.h:330
struct k_work_delayable timer
Timeout timer.
Definition: ppp.h:237
Shell instance internals.
Definition: shell.h:890