/** * @brief Processes traffic received on UDP port 69 * @param args: pointer on tftp_connection arguments * @param upcb: pointer on udp_pcb structure * @param pbuf: pointer on packet buffer * @param addr: pointer on the receive IP address * @param port: receive port number * @retval None */ static void IAP_tftp_recv_callback(void *arg, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_opcode op; struct udp_pcb *upcb_tftp_data; err_t err; #ifdef USE_LCD uint32_t i; char filename[40],message[40], *ptr; #endif /* create new UDP PCB structure */ upcb_tftp_data = udp_new(); if (!upcb_tftp_data) { /* Error creating PCB. Out of Memory */ #ifdef USE_LCD LCD_ErrLog("Can not create pcb \n"); #endif 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_tftp_data, IP_ADDR_ANY, 0); if (err != ERR_OK) { /* Unable to bind to port */ #ifdef USE_LCD LCD_ErrLog("Can not create pcb \n"); #endif return; } op = IAP_tftp_decode_op(pkt_buf->payload); if (op != TFTP_WRQ) { /* remove PCB */ #ifdef USE_LCD LCD_ErrLog("Bad TFTP opcode \n"); #endif udp_remove(upcb_tftp_data); } else { #ifdef USE_LCD ptr = pkt_buf->payload; ptr = ptr +2; /*extract file name info */ i= 0; while (*(ptr+i)!=0x0) { i++; } strncpy(filename, ptr, i+1); LCD_UsrLog("IAP using TFTP \n"); sprintf(message, "File: %s",filename); LCD_UsrLog("%s\n", message); LCD_UsrLog(" State: Erasing...\n"); #endif /* Start the TFTP write mode*/ IAP_tftp_process_write(upcb_tftp_data, addr, port); } pbuf_free(pkt_buf); }
/** * @brief Processes traffic received on UDP port 69 * @param args: pointer on tftp_connection arguments * @param upcb: pointer on udp_pcb structure * @param pbuf: pointer on packet buffer * @param addr: pointer on the receive IP address * @param port: receive port number * @retval none */ static void IAP_tftp_recv_callback(void *arg, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_opcode op; struct udp_pcb *upcb_tftp_data; err_t err; #ifdef USE_LCD uint32_t i; char filename[40],message[40], *ptr; #endif /* create new UDP PCB structure */ upcb_tftp_data = udp_new(); if (!upcb_tftp_data) { udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺6",UPDATE_FONT); UDP_AddUpdateError(); // /* Error creating PCB. Out of Memory */ // #ifdef USE_LCD // LCD_SetTextColor(Red); // LCD_DisplayStringLine(Line9, (uint8_t*)"Can not create pcb"); // #endif 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_tftp_data, IP_ADDR_ANY, 0); if (err != ERR_OK) { udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺7",UPDATE_FONT); UDP_AddUpdateError(); // /* Unable to bind to port */ // #ifdef USE_LCD // LCD_SetTextColor(Red); // LCD_DisplayStringLine(Line9, (uint8_t*)"Can not bind pcb"); // #endif return; } op = IAP_tftp_decode_op(pkt_buf->payload); if (op != TFTP_WRQ) { udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺8",UPDATE_FONT); UDP_AddUpdateError(); // /* remove PCB */ // #ifdef USE_LCD // LCD_SetTextColor(Red); // LCD_DisplayStringLine(Line9, (uint8_t*)"Bad TFTP opcode "); // #endif udp_remove(upcb_tftp_data); } else { // #ifdef USE_LCD // ptr = pkt_buf->payload; // ptr = ptr +2; // /*extract file name info */ // i= 0; // while (*(ptr+i)!=0x0) // { // i++; // } // strncpy(filename, ptr, i+1); // // /* Set the LCD Text Color */ // LCD_SetTextColor(White); // LCD_Clear(Black); // // LCD_DisplayStringLine(Line0, (uint8_t*)" IAP using TFTP "); // sprintf(message, "File: %s",filename); // LCD_DisplayStringLine(Line3, (uint8_t*)message); // /* Set the LCD Text Color */ // LCD_DisplayStringLine(Line8, (uint8_t*)"State: Erasing..."); // // #endif /* Start the TFTP write mode*/ IAP_tftp_process_write(upcb_tftp_data, addr, port); } pbuf_free(pkt_buf); }