@@ -59,8 +59,13 @@ static uint8_t buffer_mem_tx[TX_CTRL_BUF_SIZE * LLCP_TX_CTRL_BUF_COUNT];
5959static struct llcp_mem_pool mem_tx = { .pool = buffer_mem_tx };
6060
6161/* TODO: Determine 'correct' number of ctx */
62- static uint8_t buffer_mem_ctx [PROC_CTX_BUF_SIZE * CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM ];
63- static struct llcp_mem_pool mem_ctx = { .pool = buffer_mem_ctx };
62+ static uint8_t buffer_mem_local_ctx [PROC_CTX_BUF_SIZE * CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM ];
63+ static struct llcp_mem_pool mem_local_ctx = { .pool = buffer_mem_local_ctx };
64+
65+ /* TODO(thoh-ot): Determine 'correct' number of ctx */
66+ static uint8_t buffer_mem_remote_ctx [PROC_CTX_BUF_SIZE *
67+ CONFIG_BT_CTLR_LLCP_REMOTE_PROC_CTX_BUF_NUM ];
68+ static struct llcp_mem_pool mem_remote_ctx = { .pool = buffer_mem_remote_ctx };
6469
6570/*
6671 * LLCP Resource Management
@@ -282,7 +287,7 @@ struct proc_ctx *llcp_create_local_procedure(enum llcp_proc proc)
282287{
283288 struct proc_ctx * ctx ;
284289
285- ctx = create_procedure (proc , & mem_ctx );
290+ ctx = create_procedure (proc , & mem_local_ctx );
286291 if (!ctx ) {
287292 return NULL ;
288293 }
@@ -350,7 +355,7 @@ struct proc_ctx *llcp_create_remote_procedure(enum llcp_proc proc)
350355{
351356 struct proc_ctx * ctx ;
352357
353- ctx = create_procedure (proc , & mem_ctx );
358+ ctx = create_procedure (proc , & mem_remote_ctx );
354359 if (!ctx ) {
355360 return NULL ;
356361 }
@@ -423,8 +428,11 @@ struct proc_ctx *llcp_create_remote_procedure(enum llcp_proc proc)
423428
424429void ull_cp_init (void )
425430{
426- mem_init (mem_ctx .pool , PROC_CTX_BUF_SIZE , CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM ,
427- & mem_ctx .free );
431+ mem_init (mem_local_ctx .pool , PROC_CTX_BUF_SIZE , CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM ,
432+ & mem_local_ctx .free );
433+ mem_init (mem_remote_ctx .pool , PROC_CTX_BUF_SIZE ,
434+ CONFIG_BT_CTLR_LLCP_REMOTE_PROC_CTX_BUF_NUM ,
435+ & mem_remote_ctx .free );
428436 mem_init (mem_tx .pool , TX_CTRL_BUF_SIZE , LLCP_TX_CTRL_BUF_COUNT , & mem_tx .free );
429437
430438#if defined(LLCP_TX_CTRL_BUF_QUEUE_ENABLE )
@@ -1025,13 +1033,19 @@ void ull_cp_rx(struct ll_conn *conn, struct node_rx_pdu *rx)
10251033
10261034#ifdef ZTEST_UNITTEST
10271035
1028- int ctx_buffers_free (void )
1036+ static uint16_t local_ctx_buffers_free (void )
10291037{
1030- int nr_of_free_ctx ;
1038+ return mem_free_count_get (mem_local_ctx .free );
1039+ }
10311040
1032- nr_of_free_ctx = mem_free_count_get (mem_ctx .free );
1041+ static uint16_t remote_ctx_buffers_free (void )
1042+ {
1043+ return mem_free_count_get (mem_remote_ctx .free );
1044+ }
10331045
1034- return nr_of_free_ctx ;
1046+ uint16_t ctx_buffers_free (void )
1047+ {
1048+ return local_ctx_buffers_free () + remote_ctx_buffers_free ();
10351049}
10361050
10371051void test_int_mem_proc_ctx (void )
@@ -1043,28 +1057,29 @@ void test_int_mem_proc_ctx(void)
10431057 ull_cp_init ();
10441058
10451059 nr_of_free_ctx = ctx_buffers_free ();
1046- zassert_equal (nr_of_free_ctx , CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM , NULL );
1060+ zassert_equal (nr_of_free_ctx , CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM +
1061+ CONFIG_BT_CTLR_LLCP_REMOTE_PROC_CTX_BUF_NUM , NULL );
10471062
10481063 for (int i = 0U ; i < CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM ; i ++ ) {
1049- ctx1 = proc_ctx_acquire (& mem_ctx );
1064+ ctx1 = proc_ctx_acquire (& mem_local_ctx );
10501065
10511066 /* The previous acquire should be valid */
10521067 zassert_not_null (ctx1 , NULL );
10531068 }
10541069
1055- nr_of_free_ctx = ctx_buffers_free ();
1070+ nr_of_free_ctx = local_ctx_buffers_free ();
10561071 zassert_equal (nr_of_free_ctx , 0 , NULL );
10571072
1058- ctx2 = proc_ctx_acquire (& mem_ctx );
1073+ ctx2 = proc_ctx_acquire (& mem_local_ctx );
10591074
10601075 /* The last acquire should fail */
10611076 zassert_is_null (ctx2 , NULL );
10621077
10631078 llcp_proc_ctx_release (ctx1 );
1064- nr_of_free_ctx = ctx_buffers_free ();
1079+ nr_of_free_ctx = local_ctx_buffers_free ();
10651080 zassert_equal (nr_of_free_ctx , 1 , NULL );
10661081
1067- ctx1 = proc_ctx_acquire (& mem_ctx );
1082+ ctx1 = proc_ctx_acquire (& mem_local_ctx );
10681083
10691084 /* Releasing returns the context to the avilable pool */
10701085 zassert_not_null (ctx1 , NULL );
@@ -1141,7 +1156,7 @@ void test_int_create_proc(void)
11411156
11421157 ull_cp_init ();
11431158
1144- ctx = create_procedure (PROC_VERSION_EXCHANGE , & mem_ctx );
1159+ ctx = create_procedure (PROC_VERSION_EXCHANGE , & mem_local_ctx );
11451160 zassert_not_null (ctx , NULL );
11461161
11471162 zassert_equal (ctx -> proc , PROC_VERSION_EXCHANGE , NULL );
@@ -1150,7 +1165,7 @@ void test_int_create_proc(void)
11501165
11511166 for (int i = 0U ; i < CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM ; i ++ ) {
11521167 zassert_not_null (ctx , NULL );
1153- ctx = create_procedure (PROC_VERSION_EXCHANGE , & mem_ctx );
1168+ ctx = create_procedure (PROC_VERSION_EXCHANGE , & mem_local_ctx );
11541169 }
11551170
11561171 zassert_is_null (ctx , NULL );
0 commit comments