Skip to content

Commit 49994fc

Browse files
author
Mika Leppänen
committed
Added PPP interface to nanostack
This utilizes ethernet interface. PPP interface differences to Ethernet: - interface identifier is provided when interface is added - there is no link layer address (e.g. MAC) - Neighbor solification’s are not made - SLLAO is not added to RS (because link layer address e.g. MAC address is not set) - Duplicate address detection is not made
1 parent 3383e91 commit 49994fc

File tree

8 files changed

+162
-10
lines changed

8 files changed

+162
-10
lines changed

nanostack/ethernet_mac_api.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ typedef int8_t eth_mac_mac48_address_set(const eth_mac_api_t *api, const uint8_t
123123
*/
124124
typedef int8_t eth_mac_mac48_address_get(const eth_mac_api_t *api, uint8_t *mac48_buf);
125125

126+
/**
127+
* @brief Set 64 bit interface identifier from IID64
128+
* @param api API to handle the request
129+
* @param iid64 Pointer having iid64 to be set
130+
* @return 0 if successful, -1 otherwise
131+
*/
132+
typedef int8_t eth_mac_iid64_address_set(const eth_mac_api_t *api, const uint8_t *iid64);
133+
134+
/**
135+
* @brief Read 64 bit interface identifier
136+
* @param api API to handle the request
137+
* @paramiid64_buf Pointer where IID64 can be written
138+
* @return 0 if successful, -1 otherwise
139+
*/
140+
typedef int8_t eth_mac_iid64_address_get(const eth_mac_api_t *api, uint8_t *iid64_buf);
141+
126142
/**
127143
* @brief Upper layer will call this function, when MAC is taken into use
128144
* @param api API to initialize
@@ -147,6 +163,9 @@ struct eth_mac_api_s {
147163
eth_mac_mac48_address_set *mac48_set; /**< Setter for MAC address */
148164
eth_mac_mac48_address_get *mac48_get; /**< Getter for MAC address */
149165

166+
eth_mac_iid64_address_set *iid64_set; /**< Setter for IID64 */
167+
eth_mac_iid64_address_get *iid64_get; /**< Getter for IID64 */
168+
150169
uint8_t parent_id; /**< Upper layer ID */
151170
bool address_resolution_needed; /**< Normal ethernet should set this true for tunnel or false for slip */
152171
};

nanostack/net_interface.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,20 @@ extern int8_t arm_nwk_interface_ethernet_init(struct eth_mac_api_s *api, const c
320320
*/
321321
extern int8_t arm_nwk_interface_lowpan_init(struct mac_api_s *api, char *interface_name_ptr);
322322

323+
/**
324+
* \brief Create network interface base to IDLE state.
325+
* \param api Generates interface with PPP.
326+
* \param interface_name_ptr String pointer to interface name. Need to end to '\0' character.
327+
* Max length 32 characters including NULL at end. Note: the given name is not copied,
328+
* so it must remain valid as long as the interface is.
329+
*
330+
* \return >=0 Interface ID (0-127). Application needs to save this information.
331+
* \return -1 api was NULL.
332+
* \return -2 PPP is not supported at this build.
333+
* \return -3 No memory for the interface.
334+
*/
335+
extern int8_t arm_nwk_interface_ppp_init(struct eth_mac_api_s *api, const char *interface_name_ptr);
336+
323337
/**
324338
* \brief Set IPv6 interface setup.
325339
*

nanostack/platform/arm_hal_phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef enum phy_link_type_e {
9797
PHY_LINK_15_4_SUBGHZ_TYPE, /**< Standard 802.15.4 subGHz radio 868 /915MHz. */
9898
PHY_LINK_TUN, /**< Tunnel interface for Linux TUN, RF network driver over serial bus or just basic application to application data flow. */
9999
PHY_LINK_SLIP, /**< Generic SLIP driver which just forward SLIP payload */
100+
PHY_LINK_PPP, /**< PPP */
100101
} phy_link_type_e;
101102

102103
/** Data layers */

