Esempio n. 1
0
/* for each new request (data in p->payload) from addr:port,
 * create a new port to serve the response, and start the response
 * process
 */
void process_tftp_request(struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port)
{
  tftp_opcode op = tftp_decode_op(pkt_buf->payload);
  char FileName[30];
  struct udp_pcb *upcb;
  err_t err;
  u32_t IPaddress;
  u8_t iptxt[20];
  volatile u8_t iptab[4];
  
  IPaddress = addr->addr;
  printf("\n\rTFTP RRQ (read request) from: %d.%d.%d.%d\n\r", (u8_t)(IPaddress),
            (u8_t)(IPaddress >> 8),(u8_t)(IPaddress >> 16),(u8_t)(IPaddress >> 24));
  
  /* read its IP address */
  iptab[0] = (u8_t)(IPaddress >> 24);
  iptab[1] = (u8_t)(IPaddress >> 16);
  iptab[2] = (u8_t)(IPaddress >> 8);
  iptab[3] = (u8_t)(IPaddress);

  sprintf((char*)iptxt, "TFTP: %d.%d.%d.%d   ", iptab[3], iptab[2], iptab[1], iptab[0]);	
  
  LCD_DisplayStringLine(Line7, iptxt);
  
  /* create new UDP PCB structure */
  upcb = udp_new();
  if (!upcb)
  {     /* Error creating PCB. Out of Memory  */
    return;
  }

  /* bind to port 0 to receive next available free port */
  /* NOTE:  This is how TFTP works.  There is a UDP PCB for the standard port
   * 69 which al transactions begin communication on, however, _all_ subsequent
   * transactions for a given "stream" occur on another port!  */
  err = udp_bind(upcb, IP_ADDR_ANY, 0);
  if (err != ERR_OK)
  {    /* Unable to bind to port   */
    return;
  }


  switch (op)
  {

    case TFTP_RRQ:    /* TFTP RRQ (read request)  */
      /* Read the name of the file asked by the client 
                            to be sent from the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);

      printf("\n\rTFTP RRQ (read request)");
      printf("\n\rONLY EFS filesystem(NTFS in WinXp) is support");
      
      /* If Could not open filesystem */
      if (efs_init(&efs1, 0) != 0)
      {
        printf("\n\rIf Could not open filesystem");
        return;
      }
      printf("\n\rCould open filesystem\n\r");
      /* If Could not open the selected directory */
      if (ls_openDir(&list1, &(efs1.myFs), "/") != 0)
      {
        printf("\n\rIf Could not open the selected directory");
        return;
      }
      /* Start the TFTP read mode*/
      printf("\n\rStart the TFTP read mode....");
      tftp_process_read(upcb, addr, port, FileName);
      break;

    case TFTP_WRQ:    /* TFTP WRQ (write request)   */
      /* Read the name of the file asked by the client 
                to received and writen in the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);

      /* If Could not open filesystem */
      if (efs_init(&efs2, 0) != 0)
      {
        return;
      }
      /* If Could not open the selected directory */
      if (ls_openDir(&list2, &(efs2.myFs), "/") != 0)
      {
        return;
      }

      /* Start the TFTP write mode*/
      tftp_process_write(upcb, addr, port, FileName);
      break;

    default:
      /* sEndTransfera generic access violation message */
      tftp_send_error_message(upcb, addr, port, TFTP_ERR_ACCESS_VIOLATION);
      /* TFTP unknown request op */
      /* no need to use tftp_cleanup_wr because no 
            "tftp_connection_args" struct has been malloc'd   */
      udp_remove(upcb);

      break;
  }
}
Esempio n. 2
0
/**
  * @brief  processes the tftp request on port 69
  * @param  pkt_buf: pointer on received pbuf
  * @param  ip_addr: pointer on source IP address
  * @param  port: pointer on source udp port
  * @retval None
  */
