#include "console.h"
Go to the source code of this file.
Typedefs | |
typedef void(* | ping_complete_cb_t )(uint32_t tx_pkt_cnt, uint32_t rx_pkt_cnt, void *ctx) |
Functions | |
cmd_state_t | cmd_ping (int argc, char *argv[], void *ctx) |
void | ping_set_callback (ping_complete_cb_t cb, void *ctx) |
void | ping_stop (uint32_t *tx_cnt, uint32_t *rx_cnt) |
typedef void(* ping_complete_cb_t)(uint32_t tx_pkt_cnt, uint32_t rx_pkt_cnt, void *ctx) |
cmd_state_t cmd_ping | ( | int | argc, | |
char * | argv[], | |||
void * | ctx | |||
) |
Definition at line 246 of file ping.c.
References CMD_DONE, CMD_INPROGRESS, ping_info_t::count, ping_info_t::data_size, ping_info_t::deadline, ping_info_t::destination, ping_info_t::first_tx_tm, ping_info_t::flags, INFO, init_ping_info(), ping_info_t::interval, ip2str(), ping_info_t::last_rx_tm, ping_info_t::last_tx_tm, ping_info_t::num_tx, pcb, ping_finalize(), ping_recv(), PING_REPLY, ping_send(), printk(), ping_info_t::quiet, ping_info_t::size, ping_info_t::timeout, and timer_get_ms().
Referenced by wl_init_complete_cb().
00247 { 00248 static enum { 00249 INIT, 00250 PING, 00251 WAIT_REPLY 00252 } state = INIT; 00253 00254 struct ping_info_t *ping_info = &INFO; 00255 static struct raw_pcb *pcb; 00256 00257 switch (state) { 00258 case INIT: 00259 if (init_ping_info(argc, argv, ping_info) != 0) { 00260 printk("Usage: ping [-c count] [-i interval] " \ 00261 "[-s packetsize]\n " \ 00262 "[-w deadline] [-q] destination\n"); 00263 return CMD_DONE; 00264 } 00265 00266 if (!(pcb = raw_new(IP_PROTO_ICMP))) { 00267 printk("could not allocate pcb\n"); 00268 state = INIT; 00269 return CMD_DONE; 00270 } 00271 raw_recv(pcb, ping_recv, ping_info); 00272 raw_bind(pcb, IP_ADDR_ANY); 00273 00274 printk("PING %s %d(%d) bytes of data\n", 00275 ip2str(ping_info->destination), 00276 ping_info->data_size, 00277 ping_info->size); 00278 state = PING; 00279 /* fall through */ 00280 00281 case PING: 00282 if (!netif_is_up(netif_default)) { 00283 printk("netif is down\n"); 00284 raw_remove(pcb); 00285 state = INIT; 00286 return CMD_DONE; 00287 } 00288 00289 if (ping_info->count && ping_info->num_tx == ping_info->count) { 00290 ping_finalize(ping_info); 00291 raw_remove(pcb); 00292 state = INIT; 00293 return CMD_DONE; 00294 } 00295 00296 if (timer_get_ms() < ping_info->last_rx_tm + ping_info->interval) { 00297 return CMD_INPROGRESS; 00298 } 00299 ping_send(pcb, ping_info); 00300 00301 state = WAIT_REPLY; 00302 return CMD_INPROGRESS; 00303 00304 case WAIT_REPLY: 00305 if (ping_info->flags & PING_REPLY) { 00306 ping_info->flags &= (~PING_REPLY); 00307 state = PING; 00308 return CMD_INPROGRESS; 00309 } 00310 00311 if (timer_get_ms() > 00312 ping_info->last_tx_tm + ping_info->timeout) { 00313 if (!ping_info->quiet) 00314 printk("timeout from %s\n", 00315 ip2str(ping_info->destination)); 00316 state = PING; 00317 return CMD_INPROGRESS; 00318 } 00319 00320 if (ping_info->deadline && 00321 timer_get_ms() > 00322 ping_info->first_tx_tm + ping_info->deadline * 1000) { 00323 ping_finalize(ping_info); 00324 raw_remove(pcb); 00325 state = INIT; 00326 return CMD_DONE; 00327 } 00328 00329 return CMD_INPROGRESS; 00330 } 00331 00332 /* unreachable */ 00333 Assert(0); 00334 return CMD_DONE; 00335 }
void ping_set_callback | ( | ping_complete_cb_t | cb, | |
void * | ctx | |||
) |
Definition at line 151 of file ping.c.
References ping_info_t::complete_cb, ping_info_t::ctx, and INFO.
void ping_stop | ( | uint32_t * | tx_cnt, | |
uint32_t * | rx_cnt | |||
) |
Definition at line 156 of file ping.c.
References ping_info_t::count, INFO, ping_info_t::num_rx, and ping_info_t::num_tx.
00156 { 00157 struct ping_info_t *ping_info = &INFO; 00158 00159 *tx_cnt = ping_info->num_tx; 00160 *rx_cnt = ping_info->num_rx; 00161 ping_info->count = ping_info->num_tx; 00162 if ( 0 == ping_info->count ) { 00163 ping_info->count = 1; 00164 } 00165 }