Skip to content

Commit 035af9a

Browse files
author
Juha Heiskanen
committed
Enhanced ACK GEN and TX update
Added verification that securd enhanced ACK isonly sended to device which is at device table. Seperated ACK build and buffer init functionality to own function. Change-Id: Ib8bda4117b4754a52b5fa0a1c11d1b7bc6e0f876
1 parent f786fc9 commit 035af9a

File tree

16 files changed

+239
-140
lines changed

16 files changed

+239
-140
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2019, Arm Limited and affiliates.
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 MAC_DATA_BUFFER_H_
19+
#define MAC_DATA_BUFFER_H_
20+
21+
#include "mac_mcps.h"
22+
23+
/**
24+
* @brief struct mac_aux_security_header_t MAC auxiliarity security header structure
25+
* INTERNAL use only
26+
*/
27+
typedef struct mac_aux_security_header_s {
28+
uint32_t frameCounter;
29+
uint8_t Keysource[8];
30+
uint8_t KeyIndex;
31+
unsigned securityLevel: 3;
32+
unsigned KeyIdMode: 2;
33+
} mac_aux_security_header_t;
34+
35+
typedef struct mac_fcf_sequence_s {
36+
unsigned frametype: 3;
37+
bool securityEnabled: 1;
38+
bool framePending : 1;
39+
bool ackRequested: 1;
40+
bool intraPan: 1;
41+
bool sequenceNumberSuppress: 1;
42+
bool informationElementsPresets: 1;
43+
bool DstPanPresents: 1;
44+
bool SrcPanPresents: 1;
45+
unsigned DstAddrMode: 2; /*0x00 = no address 0x01 = reserved 0x02 = 16-bit short address 0x03 = 64-bit extended address */
46+
unsigned frameVersion: 2;
47+
unsigned SrcAddrMode: 2; /*0x00 = no address 0x01 = reserved 0x02 = 16-bit short address 0x03 = 64-bit extended address */
48+
uint8_t DSN;
49+
} mac_fcf_sequence_t;
50+
51+
typedef struct mac_pre_parsed_frame_s {
52+
void *mac_class_ptr;
53+
uint8_t *payloadsIePtr;
54+
uint8_t *headerIePtr;
55+
uint8_t *macPayloadPtr;
56+
mlme_device_descriptor_t *neigh_info;
57+
uint32_t timestamp;
58+
mac_fcf_sequence_t fcf_dsn;
59+
uint16_t frameLength; //Encoded or open payload length
60+
uint16_t payloadsIeLength;
61+
uint16_t headerIeLength;
62+
uint16_t mac_header_length;
63+
uint16_t header_ie_length;
64+
uint16_t mac_payload_length;
65+
uint8_t security_aux_header_length;
66+
uint8_t LQI;
67+
int8_t dbm;
68+
bool ack_pendinfg_status;
69+
uint8_t buf[]; /*!< Trailing buffer data */
70+
} mac_pre_parsed_frame_t;
71+
72+
typedef struct mac_pre_build_frame {
73+
mac_fcf_sequence_t fcf_dsn;
74+
uint16_t DstPANId;
75+
uint8_t DstAddr[8];
76+
uint16_t SrcPANId;
77+
uint8_t SrcAddr[8];
78+
mac_aux_security_header_t aux_header;
79+
uint8_t mac_command_id; //For MLME
80+
uint16_t payloadsIeLength;
81+
uint16_t headerIeLength;
82+
uint16_t mac_payload_length;
83+
uint16_t mac_header_length_with_security;
84+
uint8_t msduHandle;
85+
uint16_t buffer_ttl;
86+
struct mcps_data_req_ie_list ie_elements;
87+
struct channel_list_s asynch_channel_list;
88+
uint8_t *mac_payload;
89+
uint8_t status;
90+
uint8_t asynch_channel;
91+
uint8_t csma_periods_left;
92+
uint8_t fhss_retry_count;
93+
uint8_t fhss_cca_retry_count;
94+
uint32_t tx_time;
95+
bool upper_layer_request: 1;
96+
bool mac_allocated_payload_ptr: 1;
97+
bool asynch_request: 1;
98+
bool message_builded: 1;
99+
unsigned security_mic_len: 5; //Max possible lengths 0, 4, 8, 16 bytes
100+
unsigned priority: 2;
101+
struct mac_pre_build_frame *next; //Pointer for queue purpose
102+
} mac_pre_build_frame_t;
103+
104+
105+
#endif /* MAC_DATA_BUFFER_H_ */