void process_tftp_request(struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port)
{
  tftp_opcode op = tftp_decode_op(pkt_buf->payload);
  char FileName[30];
  struct udp_pcb *upcb;
  err_t err;

  /* create new UDP PCB structure */
  upcb = udp_new();
  if (!upcb)
  {     
    /* Error creating PCB. Out of Memory  */
    return;
  }

  /* bind to port 0 to receive next available free port */
  /* NOTE:  This is how TFTP works.  There is a UDP PCB for the standard port
   * 69 which al transactions begin communication on, however all subsequent
   * transactions for a given "stream" occur on another port!  */
  err = udp_bind(upcb, IP_ADDR_ANY, 0);
  if (err != ERR_OK)
  {    
    /* Unable to bind to port   */
    return;
  }
  switch (op)
  {
    case TFTP_RRQ:/* TFTP RRQ (read request)  */
    {
      /* Read the name of the file asked by the client to be sent from the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);

      _CONSOLE(LogId, "TFTP_RRQ:%s\n", FileName);

      /* could not open filesystem */
      if (f_mount(&filesystem, "", 0) != FR_OK)
      {
        return;
      }
      /* could not open the selected directory */
      if (f_opendir(&dir_1, "/") != FR_OK)
      {
        return;
      }
      /* Start the TFTP read mode*/
      tftp_process_read(upcb, addr, port, FileName);
      break;
    } 

    case TFTP_WRQ:    /* TFTP WRQ (write request)   */
    {
      /* Read the name of the file asked by the client to be received and writen in the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);
  
      _CONSOLE(LogId, "TFTP_WRQ:%s\n", FileName);

      /* Could not open filesystem */
      if (f_mount(&filesystem, "", 0) != FR_OK)
      {
        return;
      }
        
      /* If Could not open the selected directory */
      if (f_opendir(&dir_2, "/") != FR_OK)
      {
        return;
      }
        
      /* Start the TFTP write mode*/
      tftp_process_write(upcb, addr, port, FileName);
      break;
    }
    default: /* TFTP unknown request op */
      /* send generic access violation message */
      tftp_send_error_message(upcb, addr, port, TFTP_ERR_ACCESS_VIOLATION);
      udp_remove(upcb);

      break;
  }
}
Esempio n. 3
0
/* for each new request (data in p->payload) from addr:port,
 * create a new port to serve the response, and start the response
 * process
 */
void process_tftp_request(struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port)
{
  tftp_opcode op = tftp_decode_op(pkt_buf->payload);
  char FileName[30];
  struct udp_pcb *upcb;
  err_t err;

  /* create new UDP PCB structure */
  upcb = udp_new();
  if (!upcb)
  {     /* Error creating PCB. Out of Memory  */
    return;
  }

  /* bind to port 0 to receive next available free port */
  /* NOTE:  This is how TFTP works.  There is a UDP PCB for the standard port
   * 69 which al transactions begin communication on, however, _all_ subsequent
   * transactions for a given "stream" occur on another port!  */
  err = udp_bind(upcb, IP_ADDR_ANY, 0);
  if (err != ERR_OK)
  {    /* Unable to bind to port   */
    return;
  }


  switch (op)
  {

    case TFTP_RRQ:    /* TFTP RRQ (read request)  */
      /* Read the name of the file asked by the client to be sent from the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);

      /* If Could not open filesystem */
      if (efs_init(&efs1, 0) != 0)
      {
        return;
      }
      /* If Could not open the selected directory */
      if (ls_openDir(&list1, &(efs1.myFs), "/") != 0)
      {
        return;
      }
      /* Start the TFTP read mode*/
      tftp_process_read(upcb, addr, port, FileName);
      break;

    case TFTP_WRQ:    /* TFTP WRQ (write request)   */
      /* Read the name of the file asked by the client to received and writen in the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);

      /* If Could not open filesystem */
      if (efs_init(&efs2, 0) != 0)
      {
        return;
      }
      /* If Could not open the selected directory */
      if (ls_openDir(&list2, &(efs2.myFs), "/") != 0)
      {
        return;
      }

      /* Start the TFTP write mode*/
      tftp_process_write(upcb, addr, port, FileName);
      break;

    default:
      /* sEndTransfera generic access violation message */
      tftp_send_error_message(upcb, addr, port, TFTP_ERR_ACCESS_VIOLATION);
      /* TFTP unknown request op */
      /* no need to use tftp_cleanup_wr because no "tftp_connection_args" struct has been malloc'd   */
      udp_remove(upcb);

      break;
  }
}