• Uboot之net


    //net读

    //api/api.c

    static cfp_t calls_table[API_MAXCALL] = { NULL, };

    void api_init(void)

    {

      ...

      calls_table[API_RSVD] = NULL;
      calls_table[API_GETC] = &API_getc;
      calls_table[API_PUTC] = &API_putc;
      calls_table[API_TSTC] = &API_tstc;
      calls_table[API_PUTS] = &API_puts;
      calls_table[API_RESET] = &API_reset;
      calls_table[API_GET_SYS_INFO] = &API_get_sys_info;
      calls_table[API_UDELAY] = &API_udelay;
      calls_table[API_GET_TIMER] = &API_get_timer;
      calls_table[API_DEV_ENUM] = &API_dev_enum;
      calls_table[API_DEV_OPEN] = &API_dev_open;
      calls_table[API_DEV_CLOSE] = &API_dev_close;
      calls_table[API_DEV_READ] = &API_dev_read;
      calls_table[API_DEV_WRITE] = &API_dev_write;
      calls_table[API_ENV_GET] = &API_env_get;
      calls_table[API_ENV_SET] = &API_env_set;
      calls_table[API_ENV_ENUM] = &API_env_enum;
      calls_no = API_MAXCALL;

      ...

    }

    static int API_dev_read(va_list ap)

    {

      ...

      else if (di->type & DEV_TYP_NET)

      {

        len_net = (int *)va_arg(ap, u_int32_t);
        if (!len_net)
          return API_EINVAL;
        if (*len_net <= 0)
          return API_EINVAL;

        act_len_net = (int *)va_arg(ap, u_int32_t);
        if (!act_len_net)
          return API_EINVAL;

        *act_len_net = dev_read_net(di->cookie, buf, *len_net);

      }

      ...

    }

    //api/api_net.c

    int dev_read_net(void *cookie, void *buf, int len)
    {

      return eth_receive(buf, len);

    }

    //net/eth.c

    int eth_receive(volatile void *packet, int length)
    {

    if (eth_rcv_current == eth_rcv_last)
    {

      ...
      push_packet = eth_save_packet;
      eth_rx();
      push_packet = pp;

      if (eth_rcv_current == eth_rcv_last)
        return -1;

      ...

    }

    //drivers ethigmacv300Higmac.c

    int eth_rx(void)

    {

      ...

      NetReceive(NetRxPackets[0], len);

      ...

    }

    //net/net.c

    void NetReceive(volatile uchar * inpkt, int len)

    {

      ...

      x = ntohs(vet->vet_type);

      ...

      switch (x) 

      {

        case PROT_ARP:

          ...

          switch (ntohs(arp->ar_op)) 

          {

            ...

            case ARPOP_REQUEST:

              ...

            case ARPOP_REPLY:

              ...

              tmp = NetReadIP(&arp->ar_data[6]);

              if (tmp == NetArpWaitReplyIP) 

              {

                ...

                (*packetHandler)(0,0,0,0);

                ...

              }

            case PROT_RARP:

              ...

            case PROT_IP:

              ...

              if (ip->ip_p == IPPROTO_ICMP)

              {

                ...

                switch (icmph->type)

                {

                  case ICMP_REDIRECT:

                    ...

                  case ICMP_ECHO_REPLY:

                    ...

                  case ICMP_ECHO_REQUEST:

                    ...

                }

              }

          }

      }

    static rxhand_f *packetHandler; /* Current RX packet handler */

    void NetSetHandler(rxhand_f * f)

    {
      packetHandler = f;
    }

    //net/net.h

    typedef void rxhand_f(uchar *, unsigned, unsigned, unsigned);

    举例tftp通讯

    //net/tftp.c

    void TftpStart (void)

    {

      ...

      NetSetHandler (TftpHandler);

      ...

    }

    static void TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)

    {

      ...

      s = (ushort *)pkt;

      proto = *s++;

      ...

      switch (ntohs(proto)) 

      {

        case TFTP_RRQ:

        case TFTP_WRQ:
          break;
        case TFTP_ACK:

        

      }

    }

  • 相关阅读:
    Exception in thread "main" java.lang.IllegalArgumentException:解决方法
    Warning: $HADOOP_HOME is deprecated.解决方法
    Android :TextView使用SpannableString设置复合文本
    一、harbor部署之centos7的基本配置
    木马基础知识要点
    【原创】红客闯关游戏部分题解
    【原创】利用Office宏实现powershell payload远控
    【原创】字典攻击教务处(BurpSuite使用)
    【原创】逆向练习(CrackMe)
    显式游标和隐式游标二者的区别
  • 原文地址:https://www.cnblogs.com/pokerface/p/7069859.html
Copyright © 2020-2023  润新知