mesh: Friendship clean-up and rewrite
PATCH 1/1 mesh: Friendship clean-up and rewrite
Friendship support re-written such that it can now support multiple nodes (on multiple mesh networks) as friends to remote Low Power Nodes (LPNs). Validated to properly respond to Friend Requests when enabled, and a hard coded Friend Queue size of 32 (FRND_CACHE_MAX).
--- mesh/crypto.c | 4 +- mesh/friend.c | 610 ++++++++------------------------------------------ mesh/friend.h | 7 +- mesh/net.c | 306 ++++++++++++------------- mesh/net.h | 31 ++- mesh/node.c | 2 +- 6 files changed, 264 insertions(+), 696 deletions(-)
mesh/crypto.c +2 -2
@@ -699,7 +699,7 @@ bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,uint16_t this_dst;bool is_segmented; -if (packet_len <14 ) +if (packet_len <10 )return false; this_dst =l_get_be16 (packet +7 );
@@ -730,7 +730,7 @@ bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,uint8_t this_opcode = packet[9 ] &OPCODE_MASK ;if (cookie) - *cookie =l_get_be32 (packet +9 ); + *cookie =l_get_be32 (packet +2 ) ^ packet[6 ];if (opcode) *opcode = this_opcode;
mesh/friend.c +92 -518
841 lines not on this page · raw message
mesh/friend.h +4 -3
@@ -28,9 +28,10 @@void friend_poll (struct mesh_net *net,uint16_t src,bool seq,struct mesh_friend *frnd); -void friend_request (struct mesh_net *net,uint16_t src,uint8_t minReq, -uint8_t delay,uint32_t timeout,uint16_t prev, -uint8_t num_elements,uint16_t cntr,int8_t rssi); +void friend_request (struct mesh_net *net,uint16_t net_idx,uint16_t src, +uint8_t minReq,uint8_t delay,uint32_t timeout, +uint16_t prev,uint8_t num_elements,uint16_t cntr, +int8_t rssi);void friend_clear_confirm (struct mesh_net *net,uint16_t src,uint16_t lpn,uint16_t lpnCounter); void friend_clear(struct mesh_net *net, uint16_t src, uint16_t lpn,
mesh/net.c +141 -165
658 lines not on this page · raw message
mesh/net.h +24 -7
@@ -162,25 +162,40 @@ struct mesh_key_set {uint8_t privacy_key[16 ]; }; +struct friend_neg { +int8_t rssi; +bool clearing; +}; + +struct friend_act { +uint16_t *grp_list; +uint32_t last_hdr; +int16_t grp_cnt; +bool seq; +bool last; +}; +struct mesh_friend {struct mesh_net *net; -struct l_queue *pkt_cache;struct l_timeout *timeout; +struct l_queue *pkt_cache;void *pkt; -uint16_t *grp_list;uint32_t poll_timeout; -uint32_t last_hdr;uint32_t net_key_cur;uint32_t net_key_upd; -uint16_t dst;/* Primary Element unicast addr */ +uint16_t old_friend; +uint16_t net_idx; +uint16_t lp_addr;/* dst; * Primary Element unicast addr */ uint16_t fn_cnt;uint16_t lp_cnt; -int16_t grp_cnt; +uint8_t receive_delay;uint8_t ele_cnt;uint8_t frd;uint8_t frw; -bool seq; -bool last; +union { +struct friend_neg negotiate; +struct friend_act active; + } u; };struct mesh_frnd_pkt {
@@ -360,3 +375,5 @@ void mesh_net_transmit_params_get(struct mesh_net *net, uint8_t *count,struct mesh_prov *mesh_net_get_prov (struct mesh_net *net);void mesh_net_set_prov (struct mesh_net *net,struct mesh_prov *prov);uint32_t mesh_net_get_instant (struct mesh_net *net); +struct l_queue *mesh_net_get_friends (struct mesh_net *net); +struct l_queue *mesh_net_get_negotiations (struct mesh_net *net);
mesh/node.c +1 -1
@@ -531,7 +531,7 @@ static bool init_from_storage(struct mesh_config_node *db_node,if (mode ==MESH_MODE_ENABLED || mode ==MESH_MODE_DISABLED )mesh_net_set_proxy_mode (node->net, mode ==MESH_MODE_ENABLED ); - mode = node->lpn; + mode = node->friend;if (mode ==MESH_MODE_ENABLED || mode ==MESH_MODE_DISABLED )mesh_net_set_friend_mode (node->net, mode ==MESH_MODE_ENABLED );
Signature · 1 line
2.21.0