123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- #ifndef ZEPHYR_INCLUDE_NET_PPP_H_
- #define ZEPHYR_INCLUDE_NET_PPP_H_
- #include <net/net_if.h>
- #include <net/net_pkt.h>
- #include <net/net_stats.h>
- #include <net/net_mgmt.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define PPP_MRU CONFIG_NET_PPP_MTU_MRU
- #define PPP_MTU PPP_MRU
- #define PPP_MAX_TERMINATE_REASON_LEN 32
- #define PPP_INTERFACE_IDENTIFIER_LEN 8
- struct ppp_api {
-
- struct net_if_api iface_api;
-
- int (*start)(const struct device *dev);
-
- int (*stop)(const struct device *dev);
-
- int (*send)(const struct device *dev, struct net_pkt *pkt);
- #if defined(CONFIG_NET_STATISTICS_PPP)
-
- struct net_stats_ppp *(*get_stats)(const struct device *dev);
- #endif
- };
- BUILD_ASSERT(offsetof(struct ppp_api, iface_api) == 0);
- enum ppp_protocol_type {
- PPP_IP = 0x0021,
- PPP_IPV6 = 0x0057,
- PPP_IPCP = 0x8021,
- PPP_ECP = 0x8053,
- PPP_IPV6CP = 0x8057,
- PPP_CCP = 0x80FD,
- PPP_LCP = 0xc021,
- PPP_PAP = 0xc023,
- PPP_CHAP = 0xc223,
- PPP_EAP = 0xc227,
- };
- enum ppp_phase {
-
- PPP_DEAD,
-
- PPP_ESTABLISH,
-
- PPP_AUTH,
-
- PPP_NETWORK,
-
- PPP_RUNNING,
-
- PPP_TERMINATE,
- };
- enum ppp_state {
- PPP_INITIAL,
- PPP_STARTING,
- PPP_CLOSED,
- PPP_STOPPED,
- PPP_CLOSING,
- PPP_STOPPING,
- PPP_REQUEST_SENT,
- PPP_ACK_RECEIVED,
- PPP_ACK_SENT,
- PPP_OPENED
- };
- enum ppp_packet_type {
- PPP_CONFIGURE_REQ = 1,
- PPP_CONFIGURE_ACK = 2,
- PPP_CONFIGURE_NACK = 3,
- PPP_CONFIGURE_REJ = 4,
- PPP_TERMINATE_REQ = 5,
- PPP_TERMINATE_ACK = 6,
- PPP_CODE_REJ = 7,
- PPP_PROTOCOL_REJ = 8,
- PPP_ECHO_REQ = 9,
- PPP_ECHO_REPLY = 10,
- PPP_DISCARD_REQ = 11
- };
- enum lcp_option_type {
- LCP_OPTION_RESERVED = 0,
-
- LCP_OPTION_MRU = 1,
-
- LCP_OPTION_ASYNC_CTRL_CHAR_MAP = 2,
-
- LCP_OPTION_AUTH_PROTO = 3,
-
- LCP_OPTION_QUALITY_PROTO = 4,
-
- LCP_OPTION_MAGIC_NUMBER = 5,
-
- LCP_OPTION_PROTO_COMPRESS = 7,
-
- LCP_OPTION_ADDR_CTRL_COMPRESS = 8
- } __packed;
- enum ipcp_option_type {
- IPCP_OPTION_RESERVED = 0,
-
- IPCP_OPTION_IP_ADDRESSES = 1,
-
- IPCP_OPTION_IP_COMP_PROTO = 2,
-
- IPCP_OPTION_IP_ADDRESS = 3,
-
-
- IPCP_OPTION_DNS1 = 129,
-
- IPCP_OPTION_NBNS1 = 130,
-
- IPCP_OPTION_DNS2 = 131,
-
- IPCP_OPTION_NBNS2 = 132,
- } __packed;
- enum ipv6cp_option_type {
- IPV6CP_OPTION_RESERVED = 0,
-
- IPV6CP_OPTION_INTERFACE_IDENTIFIER = 1,
- } __packed;
- typedef void (*net_ppp_lcp_echo_reply_cb_t)(void *user_data,
- size_t user_data_len);
- struct ppp_my_option_data;
- struct ppp_my_option_info;
- struct ppp_fsm {
-
- struct k_work_delayable timer;
- struct {
-
- int (*config_info_ack)(struct ppp_fsm *fsm,
- struct net_pkt *pkt,
- uint16_t length);
-
- struct net_pkt *(*config_info_add)(struct ppp_fsm *fsm);
-
- int (*config_info_len)(struct ppp_fsm *fsm);
-
- int (*config_info_nack)(struct ppp_fsm *fsm,
- struct net_pkt *pkt,
- uint16_t length,
- bool rejected);
-
- int (*config_info_req)(struct ppp_fsm *fsm,
- struct net_pkt *pkt,
- uint16_t length,
- struct net_pkt *ret_pkt);
-
- int (*config_info_rej)(struct ppp_fsm *fsm,
- struct net_pkt *pkt,
- uint16_t length);
-
- void (*config_info_reset)(struct ppp_fsm *fsm);
-
- void (*up)(struct ppp_fsm *fsm);
-
- void (*down)(struct ppp_fsm *fsm);
-
- void (*starting)(struct ppp_fsm *fsm);
-
- void (*finished)(struct ppp_fsm *fsm);
-
- void (*proto_reject)(struct ppp_fsm *fsm);
-
- void (*retransmit)(struct ppp_fsm *fsm);
-
- enum net_verdict (*proto_extension)(struct ppp_fsm *fsm,
- enum ppp_packet_type code,
- uint8_t id,
- struct net_pkt *pkt);
- } cb;
- struct {
-
- const struct ppp_my_option_info *info;
-
- struct ppp_my_option_data *data;
-
- size_t count;
- } my_options;
-
- uint32_t flags;
- ;
- uint32_t retransmits;
-
- uint32_t nack_loops;
-
- uint32_t recv_nack_loops;
-
- char terminate_reason[PPP_MAX_TERMINATE_REASON_LEN];
-
- uint16_t protocol;
-
- enum ppp_state state;
-
- const char *name;
-
- uint8_t id;
-
- uint8_t req_id;
-
- uint8_t ack_received : 1;
- };
- #define PPP_MY_OPTION_ACKED BIT(0)
- #define PPP_MY_OPTION_REJECTED BIT(1)
- struct ppp_my_option_data {
- uint32_t flags;
- };
- struct lcp_options {
-
- uint32_t magic;
-
- uint32_t async_map;
-
- uint16_t mru;
-
- uint16_t auth_proto;
- };
- #if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
- #define LCP_NUM_MY_OPTIONS 1
- #endif
- struct ipcp_options {
-
- struct in_addr address;
- struct in_addr dns1_address;
- struct in_addr dns2_address;
- };
- #define IPCP_NUM_MY_OPTIONS 3
- struct ipv6cp_options {
-
- uint8_t iid[PPP_INTERFACE_IDENTIFIER_LEN];
- };
- #define IPV6CP_NUM_MY_OPTIONS 1
- enum ppp_flags {
- PPP_CARRIER_UP,
- };
- struct ppp_context {
-
- atomic_t flags;
-
- struct k_work_delayable startup;
-
- struct k_work carrier_work;
- struct {
-
- struct ppp_fsm fsm;
-
- struct lcp_options my_options;
-
- struct lcp_options peer_options;
-
- uint32_t magic;
- #if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
- struct ppp_my_option_data my_options_data[LCP_NUM_MY_OPTIONS];
- #endif
- } lcp;
- #if defined(CONFIG_NET_IPV4)
- struct {
-
- struct ppp_fsm fsm;
-
- struct ipcp_options my_options;
-
- struct ipcp_options peer_options;
-
- struct ppp_my_option_data my_options_data[IPCP_NUM_MY_OPTIONS];
- } ipcp;
- #endif
- #if defined(CONFIG_NET_IPV6)
- struct {
-
- struct ppp_fsm fsm;
-
- struct ipv6cp_options my_options;
-
- struct ipv6cp_options peer_options;
-
- struct ppp_my_option_data my_options_data[IPV6CP_NUM_MY_OPTIONS];
- } ipv6cp;
- #endif
- #if defined(CONFIG_NET_L2_PPP_PAP)
- struct {
-
- struct ppp_fsm fsm;
- } pap;
- #endif
- #if defined(CONFIG_NET_SHELL)
- struct {
- struct {
-
- net_ppp_lcp_echo_reply_cb_t cb;
-
- void *user_data;
-
- size_t user_data_len;
- } echo_reply;
-
- struct k_sem wait_echo_reply;
-
- uint32_t echo_req_data;
-
- uint32_t echo_reply_data;
- } shell;
- #endif
-
- struct net_if *iface;
-
- enum ppp_phase phase;
-
- enum net_l2_flags ppp_l2_flags;
-
- int network_protos_open;
-
- int network_protos_up;
-
- uint16_t is_net_carrier_up : 1;
-
- uint16_t is_ready_to_serve : 1;
-
- uint16_t is_enabled : 1;
-
- uint16_t is_startup_pending : 1;
-
- uint16_t is_enable_done : 1;
-
- uint16_t is_ipcp_up : 1;
-
- uint16_t is_ipcp_open : 1;
-
- uint16_t is_ipv6cp_up : 1;
-
- uint16_t is_ipv6cp_open : 1;
-
- uint16_t is_pap_up : 1;
-
- uint16_t is_pap_open : 1;
- };
- void net_ppp_carrier_on(struct net_if *iface);
- void net_ppp_carrier_off(struct net_if *iface);
- void net_ppp_init(struct net_if *iface);
- #define PPP_L2_CTX_TYPE struct ppp_context
- #define _NET_PPP_LAYER NET_MGMT_LAYER_L2
- #define _NET_PPP_CODE 0x209
- #define _NET_PPP_BASE (NET_MGMT_IFACE_BIT | \
- NET_MGMT_LAYER(_NET_PPP_LAYER) | \
- NET_MGMT_LAYER_CODE(_NET_PPP_CODE))
- #define _NET_PPP_EVENT (_NET_PPP_BASE | NET_MGMT_EVENT_BIT)
- enum net_event_ppp_cmd {
- NET_EVENT_PPP_CMD_CARRIER_ON = 1,
- NET_EVENT_PPP_CMD_CARRIER_OFF,
- NET_EVENT_PPP_CMD_PHASE_RUNNING,
- NET_EVENT_PPP_CMD_PHASE_DEAD,
- };
- #define NET_EVENT_PPP_CARRIER_ON \
- (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_ON)
- #define NET_EVENT_PPP_CARRIER_OFF \
- (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_CARRIER_OFF)
- #define NET_EVENT_PPP_PHASE_RUNNING \
- (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_RUNNING)
- #define NET_EVENT_PPP_PHASE_DEAD \
- (_NET_PPP_EVENT | NET_EVENT_PPP_CMD_PHASE_DEAD)
- struct net_if;
- #if defined(CONFIG_NET_L2_PPP_MGMT)
- void ppp_mgmt_raise_carrier_on_event(struct net_if *iface);
- #else
- static inline void ppp_mgmt_raise_carrier_on_event(struct net_if *iface)
- {
- ARG_UNUSED(iface);
- }
- #endif
- #if defined(CONFIG_NET_L2_PPP_MGMT)
- void ppp_mgmt_raise_carrier_off_event(struct net_if *iface);
- #else
- static inline void ppp_mgmt_raise_carrier_off_event(struct net_if *iface)
- {
- ARG_UNUSED(iface);
- }
- #endif
- #if defined(CONFIG_NET_L2_PPP_MGMT)
- void ppp_mgmt_raise_phase_running_event(struct net_if *iface);
- #else
- static inline void ppp_mgmt_raise_phase_running_event(struct net_if *iface)
- {
- ARG_UNUSED(iface);
- }
- #endif
- #if defined(CONFIG_NET_L2_PPP_MGMT)
- void ppp_mgmt_raise_phase_dead_event(struct net_if *iface);
- #else
- static inline void ppp_mgmt_raise_phase_dead_event(struct net_if *iface)
- {
- ARG_UNUSED(iface);
- }
- #endif
- #if defined(CONFIG_NET_L2_PPP)
- int net_ppp_ping(int idx, int32_t timeout);
- #else
- static inline int net_ppp_ping(int idx, int32_t timeout)
- {
- ARG_UNUSED(idx);
- ARG_UNUSED(timeout);
- return -ENOTSUP;
- }
- #endif
- #if defined(CONFIG_NET_L2_PPP) && defined(CONFIG_NET_SHELL)
- struct ppp_context *net_ppp_context_get(int idx);
- #else
- static inline struct ppp_context *net_ppp_context_get(int idx)
- {
- ARG_UNUSED(idx);
- return NULL;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|