Skip to content

Commit 6a82e7d

Browse files
added parent priority handling. (#1942)
1 parent 7b7f1c1 commit 6a82e7d

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

nanostack/net_thread_test.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,19 @@ int thread_test_extension_name_set(int8_t interface_id, char extension_name[16])
541541
*/
542542
int8_t thread_test_mcast_address_per_message_set(uint8_t value);
543543

544+
/**
545+
* Thread router parent priority set.
546+
*
547+
* This function is used to set parent priority in connectivity TLV.
548+
*
549+
* \param interface_id Network interface ID.
550+
* \param parent_priority value to be set (0x40 High, 0x00 Medium, 0xC0 Low, 0x80 Do not use) .
551+
*
552+
* \return 0, Set OK.
553+
* \return <0 Set Fail.
554+
*/
555+
int thread_test_parent_priority_set(int8_t interface_id, uint8_t parent_priority);
556+
544557
#ifdef __cplusplus
545558
}
546559
#endif

source/6LoWPAN/Thread/thread_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ int thread_info_allocate_and_init(protocol_interface_info_entry_t *cur)
484484
cur->thread_info->version = thread_version; // Default implementation version
485485
cur->thread_info->thread_device_mode = THREAD_DEVICE_MODE_END_DEVICE;
486486
cur->thread_info->childUpdateReqTimer = -1;
487+
cur->thread_info->parent_priority = CONNECTIVITY_PP_INVALID; // default invalid - calculated using child count
487488

488489
thread_routing_init(&cur->thread_info->routing);
489490
thread_network_local_server_data_base_init(&cur->thread_info->localServerDataBase);
@@ -1245,7 +1246,9 @@ uint8_t *thread_connectivity_tlv_write(uint8_t *ptr, protocol_interface_info_ent
12451246
*ptr++ = 10;
12461247

12471248
// determine parent priority
1248-
if ((mode & MLE_DEV_MASK) == MLE_RFD_DEV && (3 * mle_class_rfd_entry_count_get(cur) > 2 * THREAD_MAX_MTD_CHILDREN)) {
1249+
if ((thread->parent_priority & CONNECTIVITY_PP_MASK) != CONNECTIVITY_PP_INVALID) {
1250+
*ptr++ = thread->parent_priority & CONNECTIVITY_PP_MASK;
1251+
} else if ((mode & MLE_DEV_MASK) == MLE_RFD_DEV && (3 * mle_class_rfd_entry_count_get(cur) > 2 * THREAD_MAX_MTD_CHILDREN)) {
12491252
*ptr++ = CONNECTIVITY_PP_LOW;
12501253
} else if (!(mode & MLE_RX_ON_IDLE) && (3 * mle_class_sleepy_entry_count_get(cur) > 2 * THREAD_MAX_SED_CHILDREN)) {
12511254
*ptr++ = CONNECTIVITY_PP_LOW;

source/6LoWPAN/Thread/thread_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ typedef struct thread_info_s {
317317
//uint8_t lastValidRouteMask[8];
318318
int8_t interface_id; //Thread Interface ID
319319
uint8_t version;
320+
uint8_t parent_priority;
320321
uint8_t testMaxActiveRouterIdLimit; //Default for this is 32
321322
uint8_t maxChildCount; //Default for this is 24
322323
uint8_t partition_weighting;

source/6LoWPAN/Thread/thread_test_api.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,3 +1384,27 @@ int thread_test_extension_name_set(int8_t interface_id, char extension_name[16])
13841384
return -1;
13851385
#endif
13861386
}
1387+
1388+
int thread_test_parent_priority_set(int8_t interface_id, uint8_t parent_priority)
1389+
{
1390+
#ifdef HAVE_THREAD
1391+
protocol_interface_info_entry_t *cur;
1392+
1393+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1394+
if (!cur) {
1395+
tr_warn("Invalid interface id");
1396+
return -1;
1397+
}
1398+
1399+
if (!cur->thread_info) {
1400+
tr_warn("Not Thread specific interface");
1401+
return -2;
1402+
}
1403+
cur->thread_info->parent_priority = parent_priority;
1404+
return 0;
1405+
#else
1406+
(void) interface_id;
1407+
(void) parent_priority;
1408+
return -1;
1409+
#endif
1410+
}

0 commit comments

Comments
 (0)