Zephyr Project API 4.2.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
34#define PPP_MRU CONFIG_NET_PPP_MTU_MRU
35
37#define PPP_MTU PPP_MRU
38
40#define PPP_MAX_TERMINATE_REASON_LEN 32
41
43#define PPP_INTERFACE_IDENTIFIER_LEN 8
44
46struct ppp_api {
51 struct net_if_api iface_api;
52
54 int (*start)(const struct device *dev);
55
57 int (*stop)(const struct device *dev);
58
60 int (*send)(const struct device *dev, struct net_pkt *pkt);
61
62#if defined(CONFIG_NET_STATISTICS_PPP)
67 struct net_stats_ppp *(*get_stats)(const struct device *dev);
68#endif
69};
70
71/* Make sure that the network interface API is properly setup inside
72 * PPP API struct (it is the first one).
73 */
74BUILD_ASSERT(offsetof(struct ppp_api, iface_api) == 0);
75
82 PPP_IP = 0x0021,
83 PPP_IPV6 = 0x0057,
84 PPP_IPCP = 0x8021,
85 PPP_ECP = 0x8053,
86 PPP_IPV6CP = 0x8057,
87 PPP_CCP = 0x80FD,
88 PPP_LCP = 0xc021,
89 PPP_PAP = 0xc023,
90 PPP_CHAP = 0xc223,
91 PPP_EAP = 0xc227,
92};
93
111
117enum ppp_state {
118 PPP_INITIAL,
119 PPP_STARTING,
120 PPP_CLOSED,
121 PPP_STOPPED,
122 PPP_CLOSING,
123 PPP_STOPPING,
124 PPP_REQUEST_SENT,
125 PPP_ACK_RECEIVED,
126 PPP_ACK_SENT,
127 PPP_OPENED
128};
129
133enum ppp_packet_type {
134 PPP_CONFIGURE_REQ = 1,
135 PPP_CONFIGURE_ACK = 2,
136 PPP_CONFIGURE_NACK = 3,
137 PPP_CONFIGURE_REJ = 4,
138 PPP_TERMINATE_REQ = 5,
139 PPP_TERMINATE_ACK = 6,
140 PPP_CODE_REJ = 7,
141 PPP_PROTOCOL_REJ = 8,
142 PPP_ECHO_REQ = 9,
143 PPP_ECHO_REPLY = 10,
144 PPP_DISCARD_REQ = 11
145};
146
177
208
219
228typedef void (*net_ppp_lcp_echo_reply_cb_t)(void *user_data,
229 size_t user_data_len);
230
231struct ppp_my_option_data;
232struct ppp_my_option_info;
233
237struct ppp_fsm {
240
242 struct {
244 int (*config_info_ack)(struct ppp_fsm *fsm,
245 struct net_pkt *pkt,
246 uint16_t length);
247
249 struct net_pkt *(*config_info_add)(struct ppp_fsm *fsm);
250
252 int (*config_info_len)(struct ppp_fsm *fsm);
253
255 int (*config_info_nack)(struct ppp_fsm *fsm,
256 struct net_pkt *pkt,
257 uint16_t length,
258 bool rejected);
259
261 int (*config_info_req)(struct ppp_fsm *fsm,
262 struct net_pkt *pkt,
263 uint16_t length,
264 struct net_pkt *ret_pkt);
265
267 int (*config_info_rej)(struct ppp_fsm *fsm,
268 struct net_pkt *pkt,
269 uint16_t length);
270
272 void (*config_info_reset)(struct ppp_fsm *fsm);
273
275 void (*up)(struct ppp_fsm *fsm);
276
278 void (*down)(struct ppp_fsm *fsm);
279
281 void (*starting)(struct ppp_fsm *fsm);
282
284 void (*finished)(struct ppp_fsm *fsm);
285
287 void (*proto_reject)(struct ppp_fsm *fsm);
288
290 void (*retransmit)(struct ppp_fsm *fsm);
291
295 enum net_verdict (*proto_extension)(struct ppp_fsm *fsm,
296 enum ppp_packet_type code,
297 uint8_t id,
298 struct net_pkt *pkt);
299 } cb;
300
302 struct {
304 const struct ppp_my_option_info *info;
305
307 struct ppp_my_option_data *data;
308
310 size_t count;
312
315
;
318
321
324
327
330
332 enum ppp_state state;
333
335 const char *name;
336
339
342
345};
346
349#define PPP_MY_OPTION_ACKED BIT(0)
350#define PPP_MY_OPTION_REJECTED BIT(1)
351
352struct ppp_my_option_data {
354};
355
356#if defined(CONFIG_NET_L2_PPP_OPTION_DNS_USE)
357#define IPCP_NUM_MY_OPTIONS 3
358#else
359#define IPCP_NUM_MY_OPTIONS 1
360#endif
361#define IPV6CP_NUM_MY_OPTIONS 1
362
363enum ppp_flags {
364 PPP_CARRIER_UP,
365};
366
383
384#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
385#define LCP_NUM_MY_OPTIONS 2
386#else
387#define LCP_NUM_MY_OPTIONS 1
388#endif
389
394
397
400};
401
407
414
417
419 struct {
421 struct ppp_fsm fsm;
422
424 struct lcp_options my_options;
425
427 struct lcp_options peer_options;
428
431
433 struct ppp_my_option_data my_options_data[LCP_NUM_MY_OPTIONS];
435
436#if defined(CONFIG_NET_IPV4)
438 struct {
440 struct ppp_fsm fsm;
441
443 struct ipcp_options my_options;
444
446 struct ipcp_options peer_options;
447
449 struct ppp_my_option_data my_options_data[IPCP_NUM_MY_OPTIONS];
450 } ipcp;
451#endif
452
453#if defined(CONFIG_NET_IPV6)
455 struct {
457 struct ppp_fsm fsm;
458
460 struct ipv6cp_options my_options;
461
463 struct ipv6cp_options peer_options;
464
466 struct ppp_my_option_data my_options_data[IPV6CP_NUM_MY_OPTIONS];
467 } ipv6cp;
468#endif
469
470#if defined(CONFIG_NET_L2_PPP_PAP)
472 struct {
474 struct ppp_fsm fsm;
475 } pap;
476#endif
477
478#if defined(CONFIG_NET_SHELL)
480 struct {
482 struct {
486
488 void *user_data;
489
491 size_t user_data_len;
492 } echo_reply;
493
495 struct k_sem wait_echo_reply;
496
498 uint32_t echo_req_data;
499
501 uint32_t echo_reply_data;
502 } shell;
503#endif
504
506 struct net_if *iface;
507
510
513
516
519
522
525
528
531
534
537
540
543
546
549
552
555};
556
562void net_ppp_init(struct net_if *iface);
563
564/* Management API for PPP */
565
568#define PPP_L2_CTX_TYPE struct ppp_context
569
570#define NET_PPP_LAYER NET_MGMT_LAYER_L2
571#define NET_PPP_CODE NET_MGMT_LAYER_CODE_PPP
572#define NET_PPP_BASE (NET_MGMT_IFACE_BIT | \
573 NET_MGMT_LAYER(NET_PPP_LAYER) | \
574 NET_MGMT_LAYER_CODE(NET_PPP_CODE))
575#define NET_PPP_EVENT (NET_PPP_BASE | NET_MGMT_EVENT_BIT)
576
577enum {
578 NET_EVENT_PPP_CMD_CARRIER_ON_VAL,
579 NET_EVENT_PPP_CMD_CARRIER_OFF_VAL,
580 NET_EVENT_PPP_CMD_PHASE_RUNNING_VAL,
581 NET_EVENT_PPP_CMD_PHASE_DEAD_VAL,
582
583 NET_EVENT_PPP_CMD_MAX
584};
585
586BUILD_ASSERT(NET_EVENT_PPP_CMD_MAX <= NET_MGMT_MAX_COMMANDS,
587 "Number of events in net_event_ppp_cmd exceeds the limit");
588
589enum net_event_ppp_cmd {
590 NET_MGMT_CMD(NET_EVENT_PPP_CMD_CARRIER_ON),
591 NET_MGMT_CMD(NET_EVENT_PPP_CMD_CARRIER_OFF),
592 NET_MGMT_CMD(NET_EVENT_PPP_CMD_PHASE_RUNNING),
593 NET_MGMT_CMD(NET_EVENT_PPP_CMD_PHASE_DEAD),
594};
595
596struct net_if;
597
601#define NET_EVENT_PPP_CARRIER_ON \
602 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_ON)
603
605#define NET_EVENT_PPP_CARRIER_OFF \
606 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_OFF)
607
609#define NET_EVENT_PPP_PHASE_RUNNING \
610 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_RUNNING)
611
613#define NET_EVENT_PPP_PHASE_DEAD \
614 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_DEAD)
615
621#if defined(CONFIG_NET_L2_PPP_MGMT)
622void ppp_mgmt_raise_carrier_on_event(struct net_if *iface);
623#else
624static inline void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
625{
626 ARG_UNUSED(iface);
627}
628#endif
629
635#if defined(CONFIG_NET_L2_PPP_MGMT)
636void ppp_mgmt_raise_carrier_off_event(struct net_if *iface);
637#else
638static inline void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
639{
640 ARG_UNUSED(iface);
641}
642#endif
643
649#if defined(CONFIG_NET_L2_PPP_MGMT)
651#else
652static inline void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
653{
654 ARG_UNUSED(iface);
655}
656#endif
657
663#if defined(CONFIG_NET_L2_PPP_MGMT)
664void ppp_mgmt_raise_phase_dead_event(struct net_if *iface);
665#else
666static inline void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
667{
668 ARG_UNUSED(iface);
669}
670#endif
671
682#if defined(CONFIG_NET_L2_PPP)
683int net_ppp_ping(int idx, int32_t timeout);
684#else
685static inline int net_ppp_ping(int idx, int32_t timeout)
686{
687 ARG_UNUSED(idx);
688 ARG_UNUSED(timeout);
689
690 return -ENOTSUP;
691}
692#endif
693
702#if defined(CONFIG_NET_L2_PPP) && defined(CONFIG_NET_SHELL)
703struct ppp_context *net_ppp_context_get(int idx);
704#else
705static inline struct ppp_context *net_ppp_context_get(int idx)
706{
707 ARG_UNUSED(idx);
708
709 return NULL;
710}
711#endif
712
713#ifdef __cplusplus
714}
715#endif
716
721#endif /* ZEPHYR_INCLUDE_NET_PPP_H_ */
long atomic_t
Definition atomic_types.h:15
net_verdict
Net Verdict.
Definition net_core.h:109
net_l2_flags
L2 flags.
Definition net_l2.h:37
ipcp_option_type
IPCP option types from RFC 1332.
Definition ppp.h:181
static void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
Raise CARRIER_ON event when PPP is connected.
Definition ppp.h:624
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:228
ppp_phase
PPP phases.
Definition ppp.h:97
#define PPP_MAX_TERMINATE_REASON_LEN
Max length of terminate description string.
Definition ppp.h:40
static struct ppp_context * net_ppp_context_get(int idx)
Get PPP context information.
Definition ppp.h:705
static void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
Raise PHASE_RUNNING event when PPP reaching RUNNING phase.
Definition ppp.h:652
ppp_protocol_type
PPP protocol types.
Definition ppp.h:81
static int net_ppp_ping(int idx, int32_t timeout)
Send PPP Echo-Request to peer.
Definition ppp.h:685
#define LCP_NUM_MY_OPTIONS
Definition ppp.h:387
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:43
lcp_option_type
LCP option types from RFC 1661 ch.
Definition ppp.h:152
static void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
Raise PHASE_DEAD event when PPP reaching DEAD phase.
Definition ppp.h:666
static void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
Raise CARRIER_OFF event when PPP is disconnected.
Definition ppp.h:638
ipv6cp_option_type
IPV6CP option types from RFC 5072.
Definition ppp.h:212
@ IPCP_OPTION_IP_ADDRESS
IP Address.
Definition ppp.h:192
@ IPCP_OPTION_DNS2
Secondary DNS Server Address.
Definition ppp.h:203
@ IPCP_OPTION_IP_COMP_PROTO
IP Compression Protocol.
Definition ppp.h:189
@ IPCP_OPTION_NBNS2
Secondary NBNS Server Address.
Definition ppp.h:206
@ IPCP_OPTION_RESERVED
Reserved IPCP option value (do not use)
Definition ppp.h:183
@ IPCP_OPTION_NBNS1
Primary NBNS Server Address.
Definition ppp.h:200
@ IPCP_OPTION_IP_ADDRESSES
IP Addresses.
Definition ppp.h:186
@ IPCP_OPTION_DNS1
Primary DNS Server Address.
Definition ppp.h:197
@ PPP_AUTH
Link authentication with peer.
Definition ppp.h:103
@ PPP_RUNNING
Network running.
Definition ppp.h:107
@ PPP_NETWORK
Network connection establishment.
Definition ppp.h:105
@ PPP_ESTABLISH
Link is being established.
Definition ppp.h:101
@ PPP_DEAD
Physical-layer not ready.
Definition ppp.h:99
@ PPP_TERMINATE
Link termination.
Definition ppp.h:109
@ PPP_IPV6
RFC 5072.
Definition ppp.h:83
@ PPP_IP
RFC 1332.
Definition ppp.h:82
@ PPP_CHAP
RFC 1334.
Definition ppp.h:90
@ PPP_LCP
RFC 1661.
Definition ppp.h:88
@ PPP_IPCP
RFC 1332.
Definition ppp.h:84
@ PPP_ECP
RFC 1968.
Definition ppp.h:85
@ PPP_CCP
RFC 1962.
Definition ppp.h:87
@ PPP_EAP
RFC 2284.
Definition ppp.h:91
@ PPP_IPV6CP
RFC 5072.
Definition ppp.h:86
@ PPP_PAP
RFC 1334.
Definition ppp.h:89
@ LCP_OPTION_ASYNC_CTRL_CHAR_MAP
Async-Control-Character-Map.
Definition ppp.h:160
@ LCP_OPTION_ADDR_CTRL_COMPRESS
Address-and-Control-Field-Compression.
Definition ppp.h:175
@ LCP_OPTION_QUALITY_PROTO
Quality-Protocol.
Definition ppp.h:166
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition ppp.h:169
@ LCP_OPTION_RESERVED
Reserved option value (do not use)
Definition ppp.h:154
@ LCP_OPTION_PROTO_COMPRESS
Protocol-Field-Compression.
Definition ppp.h:172
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition ppp.h:157
@ LCP_OPTION_AUTH_PROTO
Authentication-Protocol.
Definition ppp.h:163
@ IPV6CP_OPTION_INTERFACE_IDENTIFIER
Interface identifier.
Definition ppp.h:217
@ IPV6CP_OPTION_RESERVED
Reserved IPV6CP option value (do not use)
Definition ppp.h:214
#define ENOTSUP
Unsupported value.
Definition errno.h:114
@ NET_MGMT_CMD
Scan results available.
Definition wifi_mgmt.h:367
#define NULL
Definition iar_missing_defs.h:20
Public API for network interface.
Network Management API public header.
Network packet buffer descriptor API.
Network statistics.
flags
Definition parser.h:97
__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:510
IPv4 address struct.
Definition net_ip.h:155
IPv4 control protocol options.
Definition ppp.h:391
struct in_addr address
IPv4 address.
Definition ppp.h:393
struct in_addr dns2_address
Secondary DNS server address.
Definition ppp.h:399
struct in_addr dns1_address
Primary DNS server address.
Definition ppp.h:396
IPv6 control protocol options.
Definition ppp.h:403
uint8_t iid[8]
Interface identifier.
Definition ppp.h:405
Semaphore structure.
Definition kernel.h:3275
A structure used to submit work after a delay.
Definition kernel.h:4101
Link control protocol options.
Definition ppp.h:370
uint16_t mru
Maximum Receive Unit value.
Definition ppp.h:378
uint32_t async_map
Async char map.
Definition ppp.h:375
uint16_t auth_proto
Which authentication protocol was negotiated (0 means none)
Definition ppp.h:381
uint32_t magic
Magic number.
Definition ppp.h:372
Network Interface structure.
Definition net_if.h:726
Network Management event callback structure Used to register a callback into the network management e...
Definition net_mgmt.h:163
Network packet.
Definition net_pkt.h:91
All PPP specific statistics.
Definition net_stats.h:677
PPP L2 API.
Definition ppp.h:46
int(* stop)(const struct device *dev)
Stop the device.
Definition ppp.h:57
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition ppp.h:60
int(* start)(const struct device *dev)
Start the device.
Definition ppp.h:54
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:51
PPP L2 context specific to certain network interface.
Definition ppp.h:409
struct net_mgmt_event_callback mgmt_evt_cb
Network management callback structure.
Definition ppp.h:509
struct k_sem wait_ppp_link_terminated
Signal when PPP link is terminated.
Definition ppp.h:515
enum net_l2_flags ppp_l2_flags
This tells what features the PPP supports.
Definition ppp.h:521
int network_protos_open
This tells how many network protocols are open.
Definition ppp.h:524
struct net_if * iface
Network interface related to this PPP connection.
Definition ppp.h:506
uint16_t is_ready_to_serve
Is PPP ready to receive packets.
Definition ppp.h:530
uint32_t magic
Magic-Number value.
Definition ppp.h:430
uint16_t is_pap_up
PAP status (up / down)
Definition ppp.h:551
struct k_work_delayable startup
PPP startup worker.
Definition ppp.h:416
enum ppp_phase phase
Current phase of PPP link.
Definition ppp.h:512
atomic_t flags
Flags representing PPP state, which are accessed from multiple threads.
Definition ppp.h:413
uint16_t is_ipv6cp_up
IPV6CP status (up / down)
Definition ppp.h:545
uint16_t is_ipcp_open
IPCP open status (open / closed)
Definition ppp.h:542
uint16_t is_enabled
Is PPP L2 enabled or not.
Definition ppp.h:533
uint16_t is_pap_open
PAP open status (open / closed)
Definition ppp.h:554
uint16_t is_ipcp_up
IPCP status (up / down)
Definition ppp.h:539
struct ppp_context::@463 lcp
LCP options.
int network_protos_up
This tells how many network protocols are up.
Definition ppp.h:527
uint16_t is_ipv6cp_open
IPV6CP open status (open / closed)
Definition ppp.h:548
uint16_t is_enable_done
PPP enable pending.
Definition ppp.h:536
struct k_sem wait_ppp_link_down
Signal when PPP link is down.
Definition ppp.h:518
Generic PPP Finite State Machine.
Definition ppp.h:237
char terminate_reason[32]
Reason for closing protocol.
Definition ppp.h:326
uint32_t nack_loops
Number of NACK loops since last ACK.
Definition ppp.h:320
const struct ppp_my_option_info * info
Options information.
Definition ppp.h:304
struct ppp_fsm::@461 cb
FSM callbacks.
uint16_t protocol
PPP protocol number for this FSM.
Definition ppp.h:329
uint32_t retransmits
Number of re-transmissions left.
Definition ppp.h:317
uint8_t ack_received
Have received valid Ack, Nack or Reject to a Request.
Definition ppp.h:344
uint32_t flags
Option bits.
Definition ppp.h:314
uint32_t recv_nack_loops
Number of NACKs received.
Definition ppp.h:323
struct ppp_my_option_data * data
Options negotiation data.
Definition ppp.h:307
size_t count
Number of negotiated options.
Definition ppp.h:310
uint8_t id
Current id.
Definition ppp.h:338
uint8_t req_id
Current request id.
Definition ppp.h:341
const char * name
Protocol/layer name of this FSM (for debugging)
Definition ppp.h:335
enum ppp_state state
Current state of PPP link.
Definition ppp.h:332
struct ppp_fsm::@462 my_options
My options.
struct k_work_delayable timer
Timeout timer.
Definition ppp.h:239
Shell instance internals.
Definition shell.h:1038