ping.h File Reference

#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 Documentation

typedef void(* ping_complete_cb_t)(uint32_t tx_pkt_cnt, uint32_t rx_pkt_cnt, void *ctx)

Definition at line 35 of file ping.h.


Function Documentation

cmd_state_t cmd_ping ( int  argc,
char *  argv[],
void *  ctx 
)

Definition at line 248 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().

00249 {
00250         static enum {
00251                 INIT,
00252                 PING,
00253                 WAIT_REPLY
00254         } state = INIT;
00255 
00256         struct ping_info_t *ping_info = &INFO;
00257         static struct raw_pcb *pcb;
00258         
00259         switch (state) {
00260         case INIT:
00261                 if (init_ping_info(argc, argv, ping_info) != 0) {
00262                         printk("Usage: ping [-c count] [-i interval] "  \
00263                                "[-s packetsize]\n            " \
00264                                "[-w deadline] [-q] destination\n");
00265                         return CMD_DONE;
00266                 }
00267 
00268                 if (!(pcb = raw_new(IP_PROTO_ICMP))) {
00269                         printk("could not allocate pcb\n");
00270                         state = INIT;
00271                         return CMD_DONE;
00272                 }
00273                 raw_recv(pcb, ping_recv, ping_info);
00274                 raw_bind(pcb, IP_ADDR_ANY);
00275 
00276                 printk("PING %s %d(%d) bytes of data\n",
00277                        ip2str(ping_info->destination),
00278                        ping_info->data_size,
00279                        ping_info->size);
00280                 state = PING;
00281                 /* fall through */
00282                 
00283         case PING:
00284                 if (!netif_is_up(netif_default)) {
00285                         printk("netif is down\n");
00286                         raw_remove(pcb);
00287                         state = INIT;
00288                         return CMD_DONE;
00289                 }
00290                 
00291                 if (ping_info->count && ping_info->num_tx == ping_info->count) {
00292                         ping_finalize(ping_info);
00293                         raw_remove(pcb);
00294                         state = INIT;
00295                         return CMD_DONE;
00296                 }
00297 
00298                 
00299                 if (timer_get_ms() < ping_info->last_rx_tm + ping_info->interval) {
00300                         return CMD_INPROGRESS;
00301                 }
00302                 ping_send(pcb, ping_info);
00303                         
00304                 state = WAIT_REPLY;
00305                 return CMD_INPROGRESS;
00306                 
00307         case WAIT_REPLY:
00308                 if (ping_info->flags & PING_REPLY) {
00309                         ping_info->flags &= (~PING_REPLY);
00310                         state = PING;
00311                         return CMD_INPROGRESS;
00312                 }
00313 
00314                 if (timer_get_ms() >
00315                     ping_info->last_tx_tm + ping_info->timeout) {
00316                         if (!ping_info->quiet)
00317                                 printk("timeout from %s\n",
00318                                        ip2str(ping_info->destination));
00319                         state = PING;
00320                         return CMD_INPROGRESS;
00321                 }
00322 
00323                 if (ping_info->deadline &&
00324                     timer_get_ms() >
00325                     ping_info->first_tx_tm + ping_info->deadline * 1000) {
00326                         ping_finalize(ping_info);
00327                         raw_remove(pcb);
00328                         state = INIT;
00329                         return CMD_DONE;
00330                 }
00331 
00332                 return CMD_INPROGRESS;
00333         }
00334 
00335         /* unreachable */
00336         Assert(0);
00337     return CMD_DONE;
00338 }

void ping_set_callback ( ping_complete_cb_t  cb,
void *  ctx 
)

Definition at line 153 of file ping.c.

References ping_info_t::complete_cb, ping_info_t::ctx, and INFO.

00153                                                          {
00154         INFO.complete_cb = cb;
00155         INFO.ctx = ctx;
00156 }

void ping_stop ( uint32_t *  tx_cnt,
uint32_t *  rx_cnt 
)

Definition at line 158 of file ping.c.

References ping_info_t::count, INFO, ping_info_t::num_rx, and ping_info_t::num_tx.

00158                                                    {
00159         struct ping_info_t *ping_info = &INFO;
00160 
00161         *tx_cnt = ping_info->num_tx;
00162         *rx_cnt = ping_info->num_rx;
00163         ping_info->count = ping_info->num_tx;
00164         if ( 0 == ping_info->count ) {
00165                 ping_info->count = 1;
00166         }
00167 }


Generated on Fri Feb 19 02:24:08 2010 for AVR32 - H&D by  doxygen 1.5.5