@@ -1547,51 +1547,51 @@ lorawan_status_t LoRaMac::send_frame_on_channel(uint8_t channel)
1547
1547
return LORAWAN_STATUS_OK;
1548
1548
}
1549
1549
1550
- lorawan_status_t LoRaMac::set_tx_continuous_wave (uint16_t timeout)
1551
- {
1552
- cw_mode_params_t continuous_wave;
1550
+ // lorawan_status_t LoRaMac::set_tx_continuous_wave(uint16_t timeout)
1551
+ // {
1552
+ // cw_mode_params_t continuous_wave;
1553
1553
1554
- continuous_wave.channel = _params.channel ;
1555
- continuous_wave.datarate = _params.sys_params .channel_data_rate ;
1556
- continuous_wave.tx_power = _params.sys_params .channel_tx_power ;
1557
- continuous_wave.max_eirp = _params.sys_params .max_eirp ;
1558
- continuous_wave.antenna_gain = _params.sys_params .antenna_gain ;
1559
- continuous_wave.timeout = timeout;
1554
+ // continuous_wave.channel = _params.channel;
1555
+ // continuous_wave.datarate = _params.sys_params.channel_data_rate;
1556
+ // continuous_wave.tx_power = _params.sys_params.channel_tx_power;
1557
+ // continuous_wave.max_eirp = _params.sys_params.max_eirp;
1558
+ // continuous_wave.antenna_gain = _params.sys_params.antenna_gain;
1559
+ // continuous_wave.timeout = timeout;
1560
1560
1561
- lora_phy->set_tx_cont_mode (&continuous_wave);
1561
+ // lora_phy->set_tx_cont_mode(&continuous_wave);
1562
1562
1563
- // Starts the MAC layer status check timer
1564
- _lora_time.start (_params.timers .mac_state_check_timer ,
1565
- MAC_STATE_CHECK_TIMEOUT);
1563
+ // // Starts the MAC layer status check timer
1564
+ // _lora_time.start(_params.timers.mac_state_check_timer,
1565
+ // MAC_STATE_CHECK_TIMEOUT);
1566
1566
1567
- _params.mac_state |= LORAMAC_TX_RUNNING;
1567
+ // _params.mac_state |= LORAMAC_TX_RUNNING;
1568
1568
1569
- return LORAWAN_STATUS_OK;
1570
- }
1569
+ // return LORAWAN_STATUS_OK;
1570
+ // }
1571
1571
1572
- lorawan_status_t LoRaMac::set_tx_continuous_wave1 (uint16_t timeout,
1573
- uint32_t frequency,
1574
- uint8_t power)
1575
- {
1576
- cw_mode_params_t continuous_wave;
1572
+ // lorawan_status_t LoRaMac::set_tx_continuous_wave1(uint16_t timeout,
1573
+ // uint32_t frequency,
1574
+ // uint8_t power)
1575
+ // {
1576
+ // cw_mode_params_t continuous_wave;
1577
1577
1578
- continuous_wave.channel = 0 ;
1579
- continuous_wave.datarate = 0 ;
1580
- continuous_wave.tx_power = power;
1581
- continuous_wave.max_eirp = 0 ;
1582
- continuous_wave.antenna_gain = 0 ;
1583
- continuous_wave.timeout = timeout;
1578
+ // continuous_wave.channel = 0;
1579
+ // continuous_wave.datarate = 0;
1580
+ // continuous_wave.tx_power = power;
1581
+ // continuous_wave.max_eirp = 0;
1582
+ // continuous_wave.antenna_gain = 0;
1583
+ // continuous_wave.timeout = timeout;
1584
1584
1585
- lora_phy->set_tx_cont_mode (&continuous_wave);
1585
+ // lora_phy->set_tx_cont_mode(&continuous_wave);
1586
1586
1587
- // Starts the MAC layer status check timer
1588
- _lora_time.start (_params.timers .mac_state_check_timer ,
1589
- MAC_STATE_CHECK_TIMEOUT);
1587
+ // // Starts the MAC layer status check timer
1588
+ // _lora_time.start(_params.timers.mac_state_check_timer,
1589
+ // MAC_STATE_CHECK_TIMEOUT);
1590
1590
1591
- _params.mac_state |= LORAMAC_TX_RUNNING;
1591
+ // _params.mac_state |= LORAMAC_TX_RUNNING;
1592
1592
1593
- return LORAWAN_STATUS_OK;
1594
- }
1593
+ // return LORAWAN_STATUS_OK;
1594
+ // }
1595
1595
1596
1596
lorawan_status_t LoRaMac::initialize (loramac_primitives_t *primitives,
1597
1597
LoRaPHY *phy, EventQueue *queue)
@@ -1606,13 +1606,13 @@ lorawan_status_t LoRaMac::initialize(loramac_primitives_t *primitives,
1606
1606
lora_phy = phy;
1607
1607
1608
1608
// Activate MLME subsystem
1609
- mlme.activate_mlme_subsystem (this , lora_phy);
1609
+ mlme.activate_mlme_subsystem (lora_phy);
1610
1610
1611
1611
// Activate MCPS subsystem
1612
1612
mcps.activate_mcps_subsystem (this , lora_phy);
1613
1613
1614
1614
// Activate MIB subsystem
1615
- mib.activate_mib_subsystem (this , lora_phy);
1615
+ mib.activate_mib_subsystem (lora_phy);
1616
1616
1617
1617
// Activate channel planning subsystem
1618
1618
channel_plan.activate_channelplan_subsystem (lora_phy);
@@ -1878,10 +1878,74 @@ lorawan_status_t LoRaMac::multicast_channel_unlink(
1878
1878
1879
1879
lorawan_status_t LoRaMac::mlme_request ( loramac_mlme_req_t *mlmeRequest )
1880
1880
{
1881
- lorawan_status_t status = mlme.set_request (mlmeRequest, &_params);
1881
+ if (LORAMAC_IDLE != _params.mac_state ) {
1882
+ return LORAWAN_STATUS_BUSY;
1883
+ }
1884
+ if (MLME_JOIN == mlmeRequest->type ) {
1885
+ reset_mac_parameters ();
1886
+ }
1887
+
1888
+ mlme.reset_confirmation ();
1889
+
1890
+ mlme.get_confirmation ().req_type = mlmeRequest->type ;
1891
+ _params.flags .bits .mlme_req = 1 ;
1892
+
1893
+ lorawan_status_t status = LORAWAN_STATUS_SERVICE_UNKNOWN;
1894
+
1882
1895
if (MLME_LINK_CHECK == mlmeRequest->type ) {
1883
1896
status = mac_commands.add_mac_command (MOTE_MAC_LINK_CHECK_REQ, 0 , 0 );
1897
+ } else if (MLME_JOIN == mlmeRequest->type ) {
1898
+ if ((_params.mac_state & LORAMAC_TX_DELAYED) == LORAMAC_TX_DELAYED) {
1899
+ return LORAWAN_STATUS_BUSY;
1900
+ }
1901
+
1902
+ if ((mlmeRequest->req .join .dev_eui == NULL )
1903
+ || (mlmeRequest->req .join .app_eui == NULL )
1904
+ || (mlmeRequest->req .join .app_key == NULL )
1905
+ || (mlmeRequest->req .join .nb_trials == 0 )) {
1906
+ return LORAWAN_STATUS_PARAMETER_INVALID;
1907
+ }
1908
+ _params.keys .dev_eui = mlmeRequest->req .join .dev_eui ;
1909
+ _params.keys .app_eui = mlmeRequest->req .join .app_eui ;
1910
+ _params.keys .app_key = mlmeRequest->req .join .app_key ;
1911
+ _params.max_join_request_trials = mlmeRequest->req .join .nb_trials ;
1912
+
1913
+ if (!lora_phy->verify_nb_join_trials (mlmeRequest->req .join .nb_trials )) {
1914
+ // Value not supported, get default
1915
+ _params.max_join_request_trials = lora_phy->get_nb_join_trials (true );
1916
+ }
1917
+ // Reset variable JoinRequestTrials
1918
+ _params.join_request_trial_counter = 0 ;
1919
+ _params.sys_params .channel_data_rate =
1920
+ lora_phy->get_alternate_DR (_params.join_request_trial_counter + 1 );
1921
+
1922
+ loramac_mhdr_t machdr;
1923
+ machdr.value = 0 ;
1924
+ machdr.bits .mtype = FRAME_TYPE_JOIN_REQ;
1925
+ status = send (&machdr, 0 , NULL , 0 );
1926
+ } else if (MLME_TXCW == mlmeRequest->type ) {
1927
+ mlme.set_tx_continuous_wave (_params.channel , _params.sys_params .channel_data_rate , _params.sys_params .channel_tx_power ,
1928
+ _params.sys_params .max_eirp , _params.sys_params .antenna_gain , mlmeRequest->req .cw_tx_mode .timeout );
1929
+ _lora_time.start (_params.timers .mac_state_check_timer ,
1930
+ MAC_STATE_CHECK_TIMEOUT);
1931
+
1932
+ _params.mac_state |= LORAMAC_TX_RUNNING;
1933
+ status = LORAWAN_STATUS_OK;
1934
+ } else if (MLME_TXCW_1 == mlmeRequest->type ) {
1935
+ mlme.set_tx_continuous_wave (0 , 0 , mlmeRequest->req .cw_tx_mode .power , 0 , 0 , mlmeRequest->req .cw_tx_mode .timeout );
1936
+ _lora_time.start (_params.timers .mac_state_check_timer ,
1937
+ MAC_STATE_CHECK_TIMEOUT);
1938
+
1939
+ _params.mac_state |= LORAMAC_TX_RUNNING;
1940
+ status = LORAWAN_STATUS_OK;
1884
1941
}
1942
+
1943
+ if (status != LORAWAN_STATUS_OK) {
1944
+ _params.is_node_ack_requested = false ;
1945
+ _params.flags .bits .mlme_req = 0 ;
1946
+ }
1947
+
1948
+
1885
1949
return status;
1886
1950
}
1887
1951
@@ -1903,7 +1967,12 @@ lorawan_status_t LoRaMac::mib_get_request_confirm( loramac_mib_req_confirm_t *mi
1903
1967
1904
1968
lorawan_status_t LoRaMac::mib_set_request_confirm ( loramac_mib_req_confirm_t *mibSet )
1905
1969
{
1906
- return mib.set_request (mibSet, &_params);
1970
+ lorawan_status_t status = mib.set_request (mibSet, &_params);
1971
+ if (LORAWAN_STATUS_OK == status && CLASS_C == _params.dev_class && (MIB_DEVICE_CLASS == mibSet->type ||
1972
+ (MIB_RX2_CHANNEL == mibSet->type && _params.is_nwk_joined ))) {
1973
+ open_continuous_rx2_window ();
1974
+ }
1975
+ return status;
1907
1976
}
1908
1977
1909
1978
radio_events_t *LoRaMac::get_phy_event_handlers ()
0 commit comments