Skip to content

Commit cfc50b4

Browse files
committed
mender client: add network connect/disconnect callbacks
1 parent 66c7116 commit cfc50b4

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/main.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,42 @@ net_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struc
111111
/* Print interface information */
112112
net_if_ipv4_addr_foreach(iface, print_dhcpv4_addr, NULL);
113113

114-
/* Application can now process to the initialization of the mender-mcu-client */
114+
/* Indicate the network is available */
115115
k_event_post(&mender_client_events, MENDER_CLIENT_EVENT_NETWORK_UP);
116116
}
117117

118+
/**
119+
* @brief Network connnect callback
120+
* @return MENDER_OK if network is connected following the request, error code otherwise
121+
*/
122+
static mender_err_t
123+
network_connect_cb(void) {
124+
125+
LOG_INF("Mender client connect network");
126+
127+
/* This callback can be used to configure network connection */
128+
/* Note that the application can connect the network before if required */
129+
/* This callback only indicates the mender-client requests network access now */
130+
/* Nothing to do in this example application just return network is available */
131+
return MENDER_OK;
132+
}
133+
134+
/**
135+
* @brief Network release callback
136+
* @return MENDER_OK if network is released following the request, error code otherwise
137+
*/
138+
static mender_err_t
139+
network_release_cb(void) {
140+
141+
LOG_INF("Mender client released network");
142+
143+
/* This callback can be used to release network connection */
144+
/* Note that the application can keep network activated if required */
145+
/* This callback only indicates the mender-client doesn't request network access now */
146+
/* Nothing to do in this example application just return network is released */
147+
return MENDER_OK;
148+
}
149+
118150
/**
119151
* @brief Authentication success callback
120152
* @return MENDER_OK if application is marked valid and success deployment status should be reported to the server, error code otherwise
@@ -240,7 +272,7 @@ main(void) {
240272
net_mgmt_add_event_callback(&mgmt_cb);
241273
net_dhcpv4_start(iface);
242274

243-
/* Wait for mender-mcu-client events */
275+
/* Wait until the network interface is operational */
244276
k_event_wait_all(&mender_client_events, MENDER_CLIENT_EVENT_NETWORK_UP, false, K_FOREVER);
245277

246278
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
@@ -283,7 +315,9 @@ main(void) {
283315
.authentication_poll_interval = 0,
284316
.update_poll_interval = 0,
285317
.recommissioning = false };
286-
mender_client_callbacks_t mender_client_callbacks = { .authentication_success = authentication_success_cb,
318+
mender_client_callbacks_t mender_client_callbacks = { .network_connect = network_connect_cb,
319+
.network_release = network_release_cb,
320+
.authentication_success = authentication_success_cb,
287321
.authentication_failure = authentication_failure_cb,
288322
.deployment_status = deployment_status_cb,
289323
.restart = restart_cb };

0 commit comments

Comments
 (0)