source/MAC/IEEE802_15_4/mac_defines.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "eventOS_event.h"
2222
#include "mlme.h"
23+
#include "mac_data_buffer.h"
2324
#include "ns_list.h"
2425

2526
struct cca_structure_s;
@@ -186,6 +187,7 @@ typedef struct protocol_interface_rf_mac_setup {
186187
bool macBroadcastDisabled: 1;
187188
bool scan_active: 1;
188189
bool rf_csma_extension_supported: 1;
190+
bool ack_tx_possible: 1;
189191
/* CSMA Params */
190192
unsigned macMinBE: 4;
191193
unsigned macMaxBE: 4;
@@ -224,6 +226,8 @@ typedef struct protocol_interface_rf_mac_setup {
224226
uint16_t multi_cca_interval; /**< Length of the additional CSMA-CA period(s) in microseconds */
225227
/* Indirect queue parameters */
226228
struct mac_pre_build_frame *indirect_pd_data_request_queue;
229+
struct mac_pre_build_frame enhanced_ack_buffer;
230+
uint32_t enhanced_ack_handler_timestamp;
227231
arm_event_t mac_mcps_timer_event;
228232
uint16_t indirect_pending_bytes;
229233
arm_nwk_mlme_event_type_e mac_mlme_event;

source/MAC/IEEE802_15_4/mac_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "mac_filter_api.h"
2626
#include "mac_filter.h"
2727
#include "mac_common_defines.h"
28-
28+
#include "mac_defines.h"
2929
#include "mac_mcps.h"
3030
#include "MAC/IEEE802_15_4/mac_mcps_sap.h"
3131
#include "MAC/IEEE802_15_4/mac_header_helper_functions.h"

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static ns_mem_heap_size_t ns_dyn_mem_rate_limiting_threshold = 0xFFFFFFFF;
8383
* \return Timestamp from PHY
8484
*
8585
*/
86-
static uint32_t mac_mcps_sap_get_phy_timestamp(protocol_interface_rf_mac_setup_s *rf_mac_setup)
86+
uint32_t mac_mcps_sap_get_phy_timestamp(protocol_interface_rf_mac_setup_s *rf_mac_setup)
8787
{
8888
uint32_t timestamp;
8989
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_TIMESTAMP, (uint8_t *)&timestamp);
@@ -1589,15 +1589,12 @@ static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_pt
15891589
return 0;
15901590
}
15911591

1592-
int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const mac_fcf_sequence_t *fcf, const uint8_t *data_ptr, const mcps_ack_data_payload_t *ack_payload)
1592+
int8_t mcps_generic_ack_data_request_init(protocol_interface_rf_mac_setup_s *rf_ptr, const mac_fcf_sequence_t *fcf, const uint8_t *data_ptr, const mcps_ack_data_payload_t *ack_payload)
15931593
{
1594-
phy_device_driver_s *dev_driver = rf_ptr->dev_driver->phy_driver;
1595-
dev_driver_tx_buffer_s *tx_buf = &rf_ptr->dev_driver_tx_buffer;
1596-
1597-
ccm_globals_t ccm_ptr;
1594+
mac_pre_build_frame_t *buffer = &rf_ptr->enhanced_ack_buffer;
1595+
//save timestamp
1596+
rf_ptr->enhanced_ack_handler_timestamp = mac_mcps_sap_get_phy_timestamp(rf_ptr);
15981597

1599-
mac_pre_build_frame_t pd_act_buf;
1600-
mac_pre_build_frame_t *buffer = &pd_act_buf;
16011598
memset(buffer, 0, sizeof(mac_pre_build_frame_t));
16021599
buffer->fcf_dsn.frametype = FC_ACK_FRAME;
16031600
buffer->fcf_dsn.frameVersion = fcf->frameVersion;
@@ -1609,6 +1606,7 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m
16091606
buffer->fcf_dsn.SrcAddrMode = fcf->DstAddrMode;
16101607
buffer->fcf_dsn.SrcPanPresents = fcf->SrcPanPresents;
16111608
buffer->fcf_dsn.DstAddrMode = fcf->SrcAddrMode;
1609+
16121610
if (buffer->fcf_dsn.sequenceNumberSuppress) {
16131611
buffer->mac_header_length_with_security = 2;
16141612
} else {
@@ -1642,8 +1640,6 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m
16421640

16431641
}
16441642

1645-
1646-
//TODO Request Application data to ACK
16471643
uint16_t ie_header_length = 0;
16481644
uint16_t ie_payload_length = 0;
16491645

@@ -1666,15 +1662,31 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m
16661662

16671663
//This will prepare MHR length with Header IE
16681664
mac_header_information_elements_preparation(buffer);
1665+
return 0;
1666+
}
1667+
1668+
1669+
int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, bool init_build)
1670+
{
1671+
phy_device_driver_s *dev_driver = rf_ptr->dev_driver->phy_driver;
1672+
dev_driver_tx_buffer_s *tx_buf = &rf_ptr->dev_driver_tx_buffer;
1673+
1674+
ccm_globals_t ccm_ptr;
1675+
mac_pre_build_frame_t *buffer = &rf_ptr->enhanced_ack_buffer;
1676+
16691677

16701678
if (buffer->fcf_dsn.securityEnabled) {
16711679
//Remember to update security counter here!
1672-
buffer->aux_header.frameCounter = mac_mlme_framecounter_get(rf_ptr);
1680+
if (init_build) {
1681+
buffer->aux_header.frameCounter = mac_mlme_framecounter_get(rf_ptr);
1682+
}
16731683
if (!mac_frame_security_parameters_init(&ccm_ptr, rf_ptr, buffer)) {
16741684
return -2;
16751685
}
1676-
//Increment security counter
1677-
mac_mlme_framecounter_increment(rf_ptr);
1686+
if (init_build) {
1687+
//Increment security counter
1688+
mac_mlme_framecounter_increment(rf_ptr);
1689+
}
16781690
}
16791691

16801692
//Calculate Payload length here with IE extension

source/MAC/IEEE802_15_4/mac_mcps_sap.h

Lines changed: 6 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
#include "mlme.h"
2929
#include "mac_common_defines.h"
30+
#include "mac_data_buffer.h"
3031

3132
struct protocol_interface_rf_mac_setup;
3233
struct mcps_data_req_s;
3334
struct arm_phy_sap_msg_s;
3435
struct mcps_purge_s;
35-
struct mcps_data_ie_list;
3636
struct mcps_data_req_ie_list;
3737
struct channel_list_s;
3838

@@ -62,88 +62,6 @@ typedef enum {
6262
// Interval between two CCA checks
6363
#define MAC_DEFAULT_CSMA_MULTI_CCA_INTERVAL 1000
6464

65-
/**
66-
* @brief struct mac_aux_security_header_t MAC auxiliarity security header structure
67-
* INTERNAL use only
68-
*/
69-
typedef struct mac_aux_security_header_s {
70-
unsigned securityLevel: 3;
71-
unsigned KeyIdMode: 2;
72-
uint32_t frameCounter;
73-
uint8_t Keysource[8];
74-
uint8_t KeyIndex;
75-
} mac_aux_security_header_t;
76-
77-
typedef struct mac_fcf_sequence_s {
78-
unsigned frametype: 3;
79-
bool securityEnabled: 1;
80-
bool framePending : 1;
81-
bool ackRequested: 1;
82-
bool intraPan: 1;
83-
bool sequenceNumberSuppress: 1;
84-
bool informationElementsPresets: 1;
85-
bool DstPanPresents: 1;
86-
bool SrcPanPresents: 1;
87-
unsigned DstAddrMode: 2; /*0x00 = no address 0x01 = reserved 0x02 = 16-bit short address 0x03 = 64-bit extended address */
88-
unsigned frameVersion: 2;
89-
unsigned SrcAddrMode: 2; /*0x00 = no address 0x01 = reserved 0x02 = 16-bit short address 0x03 = 64-bit extended address */
90-
uint8_t DSN;
91-
} mac_fcf_sequence_t;
92-
93-
typedef struct mac_pre_parsed_frame_s {
94-
void *mac_class_ptr;
95-
uint8_t *payloadsIePtr;
96-
uint8_t *headerIePtr;
97-
uint8_t *macPayloadPtr;
98-
mlme_device_descriptor_t *neigh_info;
99-
uint8_t LQI;
100-
int8_t dbm;
101-
mac_fcf_sequence_t fcf_dsn;
102-
uint16_t frameLength; //Encoded or open payload length
103-
uint16_t payloadsIeLength;
104-
uint16_t headerIeLength;
105-
uint16_t mac_header_length;
106-
uint16_t header_ie_length;
107-
uint8_t security_aux_header_length;
108-
uint16_t mac_payload_length;
109-
uint32_t timestamp;
110-
bool ack_pendinfg_status;
111-
112-
uint8_t buf[]; /*!< Trailing buffer data */
113-
} mac_pre_parsed_frame_t;
114-
115-
typedef struct mac_pre_build_frame {
116-
mac_fcf_sequence_t fcf_dsn;
117-
uint16_t DstPANId;
118-
uint8_t DstAddr[8];
119-
uint16_t SrcPANId;
120-
uint8_t SrcAddr[8];
121-
mac_aux_security_header_t aux_header;
122-
uint8_t mac_command_id; //For MLME
123-
uint16_t payloadsIeLength;
124-
uint16_t headerIeLength;
125-
uint16_t mac_payload_length;
126-
uint16_t mac_header_length_with_security;
127-
uint8_t msduHandle;
128-
uint16_t buffer_ttl;
129-
struct mcps_data_req_ie_list ie_elements;
130-
struct channel_list_s asynch_channel_list;
131-
uint8_t *mac_payload;
132-
uint8_t status;
133-
uint8_t asynch_channel;
134-
uint8_t csma_periods_left;
135-
uint8_t fhss_retry_count;
136-
uint8_t fhss_cca_retry_count;
137-
uint32_t tx_time;
138-
bool upper_layer_request;
139-
bool mac_allocated_payload_ptr: 1;
140-
bool asynch_request: 1;
141-
bool message_builded: 1;
142-
unsigned security_mic_len: 5; //Max possible lengths 0, 4, 8, 16 bytes
143-
unsigned priority: 2;
144-
struct mac_pre_build_frame *next; //Pointer for queue purpose
145-
} mac_pre_build_frame_t;
146-
14765

14866
void mac_generic_event_trig(uint8_t event_type, void *mac_ptr, bool low_latency);
14967

@@ -214,8 +132,12 @@ uint8_t mcps_sap_purge_reg_handler(struct protocol_interface_rf_mac_setup *rf_ma
214132

215133
int8_t mcps_pd_data_rebuild(struct protocol_interface_rf_mac_setup *rf_ptr, mac_pre_build_frame_t *buffer);
216134

217-
int8_t mcps_generic_ack_build(struct protocol_interface_rf_mac_setup *rf_ptr, const mac_fcf_sequence_t *fcf, const uint8_t *data_ptr, const mcps_ack_data_payload_t *ack_payload);
135+
int8_t mcps_generic_ack_data_request_init(struct protocol_interface_rf_mac_setup *rf_ptr, const mac_fcf_sequence_t *fcf, const uint8_t *data_ptr, const mcps_ack_data_payload_t *ack_payload);
136+
137+
int8_t mcps_generic_ack_build(struct protocol_interface_rf_mac_setup *rf_ptr, bool init_build);
218138

219139
int mcps_packet_ingress_rate_limit_by_memory(uint8_t free_heap_percentage);
220140

141+
uint32_t mac_mcps_sap_get_phy_timestamp(struct protocol_interface_rf_mac_setup *rf_mac_setup);
142+
221143
#endif /* MAC_IEEE802_15_4_MAC_MCPS_SAP_H_ */

0 commit comments

Comments
 (0)