Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ppp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Trackunit Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include <zephyr/kernel.h>
8#include <zephyr/types.h>
9#include <zephyr/net/net_if.h>
10#include <zephyr/net/net_pkt.h>
11#include <zephyr/net/ppp.h>
13#include <zephyr/sys/atomic.h>
14
15#include <zephyr/modem/pipe.h>
16#include <zephyr/modem/stats.h>
17
18#ifndef ZEPHYR_INCLUDE_MODEM_PPP_H_
19#define ZEPHYR_INCLUDE_MODEM_PPP_H_
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
33
35typedef void (*modem_ppp_init_iface)(struct net_if *iface);
36
40
41enum modem_ppp_state {
42 /* Pipe is attached */
43 MODEM_PPP_STATE_ATTACHED_BIT = 0,
44 /* Link is dead */
45 MODEM_PPP_STATE_DEAD_BIT,
46};
47
48enum modem_ppp_receive_state {
49 /* Searching for start of frame and header */
50 MODEM_PPP_RECEIVE_STATE_HDR_SOF = 0,
51 MODEM_PPP_RECEIVE_STATE_HDR_FF,
52 MODEM_PPP_RECEIVE_STATE_HDR_FF_UNESCAPE,
53 MODEM_PPP_RECEIVE_STATE_HDR_CTRL_UNESCAPE,
54 MODEM_PPP_RECEIVE_STATE_HDR_CTRL,
55 /* Writing bytes to network packet */
56 MODEM_PPP_RECEIVE_STATE_WRITING,
57 /* Unescaping next byte before writing to network packet */
58 MODEM_PPP_RECEIVE_STATE_UNESCAPING,
59 /* Receiving an unsolicited "NO CARRIER" event */
60 MODEM_PPP_RECEIVE_STATE_UNSOLICITED_NO_CARRIER,
61};
62
63enum modem_ppp_transmit_state {
64 MODEM_PPP_TRANSMIT_STATE_IDLE = 0,
65 MODEM_PPP_TRANSMIT_STATE_SOF,
66 MODEM_PPP_TRANSMIT_STATE_PROTOCOL,
67 MODEM_PPP_TRANSMIT_STATE_DATA,
68 MODEM_PPP_TRANSMIT_STATE_EOF,
69};
70
71struct modem_ppp {
72 /* Network interface instance is bound to */
73 struct net_if *iface;
74
75 /* Hook for PPP L2 network interface initialization */
76 modem_ppp_init_iface init_iface;
77
79
80 /* Buffers used for processing partial frames */
81 uint8_t *receive_buf;
82 uint8_t *transmit_buf;
83 uint16_t buf_size;
84
85 /* Wrapped PPP frames are sent and received through this pipe */
86 struct modem_pipe *pipe;
87
88 /* Receive PPP frame state */
89 enum modem_ppp_receive_state receive_state;
90 uint8_t receive_offset;
91
92 /* Allocated network packet being created */
93 struct net_pkt *rx_pkt;
94 /* FCS of the received header bytes not stored in rx_pkt */
95 uint16_t rx_pkt_fcs;
96
97 /* Packet being sent */
98 enum modem_ppp_transmit_state transmit_state;
99 struct net_pkt *tx_pkt;
100 uint16_t tx_pkt_fcs;
101
102 /* Ring buffer used for transmitting partial PPP frame */
103 struct ring_buf transmit_rb;
104
105 struct k_fifo tx_pkt_fifo;
106
107 /* Work */
108 struct k_work send_work;
109 struct k_work process_work;
110 struct k_work closed_work;
111
112#if defined(CONFIG_NET_STATISTICS_PPP)
113 struct net_stats_ppp stats;
114#endif
115
116#if CONFIG_MODEM_STATS
117 struct modem_stats_buffer receive_buf_stats;
118 struct modem_stats_buffer transmit_buf_stats;
119#endif
120};
121
122struct modem_ppp_config {
123 const struct device *dev;
124};
125
129
136int modem_ppp_attach(struct modem_ppp *ppp, struct modem_pipe *pipe);
137
144struct net_if *modem_ppp_get_iface(struct modem_ppp *ppp);
145
151void modem_ppp_release(struct modem_ppp *ppp);
152
156
162int modem_ppp_init_internal(const struct device *dev);
163
167
184#define MODEM_DEV_PPP_DEFINE(_dev, _name, _init_iface, _mtu, _buf_size) \
185 extern const struct ppp_driver_api modem_ppp_ppp_api; \
186 \
187 static uint8_t _CONCAT(_name, _receive_buf)[_buf_size]; \
188 static uint8_t _CONCAT(_name, _transmit_buf)[_buf_size]; \
189 \
190 static struct modem_ppp _name = { \
191 .init_iface = _init_iface, \
192 .receive_buf = _CONCAT(_name, _receive_buf), \
193 .transmit_buf = _CONCAT(_name, _transmit_buf), \
194 .buf_size = _buf_size, \
195 }; \
196 static const struct modem_ppp_config _CONCAT(_name, _config) = { \
197 .dev = _dev, \
198 }; \
199 \
200 NET_DEVICE_INIT(_CONCAT(ppp_net_dev_, _name), "modem_ppp_" #_name, \
201 modem_ppp_init_internal, NULL, &_name, &_CONCAT(_name, _config), \
202 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
203 &modem_ppp_ppp_api, PPP_L2, NET_L2_GET_CTX_TYPE(PPP_L2), _mtu)
204
210#define MODEM_DT_INST_PPP_DEFINE(inst, _name, _init_iface, _mtu, _buf_size) \
211 MODEM_DEV_PPP_DEFINE(DEVICE_DT_INST_GET(inst), _name, _init_iface, _mtu, _buf_size)
212
218#define MODEM_PPP_DEFINE(_name, _init_iface, _mtu, _buf_size) \
219 MODEM_DEV_PPP_DEFINE(NULL, _name, _init_iface, _mtu, _buf_size)
220
224
225#ifdef __cplusplus
226}
227#endif
228
229#endif /* ZEPHYR_INCLUDE_MODEM_PPP_H_ */
Header file for the Atomic operations API.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
int modem_ppp_attach(struct modem_ppp *ppp, struct modem_pipe *pipe)
Attach pipe to instance and connect.
struct net_if * modem_ppp_get_iface(struct modem_ppp *ppp)
Get network interface modem PPP instance is bound to.
void modem_ppp_release(struct modem_ppp *ppp)
Release pipe from instance.
void(* modem_ppp_init_iface)(struct net_if *iface)
L2 network interface init callback.
Definition ppp.h:35
Public kernel APIs.
PPP (Point-to-Point Protocol).
Public API for network interface.
Network packet buffer descriptor API.
state
Definition parser_state.h:29
Simple, header-only ring buffer implementation.
__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
Network Interface structure.
Definition net_if.h:875