Skip to content

Commit fd9fbb2

Browse files
SeppoTakalocarlescufi
authored andcommitted
net: nrf_provisioning: Move all processing into own workq
Define a worke queue, instead of thread and run all longer running processes from this work queue. Refactor the previous background thread to be a delayable work item for this queue. This way we don't accidentally block system work queue on initialization phase. Signed-off-by: Seppo Takalo <[email protected]>
1 parent ac1f02e commit fd9fbb2

File tree

9 files changed

+358
-344
lines changed

9 files changed

+358
-344
lines changed

include/net/nrf_provisioning.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ struct nrf_provisioning_dm_change {
9191
* Feeding a null as a callback address means that the corresponding default callback function is
9292
* taken into use.
9393
*
94+
* This function return immediately after configuring the callbacks and schedules
95+
* longer initialization work to be done in the background.
96+
*
9497
* @param mmode Modem mode change callback. Used when data is written to modem.
9598
* @param dmode Device mode callback. Used when provisioning state changes.
9699
* @return <0 on error, 0 on success.

samples/cellular/nrf_provisioning/src/main.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,6 @@ static void device_mode_cb(enum nrf_provisioning_event event, void *user_data)
133133
static struct nrf_provisioning_mm_change mmode = { .cb = modem_mode_cb, .user_data = NULL };
134134
static struct nrf_provisioning_dm_change dmode = { .cb = device_mode_cb, .user_data = NULL };
135135

136-
/* Work item to initialize the provisioning library and start checking for provisioning commands.
137-
* Called automatically the first time network connectivity is established.
138-
* Needs to be a work item since nrf_provisioning_init may attempt to install certs in a blocking
139-
* fashion.
140-
*/
141-
static void start_provisioning_work_fn(struct k_work *work)
142-
{
143-
LOG_INF("Initializing the nRF Provisioning library...");
144-
145-
int ret = nrf_provisioning_init(&mmode, &dmode);
146-
147-
if (ret) {
148-
LOG_ERR("Failed to initialize provisioning client, error: %d", ret);
149-
}
150-
}
151-
152-
static K_WORK_DEFINE(start_provisioning_work, start_provisioning_work_fn);
153-
154136
/* Callback to track network connectivity */
155137
static struct net_mgmt_event_callback l4_callback;
156138
static void l4_event_handler(struct net_mgmt_event_callback *cb,
@@ -166,13 +148,15 @@ static void l4_event_handler(struct net_mgmt_event_callback *cb,
166148
k_event_clear(&prov_events, NETWORK_DOWN);
167149
k_event_post(&prov_events, NETWORK_UP);
168150

169-
/* Start the provisioning library after network readiness is first established.
170-
* We offload this to a workqueue item to avoid a deadlock.
171-
* (nrf_provisioning_init might attempt to install certs, and in the process,
172-
* trigger a blocking wait for L4_DOWN, which cannot fire until this handler exits.)
173-
*/
151+
/* Start the provisioning library after network readiness is first established. */
174152
if (!provisioning_started) {
175-
k_work_submit(&start_provisioning_work);
153+
LOG_INF("Initializing the nRF Provisioning library...");
154+
155+
int ret = nrf_provisioning_init(&mmode, &dmode);
156+
157+
if (ret) {
158+
LOG_ERR("Failed to initialize provisioning client, error: %d", ret);
159+
}
176160
provisioning_started = true;
177161
}
178162
}

subsys/net/lib/nrf_provisioning/include/nrf_provisioning_internal.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
extern "C" {
1717
#endif
1818

19-
/**
20-
* @brief Background provisioning service - assumed to run in its own thread.
21-
*
22-
* Revealed only to be able to test the functionality.
23-
*/
24-
int nrf_provisioning_req(void);
25-
2619
/**
2720
* @brief Seconds to next provisioning
2821
*

0 commit comments

Comments
 (0)