source/MAC/ethernet/ethernet_mac_api.c

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct eth_mac_internal_s {
2828
arm_device_driver_list_s *dev_driver;
2929
uint8_t *mtu_ptr;
3030
uint16_t mtu_size;
31-
uint8_t mac48[6];
31+
uint8_t mac48_iid64[8];
3232
bool active_data_request;
3333
int8_t tasklet_id;
3434
//linked list link
@@ -52,6 +52,8 @@ static int8_t eth_mac_api_init(eth_mac_api_t *api, eth_mac_data_confirm *conf_cb
5252
static void data_req(const eth_mac_api_t *api, const eth_data_req_t *data);
5353
static int8_t mac48_address_set(const eth_mac_api_t *api, const uint8_t *mac48);
5454
static int8_t mac48_address_get(const eth_mac_api_t *api, uint8_t *mac48_buf);
55+
static int8_t iid64_address_set(const eth_mac_api_t *api, const uint8_t *iid64);
56+
static int8_t iid64_address_get(const eth_mac_api_t *api, uint8_t *iid64_buf);
5557

5658
static int8_t eth_mac_net_phy_rx(const uint8_t *data_ptr, uint16_t data_len, uint8_t link_quality, int8_t dbm, int8_t driver_id);
5759
static int8_t eth_mac_net_phy_tx_done(int8_t driver_id, uint8_t tx_handle, phy_link_tx_status_e status, uint8_t cca_retry, uint8_t tx_retry);
@@ -98,6 +100,7 @@ eth_mac_api_t *ethernet_mac_create(int8_t driver_id)
98100
switch (driver->phy_driver->link_type) {
99101

100102
case PHY_LINK_SLIP:
103+
case PHY_LINK_PPP:
101104
//Do not Allocate
102105
address_resolution_needed = false;
103106
buffer_length = 0;
@@ -133,19 +136,29 @@ eth_mac_api_t *ethernet_mac_create(int8_t driver_id)
133136
memset(this, 0, sizeof(eth_mac_api_t));
134137
this->mac_initialize = &eth_mac_api_init;
135138
this->data_req = &data_req;
136-
this->mac48_get = &mac48_address_get;
137-
this->mac48_set = &mac48_address_set;
139+
140+
if (driver->phy_driver->link_type == PHY_LINK_PPP) {
141+
this->iid64_get = &iid64_address_get;
142+
this->iid64_set = &iid64_address_set;
143+
} else {
144+
this->mac48_get = &mac48_address_get;
145+
this->mac48_set = &mac48_address_set;
146+
}
138147

139148
this->address_resolution_needed = address_resolution_needed;
140149

141-
memset(&mac_store.mac48, 0, 6);
150+
memset(&mac_store.mac48_iid64, 0, 8);
142151
mac_store.active_data_request = false;
143152
mac_store.mac_api = this;
144153
mac_store.dev_driver = driver;
145154
mac_store.mtu_ptr = buffer_ptr;
146155
mac_store.mtu_size = buffer_length;
147156

148-
memcpy(&mac_store.mac48, mac_store.dev_driver->phy_driver->PHY_MAC, 6);
157+
if (driver->phy_driver->link_type == PHY_LINK_PPP) {
158+
memcpy(&mac_store.mac48_iid64, mac_store.dev_driver->phy_driver->PHY_MAC, 8);
159+
} else {
160+
memcpy(&mac_store.mac48_iid64, mac_store.dev_driver->phy_driver->PHY_MAC, 6);
161+
}
149162
if (mac_store.tasklet_id == -1) {
150163
mac_store.tasklet_id = eventOS_event_handler_create(&ethernet_mac_tasklet, ETH_INIT_EVENT);
151164
}
@@ -289,7 +302,7 @@ static int8_t eth_mac_net_phy_rx(const uint8_t *data_ptr, uint16_t data_len, uin
289302

290303
data_len -= 4;
291304
data_ptr += 4;
292-
} else if (driver->phy_driver->link_type == PHY_LINK_SLIP) {
305+
} else if (driver->phy_driver->link_type == PHY_LINK_SLIP || driver->phy_driver->link_type == PHY_LINK_PPP) {
293306
data_ind->etehernet_type = ETHERTYPE_IPV6;
294307
}
295308

@@ -357,10 +370,10 @@ static int8_t mac48_address_set(const eth_mac_api_t *api, const uint8_t *mac48)
357370
if (!mac48 || !api || mac_store.mac_api != api) {
358371
return -1;
359372
}
360-
memcpy(mac_store.mac48, mac48, 6);
373+
memcpy(mac_store.mac48_iid64, mac48, 6);
361374
phy_device_driver_s *driver = mac_store.dev_driver->phy_driver;
362375
if (driver->address_write) {
363-
driver->address_write(PHY_MAC_48BIT, mac_store.mac48);
376+
driver->address_write(PHY_MAC_48BIT, mac_store.mac48_iid64);
364377
}
365378
return 0;
366379
}
@@ -370,7 +383,30 @@ static int8_t mac48_address_get(const eth_mac_api_t *api, uint8_t *mac48_buf)
370383
if (!mac48_buf || !api || mac_store.mac_api != api) {
371384
return -1;
372385
}
373-
memcpy(&mac_store.mac48, mac_store.dev_driver->phy_driver->PHY_MAC, 6);
374-
memcpy(mac48_buf, mac_store.mac48, 6);
386+
memcpy(&mac_store.mac48_iid64, mac_store.dev_driver->phy_driver->PHY_MAC, 6);
387+
memcpy(mac48_buf, mac_store.mac48_iid64, 6);
388+
return 0;
389+
}
390+
391+
static int8_t iid64_address_set(const eth_mac_api_t *api, const uint8_t *iid64)
392+
{
393+
if (!iid64 || !api || mac_store.mac_api != api) {
394+
return -1;
395+
}
396+
memcpy(mac_store.mac48_iid64, iid64, 8);
397+
phy_device_driver_s *driver = mac_store.dev_driver->phy_driver;
398+
if (driver->address_write) {
399+
driver->address_write(PHY_MAC_48BIT, mac_store.mac48_iid64);
400+
}
401+
return 0;
402+
}
403+
404+
static int8_t iid64_address_get(const eth_mac_api_t *api, uint8_t *iid64_buf)
405+
{
406+
if (!iid64_buf || !api || mac_store.mac_api != api) {
407+
return -1;
408+
}
409+
memcpy(&mac_store.mac48_iid64, mac_store.dev_driver->phy_driver->PHY_MAC, 8);
410+
memcpy(iid64_buf, mac_store.mac48_iid64, 8);
375411
return 0;
376412
}

source/NWK_INTERFACE/Include/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ extern uint8_t nwk_bootsrap_ready(protocol_interface_info_entry_t *cur);
499499
extern protocol_interface_info_entry_t *protocol_stack_interface_info_get(nwk_interface_id nwk_id);
500500
extern bool nwk_interface_compare_mac_address(protocol_interface_info_entry_t *cur, uint_fast8_t addrlen, const uint8_t addr[/*addrlen*/]);
501501
extern protocol_interface_info_entry_t *protocol_stack_interface_generate_ethernet(struct eth_mac_api_s *api);
502+
extern protocol_interface_info_entry_t *protocol_stack_interface_generate_ppp(struct eth_mac_api_s *api);
502503
extern protocol_interface_info_entry_t *protocol_stack_interface_generate_lowpan(struct mac_api_s *api);
503504
extern uint32_t protocol_stack_interface_set_reachable_time(protocol_interface_info_entry_t *cur, uint32_t base_reachable_time);
504505
extern void net_bootsrap_cb_run(uint8_t event);

source/NWK_INTERFACE/protocol_core.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,59 @@ protocol_interface_info_entry_t *protocol_stack_interface_generate_ethernet(eth_
904904
return NULL;
905905
}
906906

907+
void protocol_stack_interface_ppp_addr_notification(struct protocol_interface_info_entry *interface, const struct if_address_entry *addr, if_address_callback_t reason)
908+
{
909+
if (interface->dup_addr_detect_transmits == 0 && !addr_is_ipv6_link_local(addr->address) && reason == ADDR_CALLBACK_DAD_COMPLETE && addr->source == ADDR_SOURCE_SLAAC) {
910+
interface->global_address_available = true;
911+
}
912+
}
913+
914+
protocol_interface_info_entry_t *protocol_stack_interface_generate_ppp(eth_mac_api_t *api)
915+
{
916+
if (!api) {
917+
return NULL;
918+
}
919+
protocol_interface_info_entry_t *new_entry = NULL;
920+
921+
ns_list_foreach(protocol_interface_info_entry_t, cur, &protocol_interface_info_list) {
922+
if (cur->eth_mac_api == api) {
923+
return cur;
924+
}
925+
}
926+
927+
if (api) {
928+
new_entry = protocol_core_interface_ethernet_entry_get(api);
929+
930+
if (new_entry) {
931+
neighbor_cache_init(&(new_entry->neigh_cache));
932+
pan_blacklist_cache_init(&(new_entry->pan_blaclist_cache));
933+
pan_coordinator_blacklist_cache_init(&(new_entry->pan_cordinator_black_list));
934+
ipv6_neighbour_cache_init(&new_entry->ipv6_neighbour_cache, new_entry->id);
935+
addr_max_slaac_entries_set(new_entry, 16);
936+
uint8_t iid64[8];
937+
int8_t error = api->iid64_get(api, iid64);
938+
if (error) {
939+
tr_error("iid64_get failed: %d", error);
940+
ns_dyn_mem_free(new_entry);
941+
return NULL;
942+
}
943+
memcpy(new_entry->iid_slaac, iid64, 8);
944+
memcpy(new_entry->iid_eui64, iid64, 8);
945+
new_entry->send_mld = false; // No mld for PPP
946+
new_entry->dup_addr_detect_transmits = 0; // No duplicate detection for PPP
947+
948+
ns_list_add_to_start(&protocol_interface_info_list, new_entry);
949+
950+
(void) ipv6_route_table_set_max_entries(new_entry->id, ROUTE_RADV, 16);
951+
952+
addr_notification_register(protocol_stack_interface_ppp_addr_notification);
953+
954+
return new_entry;
955+
}
956+
}
957+
return NULL;
958+
}
959+
907960
protocol_interface_info_entry_t *protocol_stack_interface_generate_lowpan(mac_api_t *api)
908961
{
909962
if (!api) {

source/ipv6_stack/protocol_ipv6.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ static uint8_t ethernet_llao_write(protocol_interface_info_entry_t *cur, uint8_t
245245
{
246246
(void) must;
247247
(void) ip_addr;
248+
249+
uint8_t mac_not_set[8] = {0,0,0,0,0,0,0,0};
250+
if (memcmp(cur->mac, mac_not_set, 8) == 0) {
251+
return 0;
252+
}
253+
248254
if (opt_out) {
249255
opt_out[0] = opt_type;
250256
opt_out[1] = 1;

source/libNET/src/ns_net.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,28 @@ int8_t arm_nwk_interface_ethernet_init(eth_mac_api_t *api, const char *interface
701701
#endif
702702
}
703703

704+
extern int8_t arm_nwk_interface_ppp_init(struct eth_mac_api_s *api, const char *interface_name_ptr)
705+
{
706+
#ifdef HAVE_ETHERNET
707+
if (!api) {
708+
return -1;
709+
}
710+
711+
protocol_interface_info_entry_t *cur = protocol_stack_interface_generate_ppp(api);
712+
if (!cur) {
713+
return -3;
714+
}
715+
716+
cur->if_up = ipv6_interface_up;
717+
cur->if_down = ipv6_interface_down;
718+
cur->interface_name = interface_name_ptr;
719+
return cur->id;
720+
#else
721+
(void)api;
722+
(void)interface_name_ptr;
723+
return -2;
724+
#endif
725+
}
704726

705727
int8_t arm_nwk_interface_lowpan_init(mac_api_t *api, char *interface_name_ptr)
706728
{

0 commit comments

Comments
 (0)