Zephyr API Documentation 4.4.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_MODEM_PPP_
19#define ZEPHYR_MODEM_PPP_
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_CTRL_UNESCAPE,
53 MODEM_PPP_RECEIVE_STATE_HDR_CTRL,
54 /* Writing bytes to network packet */
55 MODEM_PPP_RECEIVE_STATE_WRITING,
56 /* Unescaping next byte before writing to network packet */
57 MODEM_PPP_RECEIVE_STATE_UNESCAPING,
58 /* Receiving an unsolicited "NO CARRIER" event */
59 MODEM_PPP_RECEIVE_STATE_UNSOLICITED_NO_CARRIER,
60};
61
62enum modem_ppp_transmit_state {
63 MODEM_PPP_TRANSMIT_STATE_IDLE = 0,
64 MODEM_PPP_TRANSMIT_STATE_SOF,
65 MODEM_PPP_TRANSMIT_STATE_PROTOCOL,
66 MODEM_PPP_TRANSMIT_STATE_DATA,
67 MODEM_PPP_TRANSMIT_STATE_EOF,
68};
69
70struct modem_ppp {
71 /* Network interface instance is bound to */
72 struct net_if *iface;
73
74 /* Hook for PPP L2 network interface initialization */
75 modem_ppp_init_iface init_iface;
76
78
79 /* Buffers used for processing partial frames */
80 uint8_t *receive_buf;
81 uint8_t *transmit_buf;
82 uint16_t buf_size;
83
84 /* Wrapped PPP frames are sent and received through this pipe */
85 struct modem_pipe *pipe;
86
87 /* Receive PPP frame state */
88 enum modem_ppp_receive_state receive_state;
89 uint8_t receive_offset;
90
91 /* Allocated network packet being created */
92 struct net_pkt *rx_pkt;
93
94 /* Packet being sent */
95 enum modem_ppp_transmit_state transmit_state;
96 struct net_pkt *tx_pkt;
97 uint16_t tx_pkt_fcs;
98
99 /* Ring buffer used for transmitting partial PPP frame */
100 struct ring_buf transmit_rb;
101
102 struct k_fifo tx_pkt_fifo;
103
104 /* Work */
105 struct k_work send_work;
106 struct k_work process_work;
107
108#if defined(CONFIG_NET_STATISTICS_PPP)
109 struct net_stats_ppp stats;
110#endif
111
112#if CONFIG_MODEM_STATS
113 struct modem_stats_buffer receive_buf_stats;
114 struct modem_stats_buffer transmit_buf_stats;
115#endif
116};
117
118struct modem_ppp_config {
119 const struct device *dev;
120};
121
125
132int modem_ppp_attach(struct modem_ppp *ppp, struct modem_pipe *pipe);
133
140struct net_if *modem_ppp_get_iface(struct modem_ppp *ppp);
141
147void modem_ppp_release(struct modem_ppp *ppp);
148
152
158int modem_ppp_init_internal(const struct device *dev);
159
163
181#define MODEM_DEV_PPP_DEFINE(_dev, _name, _init_iface, _prio, _mtu, _buf_size) \
182 extern const struct ppp_api modem_ppp_ppp_api; \
183 \
184 static uint8_t _CONCAT(_name, _receive_buf)[_buf_size]; \
185 static uint8_t _CONCAT(_name, _transmit_buf)[_buf_size]; \
186 \
187 static struct modem_ppp _name = { \
188 .init_iface = _init_iface, \
189 .receive_buf = _CONCAT(_name, _receive_buf), \
190 .transmit_buf = _CONCAT(_name, _transmit_buf), \
191 .buf_size = _buf_size, \
192 }; \
193 static const struct modem_ppp_config _CONCAT(_name, _config) = { \
194 .dev = _dev, \
195 }; \
196 \
197 NET_DEVICE_INIT(_CONCAT(ppp_net_dev_, _name), "modem_ppp_" #_name, \
198 modem_ppp_init_internal, NULL, &_name, &_CONCAT(_name, _config), _prio, \
199 &modem_ppp_ppp_api, PPP_L2, NET_L2_GET_CTX_TYPE(PPP_L2), _mtu)
200
206#define MODEM_DT_INST_PPP_DEFINE(inst, _name, _init_iface, _prio, _mtu, _buf_size) \
207 MODEM_DEV_PPP_DEFINE(DEVICE_DT_INST_GET(inst), _name, _init_iface, _prio, _mtu, _buf_size)
208
214#define MODEM_PPP_DEFINE(_name, _init_iface, _prio, _mtu, _buf_size) \
215 MODEM_DEV_PPP_DEFINE(NULL, _name, _init_iface, _prio, _mtu, _buf_size)
216
220
221#ifdef __cplusplus
222}
223#endif
224
225#endif /* ZEPHYR_MODEM_PPP_ */
long atomic_t
Definition atomic_types.h:15
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
__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:513
Network Interface structure.
Definition net_if.h:731