@@ -187,6 +187,66 @@ static int cmd_net_dhcpv4_server_status(const struct shell *sh, size_t argc, cha
187
187
return 0 ;
188
188
}
189
189
190
+ static int cmd_net_dhcpv4_client_start (const struct shell * sh , size_t argc , char * argv [])
191
+ {
192
+ #if defined(CONFIG_NET_DHCPV4 )
193
+ struct net_if * iface = NULL ;
194
+ int idx ;
195
+
196
+ if (argc < 1 ) {
197
+ PR_ERROR ("Correct usage: net dhcpv4 client %s <index>\n" , "start" );
198
+ return - EINVAL ;
199
+ }
200
+
201
+ idx = get_iface_idx (sh , argv [1 ]);
202
+ if (idx < 0 ) {
203
+ return - ENOEXEC ;
204
+ }
205
+
206
+ iface = net_if_get_by_index (idx );
207
+ if (!iface ) {
208
+ PR_WARNING ("No such interface in index %d\n" , idx );
209
+ return - ENOEXEC ;
210
+ }
211
+
212
+ net_dhcpv4_restart (iface );
213
+
214
+ #else /* CONFIG_NET_DHCPV4 */
215
+ PR_INFO ("Set %s to enable %s support.\n" , "CONFIG_NET_DHCPV4" , "DHCPv4" );
216
+ #endif /* CONFIG_NET_DHCPV4 */
217
+ return 0 ;
218
+ }
219
+
220
+ static int cmd_net_dhcpv4_client_stop (const struct shell * sh , size_t argc , char * argv [])
221
+ {
222
+ #if defined(CONFIG_NET_DHCPV4 )
223
+ struct net_if * iface = NULL ;
224
+ int idx ;
225
+
226
+ if (argc < 1 ) {
227
+ PR_ERROR ("Correct usage: net dhcpv4 client %s <index>\n" , "stop" );
228
+ return - EINVAL ;
229
+ }
230
+
231
+ idx = get_iface_idx (sh , argv [1 ]);
232
+ if (idx < 0 ) {
233
+ return - ENOEXEC ;
234
+ }
235
+
236
+ iface = net_if_get_by_index (idx );
237
+ if (!iface ) {
238
+ PR_WARNING ("No such interface in index %d\n" , idx );
239
+ return - ENOEXEC ;
240
+ }
241
+
242
+ net_dhcpv4_stop (iface );
243
+
244
+ #else /* CONFIG_NET_DHCPV4 */
245
+ PR_INFO ("Set %s to enable %s support.\n" , "CONFIG_NET_DHCPV4" , "DHCPv4" );
246
+ #endif /* CONFIG_NET_DHCPV4 */
247
+ return 0 ;
248
+ }
249
+
190
250
SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_dhcpv4_server ,
191
251
SHELL_CMD_ARG (start , NULL , "Start the DHCPv4 server operation on the interface.\n"
192
252
"'net dhcpv4 server start <index> <base address>'\n"
@@ -204,10 +264,25 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_dhcpv4_server,
204
264
SHELL_SUBCMD_SET_END
205
265
);
206
266
267
+ SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_dhcpv4_client ,
268
+ SHELL_CMD_ARG (start , NULL , "Start the DHCPv4 client operation on the interface.\n"
269
+ "'net dhcpv4 client start <index>'\n"
270
+ "<index> is the network interface index." ,
271
+ cmd_net_dhcpv4_client_start , 2 , 0 ),
272
+ SHELL_CMD_ARG (stop , NULL , "Stop the DHCPv4 client operation on the interface.\n"
273
+ "'net dhcpv4 client stop <index>'\n"
274
+ "<index> is the network interface index." ,
275
+ cmd_net_dhcpv4_client_stop , 2 , 0 ),
276
+ SHELL_SUBCMD_SET_END
277
+ );
278
+
207
279
SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_dhcpv4 ,
208
280
SHELL_CMD (server , & net_cmd_dhcpv4_server ,
209
281
"DHCPv4 server service management." ,
210
282
NULL ),
283
+ SHELL_CMD (client , & net_cmd_dhcpv4_client ,
284
+ "DHCPv4 client management." ,
285
+ NULL ),
211
286
SHELL_SUBCMD_SET_END
212
287
);
213
288
0 commit comments