12#ifndef ZEPHYR_INCLUDE_NET_PPP_H_
13#define ZEPHYR_INCLUDE_NET_PPP_H_
34#define PPP_MRU CONFIG_NET_PPP_MTU_MRU
37#define PPP_MTU PPP_MRU
40#define PPP_MAX_TERMINATE_REASON_LEN 32
43#define PPP_INTERFACE_IDENTIFIER_LEN 8
62#if defined(CONFIG_NET_STATISTICS_PPP)
132enum ppp_packet_type {
133 PPP_CONFIGURE_REQ = 1,
134 PPP_CONFIGURE_ACK = 2,
135 PPP_CONFIGURE_NACK = 3,
136 PPP_CONFIGURE_REJ = 4,
137 PPP_TERMINATE_REQ = 5,
138 PPP_TERMINATE_ACK = 6,
140 PPP_PROTOCOL_REJ = 8,
228 size_t user_data_len);
230struct ppp_my_option_data;
231struct ppp_my_option_info;
295 enum ppp_packet_type code,
303 const struct ppp_my_option_info *
info;
306 struct ppp_my_option_data *
data;
348#define PPP_MY_OPTION_ACKED BIT(0)
349#define PPP_MY_OPTION_REJECTED BIT(1)
351struct ppp_my_option_data {
355#if defined(CONFIG_NET_L2_PPP_OPTION_DNS_USE)
356#define IPCP_NUM_MY_OPTIONS 3
358#define IPCP_NUM_MY_OPTIONS 1
360#define IPV6CP_NUM_MY_OPTIONS 1
389#define LCP_NUM_MY_OPTIONS (1 \
390 + IS_ENABLED(CONFIG_NET_L2_PPP_OPTION_MRU) \
391 + IS_ENABLED(CONFIG_NET_L2_PPP_OPTION_PFC) \
392 + IS_ENABLED(CONFIG_NET_L2_PPP_OPTION_ACFC))
440#if defined(CONFIG_NET_IPV4)
453 struct ppp_my_option_data my_options_data[IPCP_NUM_MY_OPTIONS];
457#if defined(CONFIG_NET_IPV6)
464 struct ipv6cp_options my_options;
467 struct ipv6cp_options peer_options;
470 struct ppp_my_option_data my_options_data[IPV6CP_NUM_MY_OPTIONS];
474#if defined(CONFIG_NET_L2_PPP_PAP)
482#if defined(CONFIG_NET_SHELL)
495 size_t user_data_len;
499 struct k_sem wait_echo_reply;
566#define PPP_L2_CTX_TYPE struct ppp_context
568#define NET_PPP_LAYER NET_MGMT_LAYER_L2
569#define NET_PPP_CODE NET_MGMT_LAYER_CODE_PPP
570#define NET_PPP_BASE (NET_MGMT_IFACE_BIT | \
571 NET_MGMT_LAYER(NET_PPP_LAYER) | \
572 NET_MGMT_LAYER_CODE(NET_PPP_CODE))
573#define NET_PPP_EVENT (NET_PPP_BASE | NET_MGMT_EVENT_BIT)
576 NET_EVENT_PPP_CMD_CARRIER_ON_VAL,
577 NET_EVENT_PPP_CMD_CARRIER_OFF_VAL,
578 NET_EVENT_PPP_CMD_PHASE_RUNNING_VAL,
579 NET_EVENT_PPP_CMD_PHASE_DEAD_VAL,
581 NET_EVENT_PPP_CMD_MAX
584BUILD_ASSERT(NET_EVENT_PPP_CMD_MAX <= NET_MGMT_MAX_COMMANDS,
585 "Number of events in net_event_ppp_cmd exceeds the limit");
587enum net_event_ppp_cmd {
599#define NET_PPP_DEFAULT_ASYNC_MAP (0xffffffffU)
615#define NET_EVENT_PPP_CARRIER_ON \
616 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_ON)
619#define NET_EVENT_PPP_CARRIER_OFF \
620 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_OFF)
623#define NET_EVENT_PPP_PHASE_RUNNING \
624 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_RUNNING)
627#define NET_EVENT_PPP_PHASE_DEAD \
628 (NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_DEAD)
635#if defined(CONFIG_NET_L2_PPP_MGMT)
649#if defined(CONFIG_NET_L2_PPP_MGMT)
663#if defined(CONFIG_NET_L2_PPP_MGMT)
677#if defined(CONFIG_NET_L2_PPP_MGMT)
696#if defined(CONFIG_NET_L2_PPP)
716#if defined(CONFIG_NET_L2_PPP) && defined(CONFIG_NET_SHELL)
#define DEVICE_API_EXTENDS(_child, _parent, _member)
Declare that API class _child is an extension of device API class _parent.
Definition device.h:1470
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
net_verdict
Net Verdict.
Definition net_core.h:84
net_l2_flags
L2 flags.
Definition net_l2.h:37
ipcp_option_type
IPCP option types from RFC 1332.
Definition ppp.h:180
static void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
Raise CARRIER_ON event when PPP is connected.
Definition ppp.h:638
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:227
ppp_phase
PPP phases.
Definition ppp.h:96
#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:719
uint32_t ppp_peer_async_control_character_map(struct net_if *iface)
Retrieve the PPP peers Asynchronous Control Character Map.
static void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
Raise PHASE_RUNNING event when PPP reaching RUNNING phase.
Definition ppp.h:666
ppp_protocol_type
PPP protocol types.
Definition ppp.h:80
static int net_ppp_ping(int idx, int32_t timeout)
Send PPP Echo-Request to peer.
Definition ppp.h:699
#define LCP_NUM_MY_OPTIONS
Definition ppp.h:389
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, section-6.
Definition ppp.h:151
static void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
Raise PHASE_DEAD event when PPP reaching DEAD phase.
Definition ppp.h:680
static void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
Raise CARRIER_OFF event when PPP is disconnected.
Definition ppp.h:652
ipv6cp_option_type
IPV6CP option types from RFC 5072.
Definition ppp.h:211
@ IPCP_OPTION_IP_ADDRESS
IP Address.
Definition ppp.h:191
@ IPCP_OPTION_DNS2
Secondary DNS Server Address.
Definition ppp.h:202
@ IPCP_OPTION_IP_COMP_PROTO
IP Compression Protocol.
Definition ppp.h:188
@ IPCP_OPTION_NBNS2
Secondary NBNS Server Address.
Definition ppp.h:205
@ IPCP_OPTION_RESERVED
Reserved IPCP option value (do not use).
Definition ppp.h:182
@ IPCP_OPTION_NBNS1
Primary NBNS Server Address.
Definition ppp.h:199
@ IPCP_OPTION_IP_ADDRESSES
IP Addresses.
Definition ppp.h:185
@ IPCP_OPTION_DNS1
Primary DNS Server Address.
Definition ppp.h:196
@ PPP_AUTH
Link authentication with peer.
Definition ppp.h:102
@ PPP_RUNNING
Network running.
Definition ppp.h:106
@ PPP_NETWORK
Network connection establishment.
Definition ppp.h:104
@ PPP_ESTABLISH
Link is being established.
Definition ppp.h:100
@ PPP_DEAD
Physical-layer not ready.
Definition ppp.h:98
@ PPP_TERMINATE
Link termination.
Definition ppp.h:108
@ PPP_IPV6
RFC 5072
Definition ppp.h:82
@ PPP_IP
RFC 1332
Definition ppp.h:81
@ PPP_CHAP
RFC 1334
Definition ppp.h:89
@ PPP_LCP
RFC 1661
Definition ppp.h:87
@ PPP_IPCP
RFC 1332
Definition ppp.h:83
@ PPP_ECP
RFC 1968
Definition ppp.h:84
@ PPP_CCP
RFC 1962
Definition ppp.h:86
@ PPP_EAP
RFC 2284
Definition ppp.h:90
@ PPP_IPV6CP
RFC 5072
Definition ppp.h:85
@ PPP_PAP
RFC 1334
Definition ppp.h:88
@ LCP_OPTION_ASYNC_CTRL_CHAR_MAP
Async-Control-Character-Map.
Definition ppp.h:159
@ LCP_OPTION_ADDR_CTRL_COMPRESS
Address-and-Control-Field-Compression.
Definition ppp.h:174
@ LCP_OPTION_QUALITY_PROTO
Quality-Protocol.
Definition ppp.h:165
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition ppp.h:168
@ LCP_OPTION_RESERVED
Reserved option value (do not use).
Definition ppp.h:153
@ LCP_OPTION_PROTO_COMPRESS
Protocol-Field-Compression.
Definition ppp.h:171
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition ppp.h:156
@ LCP_OPTION_AUTH_PROTO
Authentication-Protocol.
Definition ppp.h:162
@ IPV6CP_OPTION_INTERFACE_IDENTIFIER
Interface identifier.
Definition ppp.h:216
@ IPV6CP_OPTION_RESERVED
Reserved IPV6CP option value (do not use).
Definition ppp.h:213
#define ENOTSUP
Unsupported value.
Definition errno.h:115
@ NET_MGMT_CMD
Scan results available.
Definition wifi_mgmt.h:416
Public API for network interface.
Network Management API public header.
Network packet buffer descriptor API.
flags
Definition parser.h:86
__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:543
IPv4 control protocol options.
Definition ppp.h:395
struct net_in_addr dns2_address
Secondary DNS server address.
Definition ppp.h:403
struct net_in_addr dns1_address
Primary DNS server address.
Definition ppp.h:400
struct net_in_addr address
IPv4 address.
Definition ppp.h:397
IPv6 control protocol options.
Definition ppp.h:407
uint8_t iid[8]
Interface identifier.
Definition ppp.h:409
Semaphore structure.
Definition kernel.h:4002
A structure used to submit work after a delay.
Definition kernel.h:4955
Link control protocol options.
Definition ppp.h:369
uint16_t mru
Maximum Receive Unit value.
Definition ppp.h:377
uint32_t async_map
Async char map.
Definition ppp.h:374
bool acfc
Address-and-Control-Field-Compression negotiated.
Definition ppp.h:386
uint16_t auth_proto
Which authentication protocol was negotiated (0 means none).
Definition ppp.h:380
uint32_t magic
Magic number.
Definition ppp.h:371
bool pfc
Protocol-Field-Compression negotiated.
Definition ppp.h:383
Network Interface structure.
Definition net_if.h:875
IPv4 address struct.
Definition net_ip.h:156
Network packet.
Definition net_pkt.h:119
All PPP specific statistics.
Definition net_stats.h:702
PPP L2 context specific to certain network interface.
Definition ppp.h:413
struct k_sem wait_ppp_link_terminated
Signal when PPP link is terminated.
Definition ppp.h:516
enum net_l2_flags ppp_l2_flags
This tells what features the PPP supports.
Definition ppp.h:519
int network_protos_open
This tells how many network protocols are open.
Definition ppp.h:522
struct lcp_options my_options
Options that we want to request.
Definition ppp.h:428
struct net_if * iface
Network interface related to this PPP connection.
Definition ppp.h:510
uint16_t is_ready_to_serve
Is PPP ready to receive packets.
Definition ppp.h:528
uint32_t magic
Magic-Number value.
Definition ppp.h:434
uint16_t is_pap_up
PAP status (up / down).
Definition ppp.h:549
struct k_work_delayable startup
PPP startup worker.
Definition ppp.h:420
enum ppp_phase phase
Current phase of PPP link.
Definition ppp.h:513
atomic_t flags
Flags representing PPP state, which are accessed from multiple threads.
Definition ppp.h:417
struct ppp_context::@107044235232120325226013173232044313172073104354 lcp
LCP options.
uint16_t is_ipv6cp_up
IPV6CP status (up / down).
Definition ppp.h:543
uint16_t is_ipcp_open
IPCP open status (open / closed).
Definition ppp.h:540
uint16_t is_enabled
Is PPP L2 enabled or not.
Definition ppp.h:531
uint16_t is_pap_open
PAP open status (open / closed).
Definition ppp.h:552
struct lcp_options peer_options
Options that peer want to request.
Definition ppp.h:431
uint16_t is_ipcp_up
IPCP status (up / down).
Definition ppp.h:537
struct ppp_my_option_data my_options_data[(1+IS_ENABLED(CONFIG_NET_L2_PPP_OPTION_MRU)+IS_ENABLED(CONFIG_NET_L2_PPP_OPTION_PFC)+IS_ENABLED(CONFIG_NET_L2_PPP_OPTION_ACFC))]
Options data.
Definition ppp.h:437
int network_protos_up
This tells how many network protocols are up.
Definition ppp.h:525
uint16_t is_ipv6cp_open
IPV6CP open status (open / closed).
Definition ppp.h:546
struct ppp_fsm fsm
Finite state machine for LCP.
Definition ppp.h:425
uint16_t is_enable_done
PPP enable pending.
Definition ppp.h:534
PPP L2 API.
Definition ppp.h:46
int(* start)(const struct device *dev)
Start the device.
Definition ppp.h:54
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition ppp.h:60
struct net_if_driver_api iface_api
The net_if_driver_api must be placed in first position in this struct so that we are compatible with ...
Definition ppp.h:51
int(* stop)(const struct device *dev)
Stop the device.
Definition ppp.h:57
Generic PPP Finite State Machine.
Definition ppp.h:236
char terminate_reason[32]
Reason for closing protocol.
Definition ppp.h:325
int(* config_info_len)(struct ppp_fsm *fsm)
Length of Configuration Information.
Definition ppp.h:251
uint32_t nack_loops
Number of NACK loops since last ACK.
Definition ppp.h:319
struct ppp_fsm::@052004163371367320103113371230205042101145245273 cb
FSM callbacks.
const struct ppp_my_option_info * info
Options information.
Definition ppp.h:303
uint16_t protocol
PPP protocol number for this FSM.
Definition ppp.h:328
void(* down)(struct ppp_fsm *fsm)
FSM leaves OPENED state.
Definition ppp.h:277
uint32_t retransmits
Number of re-transmissions left.
Definition ppp.h:316
struct ppp_fsm::@036065054042057125263035255322050022074300066337 my_options
My options.
uint8_t ack_received
Have received valid Ack, Nack or Reject to a Request.
Definition ppp.h:343
int(* config_info_ack)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length)
Acknowledge Configuration Information.
Definition ppp.h:243
uint32_t flags
Option bits.
Definition ppp.h:313
uint32_t recv_nack_loops
Number of NACKs received.
Definition ppp.h:322
struct ppp_my_option_data * data
Options negotiation data.
Definition ppp.h:306
size_t count
Number of negotiated options.
Definition ppp.h:309
uint8_t id
Current id.
Definition ppp.h:337
uint8_t req_id
Current request id.
Definition ppp.h:340
int(* config_info_rej)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length)
Reject Configuration Information.
Definition ppp.h:266
const char * name
Protocol/layer name of this FSM (for debugging).
Definition ppp.h:334
void(* up)(struct ppp_fsm *fsm)
FSM goes to OPENED state.
Definition ppp.h:274
enum net_verdict(* proto_extension)(struct ppp_fsm *fsm, enum ppp_packet_type code, uint8_t id, struct net_pkt *pkt)
Any code that is not understood by PPP is passed to this FSM for further processing.
Definition ppp.h:294
int(* config_info_req)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length, struct net_pkt *ret_pkt)
Request peer's Configuration Information.
Definition ppp.h:260
enum ppp_state state
Current state of PPP link.
Definition ppp.h:331
int(* config_info_nack)(struct ppp_fsm *fsm, struct net_pkt *pkt, uint16_t length, bool rejected)
Negative Acknowledge Configuration Information.
Definition ppp.h:254
void(* starting)(struct ppp_fsm *fsm)
Starting this protocol.
Definition ppp.h:280
struct k_work_delayable timer
Timeout timer.
Definition ppp.h:238
void(* retransmit)(struct ppp_fsm *fsm)
Retransmit.
Definition ppp.h:289
void(* proto_reject)(struct ppp_fsm *fsm)
We received Protocol-Reject.
Definition ppp.h:286
void(* finished)(struct ppp_fsm *fsm)
Quitting this protocol.
Definition ppp.h:283
void(* config_info_reset)(struct ppp_fsm *fsm)
Reset Configuration Information.
Definition ppp.h:271