@@ -48,6 +48,14 @@ lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
48
48
phy_param_t phy_param;
49
49
uint8_t max_num_channels;
50
50
51
+ // Check if the PHY layer supports custom channel plans or not.
52
+ get_phy.attribute = PHY_CUSTOM_CHANNEL_PLAN_SUPPORT;
53
+ phy_param = _lora_phy->get_phy_params (&get_phy);
54
+
55
+ if (!phy_param.value ) {
56
+ return LORAWAN_STATUS_SERVICE_UNKNOWN;
57
+ }
58
+
51
59
// Check first how many channels the selected PHY layer supports
52
60
get_phy.attribute = PHY_MAX_NB_CHANNELS;
53
61
phy_param = _lora_phy->get_phy_params (&get_phy);
@@ -91,18 +99,26 @@ lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
91
99
get_phy_params_t get_phy;
92
100
phy_param_t phy_param;
93
101
uint8_t max_num_channels;
94
- uint16_t *channel_masks ;
102
+ uint16_t *channel_mask ;
95
103
uint8_t count = 0 ;
96
104
105
+ // Check if the PHY layer supports custom channel plans or not.
106
+ get_phy.attribute = PHY_CUSTOM_CHANNEL_PLAN_SUPPORT;
107
+ phy_param = _lora_phy->get_phy_params (&get_phy);
108
+
109
+ if (!phy_param.value ) {
110
+ return LORAWAN_STATUS_SERVICE_UNKNOWN;
111
+ }
112
+
97
113
// Check first how many channels the selected PHY layer supports
98
114
get_phy.attribute = PHY_MAX_NB_CHANNELS;
99
115
phy_param = _lora_phy->get_phy_params (&get_phy);
100
116
max_num_channels = (uint8_t ) phy_param.value ;
101
117
102
118
// Now check the Default channel mask
103
- get_phy.attribute = PHY_CHANNELS_MASK ;
119
+ get_phy.attribute = PHY_CHANNEL_MASK ;
104
120
phy_param = _lora_phy->get_phy_params (&get_phy);
105
- channel_masks = phy_param.channel_mask ;
121
+ channel_mask = phy_param.channel_mask ;
106
122
107
123
// Request Mib to get channels
108
124
memset (&mib_confirm, 0 , sizeof (mib_confirm));
@@ -116,7 +132,7 @@ lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
116
132
117
133
for (uint8_t i = 0 ; i < max_num_channels; i++) {
118
134
// skip the channels which are not enabled
119
- if ((channel_masks[ 0 ] & ( 1U << i) ) == 0 ) {
135
+ if (_lora_phy-> mask_bit_test (channel_mask, i ) == 0 ) {
120
136
continue ;
121
137
}
122
138
@@ -143,32 +159,40 @@ lorawan_status_t LoRaMacChannelPlan::remove_plan()
143
159
get_phy_params_t get_phy;
144
160
phy_param_t phy_param;
145
161
uint8_t max_num_channels;
146
- uint16_t *channel_masks;
147
- uint16_t *default_channel_masks;
162
+ uint16_t *channel_mask;
163
+ uint16_t *default_channel_mask;
164
+
165
+ // Check if the PHY layer supports custom channel plans or not.
166
+ get_phy.attribute = PHY_CUSTOM_CHANNEL_PLAN_SUPPORT;
167
+ phy_param = _lora_phy->get_phy_params (&get_phy);
168
+
169
+ if (!phy_param.value ) {
170
+ return LORAWAN_STATUS_SERVICE_UNKNOWN;
171
+ }
148
172
149
173
// Check first how many channels the selected PHY layer supports
150
174
get_phy.attribute = PHY_MAX_NB_CHANNELS;
151
175
phy_param = _lora_phy->get_phy_params (&get_phy);
152
176
max_num_channels = (uint8_t ) phy_param.value ;
153
177
154
178
// Now check the channel mask for enabled channels
155
- get_phy.attribute = PHY_CHANNELS_MASK ;
179
+ get_phy.attribute = PHY_CHANNEL_MASK ;
156
180
phy_param = _lora_phy->get_phy_params (&get_phy);
157
- channel_masks = phy_param.channel_mask ;
181
+ channel_mask = phy_param.channel_mask ;
158
182
159
183
// Now check the channel mask for default channels
160
- get_phy.attribute = PHY_CHANNELS_DEFAULT_MASK ;
184
+ get_phy.attribute = PHY_DEFAULT_CHANNEL_MASK ;
161
185
phy_param = _lora_phy->get_phy_params (&get_phy);
162
- default_channel_masks = phy_param.channel_mask ;
186
+ default_channel_mask = phy_param.channel_mask ;
163
187
164
188
for (uint8_t i = 0 ; i < max_num_channels; i++) {
165
189
// skip any default channels
166
- if ((default_channel_masks[ 0 ] & ( 1U <<i) ) != 0 ) {
190
+ if (_lora_phy-> mask_bit_test (default_channel_mask, i ) != 0 ) {
167
191
continue ;
168
192
}
169
193
170
194
// skip any channels which are not currently enabled
171
- if ((channel_masks[ 0 ] & ( 1U <<i) ) == 0 ) {
195
+ if (_lora_phy-> mask_bit_test (channel_mask, i ) == 0 ) {
172
196
continue ;
173
197
}
174
198
@@ -187,7 +211,14 @@ lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
187
211
get_phy_params_t get_phy;
188
212
phy_param_t phy_param;
189
213
uint8_t max_num_channels;
190
- uint16_t *channel_masks;
214
+
215
+ // Check if the PHY layer supports custom channel plans or not.
216
+ get_phy.attribute = PHY_CUSTOM_CHANNEL_PLAN_SUPPORT;
217
+ phy_param = _lora_phy->get_phy_params (&get_phy);
218
+
219
+ if (!phy_param.value ) {
220
+ return LORAWAN_STATUS_SERVICE_UNKNOWN;
221
+ }
191
222
192
223
// Check first how many channels the selected PHY layer supports
193
224
get_phy.attribute = PHY_MAX_NB_CHANNELS;
@@ -201,21 +232,7 @@ lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
201
232
return LORAWAN_STATUS_PARAMETER_INVALID;
202
233
}
203
234
204
- // Now check the Default channel mask
205
- get_phy.attribute = PHY_CHANNELS_DEFAULT_MASK;
206
- phy_param = _lora_phy->get_phy_params (&get_phy);
207
- channel_masks = phy_param.channel_mask ;
208
-
209
- // check if the channel ID give belongs to a default channel
210
- // Mostly the default channels are in the first mask if the region
211
- // have multiple channel masks for various sub-bands. So we check the first
212
- // mask only and return an error code if user sent a default channel id
213
- if ((channel_masks[0 ] & (1U << channel_id)) != 0 ) {
214
- return LORAWAN_STATUS_PARAMETER_INVALID;
215
- }
216
-
217
- if (_lora_phy->remove_channel (channel_id) == false )
218
- {
235
+ if (_lora_phy->remove_channel (channel_id) == false ) {
219
236
return LORAWAN_STATUS_PARAMETER_INVALID;
220
237
}
221
238
0 commit comments