| 
 | 1 | +/*  | 
 | 2 | + * Copyright (c) 2021, Pelion 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 | +#include "string.h"  | 
 | 19 | +#include "nsconfig.h"  | 
 | 20 | +#include "ns_types.h"  | 
 | 21 | +#include "ns_trace.h"  | 
 | 22 | +#include "MAC/IEEE802_15_4/mac_defines.h"  | 
 | 23 | +#include "MAC/IEEE802_15_4/mac_mode_switch.h"  | 
 | 24 | + | 
 | 25 | +#define TRACE_GROUP "mswc"  | 
 | 26 | + | 
 | 27 | +#define PHR_LEN 2  | 
 | 28 | + | 
 | 29 | + | 
 | 30 | +int8_t ms_build_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t *data_ptr, uint8_t phy_mode_id)  | 
 | 31 | +{  | 
 | 32 | +    (void) rf_ptr, (void) phy_mode_id;  | 
 | 33 | +    if (!data_ptr) {  | 
 | 34 | +        return -1;  | 
 | 35 | +    }  | 
 | 36 | + | 
 | 37 | +    // - Write mode switch and PHY mode id fields  | 
 | 38 | +    // - Calculate checksum  | 
 | 39 | +    // - Calculate parity  | 
 | 40 | + | 
 | 41 | +    // - With successful return value, MAC should start CSMA-CA for a mode switch PHR  | 
 | 42 | +    return 0;  | 
 | 43 | +}  | 
 | 44 | + | 
 | 45 | +int8_t ms_parse_mode_switch_phr(protocol_interface_rf_mac_setup_s *rf_ptr, const uint8_t *data_ptr, uint16_t data_len)  | 
 | 46 | +{  | 
 | 47 | +    (void) rf_ptr;  | 
 | 48 | +    if (data_len != PHR_LEN) {  | 
 | 49 | +        return -1;  | 
 | 50 | +    }  | 
 | 51 | +    if (!data_ptr) {  | 
 | 52 | +        return -1;  | 
 | 53 | +    }  | 
 | 54 | +    tr_info("Received mode switch PHR %s", trace_array(data_ptr, data_len));  | 
 | 55 | + | 
 | 56 | +    // - Validate checksum  | 
 | 57 | +    // - Validate parity  | 
 | 58 | +    // - Read PHY mode id  | 
 | 59 | +    // - Store current configuration  | 
 | 60 | +    // - Resolve new configuration  | 
 | 61 | +    // - Set new configuration  | 
 | 62 | +    // - Set timer/timeout for waiting the frame with new PHY mode  | 
 | 63 | + | 
 | 64 | +    // - With successful return value, MAC should not start new transmissions until a packet is received or reception timed out  | 
 | 65 | +    return 0;  | 
 | 66 | +}  | 
 | 67 | + | 
 | 68 | +void ms_update_mode_switch_state(protocol_interface_rf_mac_setup_s *rf_ptr)  | 
 | 69 | +{  | 
 | 70 | +    (void) rf_ptr;  | 
 | 71 | +    // MAC should call this after any transmission (TX done) and reception  | 
 | 72 | +    // When mode switch PHR was sent, change new configuration here before transmitting data packet  | 
 | 73 | +    // When data packet was sent, switch back to original configuration  | 
 | 74 | +    // When packet was received in new configuration, switch back to original configuration  | 
 | 75 | +    // When reception timeout occurs, switch back to original configuration  | 
 | 76 | +}  | 
0 commit comments