Mbed OS Reference
Loading...
Searching...
No Matches
netsocket/include/netsocket/PPP.h
1/*
2 * Copyright (c) 2019 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef PPP_H_
19#define PPP_H_
20
21#include <stdbool.h>
22#include "Callback.h"
23#include "FileHandle.h"
24#include "NetStackMemoryManager.h"
25
26class PPP {
27public:
28
29 /** Return the default on-board PPP
30 *
31 * Returns the default on-board PPP - this will be target-specific, and
32 * may not be available on all targets.
33 */
35
36 virtual ~PPP() = default;
37
38 /**
39 * Callback to be registered with PPP interface and to be called for received packets
40 *
41 * <br> \c buf : Received data
42 */
43 typedef mbed::Callback<void (net_stack_mem_buf_t *buf)> ppp_link_input_cb_t;
44
45 /**
46 * Callback to be registered with PPP interface and to be called for link status changes
47 *
48 * <br> \c up : Link status
49 */
51
52 /**
53 * Return maximum transmission unit
54 *
55 * @return MTU in bytes
56 */
57 virtual uint32_t get_mtu_size() = 0;
58
59 /**
60 * Gets memory buffer alignment preference
61 *
62 * Gets preferred memory buffer alignment of the cellular device.
63 * @return Memory alignment requirement in bytes
64 */
65 virtual uint32_t get_align_preference() const = 0;
66
67 /**
68 * Return interface name
69 *
70 * @param name Pointer to where the name should be written
71 * @param size Maximum number of characters to copy
72 */
73 virtual void get_ifname(char *name, uint8_t size) const = 0;
74
75 /**
76 * Sends the packet over the link
77 *
78 * That cannot be called from an interrupt context.
79 *
80 * @param buf Packet to be sent
81 * @param ip_stack IP version to use (4 or 6) to send the packet.
82 * @return True if the packet was sent, false otherwise
83 */
84 virtual bool link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack) = 0;
85
86 /**
87 * Initializes the PPP
88 *
89 * @return True on success, False in case of an error.
90 */
91 virtual bool power_up() = 0;
92
93 /**
94 * Deinitializes the PPP
95 *
96 */
97 virtual void power_down() = 0;
98
99 /**
100 * Sets a callback that needs to be called for packets received for that interface
101 *
102 * @param input_cb Function to be register as a callback
103 */
104 virtual void set_link_input_cb(ppp_link_input_cb_t input_cb) = 0;
105
106 /**
107 * Sets a callback that needs to be called on link status changes for given interface
108 *
109 * @param state_cb Function to be register as a callback
110 */
112
113 /** Sets memory manager that is used to handle memory buffers
114 *
115 * @param mem_mngr Pointer to memory manager
116 */
117 virtual void set_memory_manager(NetStackMemoryManager &mem_mngr) = 0;
118
119 /** Sets file stream used to communicate with modem
120 *
121 * @param stream Pointer to file handle
122 */
123 virtual void set_stream(mbed::FileHandle *stream) = 0;
124
125 /** Sets IP protocol versions of IP stack
126 *
127 * @param ip_stack IP protocol version
128 */
129 virtual void set_ip_stack(nsapi_ip_stack_t ip_stack) = 0;
130
131 /** Sets user name and password for PPP protocol
132 *
133 * @param uname User name
134 * @param password Password
135 */
136 virtual void set_credentials(const char *uname, const char *password) = 0;
137
138 /** Gets local IP address
139 *
140 * @param version IP address version
141 * @return IP address
142 */
143 virtual const nsapi_addr_t *get_ip_address(nsapi_version_t version) = 0;
144
145 /** Get the local network mask.
146 *
147 * @return Local network mask or null if no network mask has been received.
148 */
149 virtual const nsapi_addr_t *get_netmask() = 0;
150
151 /** Get the local gateway.
152 *
153 * @return Local gateway or null if no network mask has been received.
154 */
155 virtual const nsapi_addr_t *get_gateway() = 0;
156
157 /** Gets DNS server address
158 *
159 * @param index Server index
160 */
161 virtual const nsapi_addr_t *get_dns_server(uint8_t index) = 0;
162};
163
164#endif /* PPP_H_ */
virtual void set_memory_manager(NetStackMemoryManager &mem_mngr)=0
Sets memory manager that is used to handle memory buffers.
virtual uint32_t get_mtu_size()=0
Return maximum transmission unit.
virtual bool power_up()=0
Initializes the PPP.
virtual void set_link_input_cb(ppp_link_input_cb_t input_cb)=0
Sets a callback that needs to be called for packets received for that interface.
virtual const nsapi_addr_t * get_dns_server(uint8_t index)=0
Gets DNS server address.
virtual const nsapi_addr_t * get_ip_address(nsapi_version_t version)=0
Gets local IP address.
virtual const nsapi_addr_t * get_gateway()=0
Get the local gateway.
virtual void set_ip_stack(nsapi_ip_stack_t ip_stack)=0
Sets IP protocol versions of IP stack.
virtual void get_ifname(char *name, uint8_t size) const =0
Return interface name.
mbed::Callback< void(bool up)> ppp_link_state_change_cb_t
Callback to be registered with PPP interface and to be called for link status changes.
virtual void set_credentials(const char *uname, const char *password)=0
Sets user name and password for PPP protocol.
virtual uint32_t get_align_preference() const =0
Gets memory buffer alignment preference.
virtual bool link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack)=0
Sends the packet over the link.
virtual const nsapi_addr_t * get_netmask()=0
Get the local network mask.
virtual void set_stream(mbed::FileHandle *stream)=0
Sets file stream used to communicate with modem.
virtual void power_down()=0
Deinitializes the PPP.
mbed::Callback< void(net_stack_mem_buf_t *buf)> ppp_link_input_cb_t
Callback to be registered with PPP interface and to be called for received packets.
static PPP & get_default_instance()
Return the default on-board PPP.
virtual void set_link_state_cb(ppp_link_state_change_cb_t state_cb)=0
Sets a callback that needs to be called on link status changes for given interface.
Callback class based on template specialization.
Definition: Callback.h:53
Class FileHandle.
Definition: FileHandle.h:46
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:237