亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tftpserver.c

?? stm32+ucos-ii
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* tftpsercer.c */

#include "tftpserver.h"
#include "stm3210c_eval_lcd.h"  // w w w . a r m j i s h u . c o m
#include "tftputils.h" 
#include "efs.h"
#include "ls.h"
#include "sd.h"
#include <stdio.h>
#include <string.h>

#define MFS_MODE_READ 0
#define MFS_MODE_WRITE 1

#define TFTP_OPCODE_LEN         2
#define TFTP_BLKNUM_LEN         2
#define TFTP_ERRCODE_LEN        2
#define TFTP_DATA_LEN_MAX       512
#define TFTP_DATA_PKT_HDR_LEN   (TFTP_OPCODE_LEN + TFTP_BLKNUM_LEN)
#define TFTP_ERR_PKT_HDR_LEN    (TFTP_OPCODE_LEN + TFTP_ERRCODE_LEN)
#define TFTP_ACK_PKT_LEN        (TFTP_OPCODE_LEN + TFTP_BLKNUM_LEN)
#define TFTP_DATA_PKT_LEN_MAX   (TFTP_DATA_PKT_HDR_LEN + TFTP_DATA_LEN_MAX)
#define TFTP_MAX_RETRIES        3
#define TFTP_TIMEOUT_INTERVAL   5


typedef struct
{
  int op;    /* RRQ/WRQ */

  /* last block read */
  char data[TFTP_DATA_PKT_LEN_MAX];
  int  data_len;

  /* destination ip:port */
  struct ip_addr to_ip;
  int to_port;

  /* next block number */
  int block;

  /* total number of bytes transferred */
  int tot_bytes;

  /* timer interrupt count when last packet was sent */
  /* this should be used to resend packets on timeout */
  unsigned long long last_time;

}tftp_connection_args;


EmbeddedFileSystem  efs1, efs2;
DirList             list1, list2;
EmbeddedFile        file_SD, file_CR;
/* UDPpcb to be binded with port 69  */
struct udp_pcb *UDPpcb;
/* tftp_errorcode error strings */
char *tftp_errorcode_string[] = {
                                  "not defined",
                                  "file not found",
                                  "access violation",
                                  "disk full",
                                  "illegal operation",
                                  "unknown transfer id",
                                  "file already exists",
                                  "no such user",
                                };

void recv_callback_tftp(void *arg, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port);


err_t tftp_send_message(struct udp_pcb *upcb, struct ip_addr *to_ip, int to_port, char *buf, int buflen)
{

  err_t err;
  struct pbuf *pkt_buf; /* Chain of pbuf's to be sent */

  /* PBUF_TRANSPORT - specifies the transport layer */
  pkt_buf = pbuf_alloc(PBUF_TRANSPORT, buflen, PBUF_POOL);

  if (!pkt_buf)      /*if the packet pbuf == NULL exit and EndTransfertransmission */
    return ERR_MEM;

  /* Copy the original data buffer over to the packet buffer's payload */
  memcpy(pkt_buf->payload, buf, buflen);

  /* Sending packet by UDP protocol */
  err = udp_sendto(upcb, pkt_buf, to_ip, to_port);

  /* free the buffer pbuf */
  pbuf_free(pkt_buf);

  return err;
}


/* construct an error message into buf using err as the error code */
int tftp_construct_error_message(char *buf, tftp_errorcode err)
{

  int errorlen;
  /* Set the opcode in the 2 first bytes */
  tftp_set_opcode(buf, TFTP_ERROR);
  /* Set the errorcode in the 2 second bytes  */
  tftp_set_errorcode(buf, err);
  /* Set the error message in the last bytes */
  tftp_set_errormsg(buf, tftp_errorcode_string[err]);
  /* Set the length of the error message  */
  errorlen = strlen(tftp_errorcode_string[err]);

  /* return message size */
  return 4 + errorlen + 1;
}

/* construct and send an error message back to client */
int tftp_send_error_message(struct udp_pcb *upcb, struct ip_addr *to, int to_port, tftp_errorcode err)
{
  char buf[512];
  int error_len;

  /* construct error */
  error_len = tftp_construct_error_message(buf, err);
  /* sEndTransfererror  */
  return tftp_send_message(upcb, to, to_port, buf, error_len);
}

/* construct and send a data packet */
int tftp_send_data_packet(struct udp_pcb *upcb, struct ip_addr *to, int to_port, int block,
                          char *buf, int buflen)
{
  char packet[TFTP_DATA_PKT_LEN_MAX]; /* (512+4) bytes */

  /* Set the opcode 3 in the 2 first bytes */
  tftp_set_opcode(packet, TFTP_DATA);
  /* Set the block numero in the 2 second bytes */
  tftp_set_block(packet, block);
  /* Set the data message in the n last bytes */
  tftp_set_data_message(packet, buf, buflen);
  /* SEndTransferthe DATA packet */
  return tftp_send_message(upcb, to, to_port, packet, buflen + 4);
}

int tftp_send_ack_packet(struct udp_pcb *upcb, struct ip_addr *to, int to_port, int block)
{

  /* create the maximum possible size packet that a TFTP ACK packet can be */
  char packet[TFTP_ACK_PKT_LEN];

  /* define the first two bytes of the packet */
  tftp_set_opcode(packet, TFTP_ACK);

  /* Specify the block number being ACK'd.
   * If we are ACK'ing a DATA pkt then the block number echoes that of the DATA pkt being ACK'd (duh)
   * If we are ACK'ing a WRQ pkt then the block number is always 0
   * RRQ packets are never sent ACK pkts by the server, instead the server sends DATA pkts to the
   * host which are, obviously, used as the "acknowledgement".  This saves from having to sEndTransferboth
   * an ACK packet and a DATA packet for RRQs - see RFC1350 for more info.  */
  tftp_set_block(packet, block);

  return tftp_send_message(upcb, to, to_port, packet, TFTP_ACK_PKT_LEN);
}

/* close the file sent, disconnect and close the connection */
void tftp_cleanup_rd(struct udp_pcb *upcb, tftp_connection_args *args)
{
  /* close the filesystem */
  file_fclose(&file_SD);
  fs_umount(&efs1.myFs);
  /* Free the tftp_connection_args structure reserverd for */
  mem_free(args);

  /* Disconnect the udp_pcb*/
  udp_disconnect(upcb);

  /* close the connection */
  udp_remove(upcb);

  udp_recv(UDPpcb, recv_callback_tftp, NULL);
}

/* close the file writen, disconnect and close the connection */
void tftp_cleanup_wr(struct udp_pcb *upcb, tftp_connection_args *args)
{
  /* close the filesystem */
  file_fclose(&file_CR);
  fs_umount(&efs2.myFs);
  /* Free the tftp_connection_args structure reserverd for */
  mem_free(args);

  /* Disconnect the udp_pcb*/
  udp_disconnect(upcb);

  /* close the connection */
  udp_remove(upcb);

  /* reset the callback function */
  udp_recv(UDPpcb, recv_callback_tftp, NULL);
}

void tftp_send_next_block(struct udp_pcb *upcb, tftp_connection_args *args,
                          struct ip_addr *to_ip, u16_t to_port)
{
  /* Function to read 512 bytes from the file to sEndTransfer(file_SD), put them
   * in "args->data" and return the number of bytes read */
  args->data_len = file_read(&file_SD, TFTP_DATA_LEN_MAX, (euint8*)args->data);

  /*   NOTE: We need to sEndTransferanother data packet even if args->data_len = 0
     The reason for this is as follows:
     1) This function is only ever called if the previous packet payload was
        512 bytes.
     2) If args->data_len = 0 then that means the file being sent is an exact
         multiple of 512 bytes.
     3) RFC1350 specifically states that only a payload of <= 511 can EndTransfera
        transfer.
     4) Therefore, we must sEndTransferanother data message of length 0 to complete
        the transfer.                */


  /* sEndTransferthe data */
  tftp_send_data_packet(upcb, to_ip, to_port, args->block, args->data, args->data_len);

}

void rrq_recv_callback(void *_args, struct udp_pcb *upcb, struct pbuf *p,
                       struct ip_addr *addr, u16_t port)
{
  /* Get our connection state  */
  tftp_connection_args *args = (tftp_connection_args *)_args;

  if (tftp_is_correct_ack(p->payload, args->block))
  {
    /* increment block # */
    args->block++;
  }
  else
  {
    /* we did not receive the expected ACK, so
       do not update block #. This causes the current block to be resent. */
  }

  /* if the last read returned less than the requested number of bytes
   * (i.e. TFTP_DATA_LEN_MAX), then we've sent the whole file and we can quit
   */
  if (args->data_len < TFTP_DATA_LEN_MAX)
  {
    /* Clean the connection*/
    tftp_cleanup_rd(upcb, args);

    pbuf_free(p);
  }

  /* if the whole file has not yet been sent then continue  */
  tftp_send_next_block(upcb, args, addr, port);

  pbuf_free(p);

}

int tftp_process_read(struct udp_pcb *upcb, struct ip_addr *to, int to_port, char* FileName)
{
  tftp_connection_args *args = NULL;

  /* If Could not open the file which will be transmitted  */
  if (file_fopen(&file_SD, &efs1.myFs, FileName, 'r') != 0)
  {
    tftp_send_error_message(upcb, to, to_port, TFTP_ERR_FILE_NOT_FOUND);

    tftp_cleanup_rd(upcb, args);

    return 0;
  }

  /* This function is called from a callback,
   * therefore, interrupts are disabled,
   * therefore, we can use regular malloc. */

  args = mem_malloc(sizeof *args);
  /* If we aren't able to allocate memory for a "tftp_connection_args" */
  if (!args)
  {
    /* unable to allocate memory for tftp args  */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区性放荡片| av午夜一区麻豆| 国产乱子轮精品视频| 色先锋aa成人| 久久久久亚洲蜜桃| 午夜电影一区二区| 日韩欧美亚洲另类制服综合在线| 国产视频911| 麻豆精品新av中文字幕| 在线观看视频欧美| 国产精品久久一卡二卡| 国内久久婷婷综合| 88在线观看91蜜桃国自产| 亚洲欧美在线视频观看| 国产传媒久久文化传媒| 精品剧情v国产在线观看在线| 亚洲黄色尤物视频| 91在线免费看| 国产精品传媒入口麻豆| 国产精品综合二区| 精品99一区二区三区| 免费看黄色91| 欧美一三区三区四区免费在线看| 亚洲精品欧美激情| 91网上在线视频| 亚洲欧美在线高清| 97久久超碰精品国产| 国产精品卡一卡二卡三| 国产成人免费高清| 久久综合九色综合97_久久久| 男人的天堂久久精品| 制服丝袜亚洲色图| 日韩av电影免费观看高清完整版| 欧美人与性动xxxx| 午夜av电影一区| 制服丝袜中文字幕亚洲| 亚洲一区二区综合| 欧美日韩国产在线观看| 视频一区二区中文字幕| 欧美精品第一页| 日韩精品色哟哟| 欧美一二三四区在线| 久久9热精品视频| 久久亚洲二区三区| 国产91丝袜在线播放九色| 久久久久久久网| 国产美女视频一区| 欧美韩国日本不卡| 91日韩一区二区三区| 一区二区三区.www| 日韩一二三区不卡| 国产精品一线二线三线精华| 久久色视频免费观看| 成人v精品蜜桃久久一区| 伊人夜夜躁av伊人久久| 欧美精品免费视频| 国产一区三区三区| 国产精品久久网站| 欧美日韩国产高清一区二区三区 | 国产日韩v精品一区二区| 国产一区视频网站| 成人免费一区二区三区在线观看| 欧美性一区二区| 精品亚洲国内自在自线福利| 欧美国产激情二区三区| 欧美影院午夜播放| 韩国女主播成人在线观看| 国产精品久久网站| 欧美一区二区三区免费观看视频 | 亚洲超碰97人人做人人爱| 日韩一级二级三级| 99久久婷婷国产综合精品| 亚洲va韩国va欧美va精品| 日韩欧美123| 国产河南妇女毛片精品久久久 | 国产精品天美传媒| 欧美视频中文字幕| 欧美aaa在线| 国产午夜亚洲精品羞羞网站| 国产成人午夜精品5599| 亚洲欧美在线高清| 欧美男人的天堂一二区| 国产精品一区二区黑丝| 亚洲福中文字幕伊人影院| 色噜噜狠狠一区二区三区果冻| 日本不卡视频在线| 亚洲欧美二区三区| 久久久久久久久岛国免费| 欧美在线色视频| 国产精品一区二区在线观看不卡 | 国产欧美精品国产国产专区| 欧美性猛交xxxx乱大交退制版 | 午夜视频一区二区三区| 国产欧美日韩精品在线| 欧美一级理论片| 欧美综合视频在线观看| 成人激情免费电影网址| 精品无人码麻豆乱码1区2区 | 亚洲午夜影视影院在线观看| 国产亚洲短视频| 欧美α欧美αv大片| 欧美三级中文字| 99久久精品国产一区二区三区| 美女视频黄免费的久久 | 欧美精品视频www在线观看| 日韩一区二区三区电影| 欧美又粗又大又爽| 97超碰欧美中文字幕| 成人午夜精品在线| 激情伊人五月天久久综合| 日韩国产精品久久久久久亚洲| 成人免费在线观看入口| 国产精品九色蝌蚪自拍| 中文字幕免费不卡在线| 久久新电视剧免费观看| 久久精品一区八戒影视| 久久精品视频网| 国产日韩成人精品| 国产精品欧美综合在线| 国产精品久久久久一区| 亚洲欧美日韩久久精品| 亚洲色图第一区| 亚洲自拍欧美精品| 亚洲高清在线视频| 香蕉成人啪国产精品视频综合网| 亚洲成人动漫在线观看| 日韩中文字幕亚洲一区二区va在线| 婷婷中文字幕一区三区| 美腿丝袜亚洲色图| 国产精品一线二线三线| 大胆亚洲人体视频| 99国产精品视频免费观看| 91美女蜜桃在线| 精品视频免费在线| 日韩一区二区精品在线观看| 精品国产乱码久久久久久夜甘婷婷| 久久久国产一区二区三区四区小说| 国产欧美日韩精品一区| 国产精品乱码一区二区三区软件| 亚洲精品写真福利| 亚洲大片在线观看| 国产综合久久久久久久久久久久 | 日韩在线一二三区| 国产一区二区免费视频| 不卡一区二区三区四区| 在线亚洲人成电影网站色www| 欧美日本一区二区| 久久精品网站免费观看| 中文字幕一区二区三区在线不卡| 一区二区视频在线看| 日日欢夜夜爽一区| 国产不卡在线一区| 欧美日本在线一区| 国产日韩v精品一区二区| 亚洲午夜久久久久| 国产成人在线免费观看| 欧洲国内综合视频| 久久综合久色欧美综合狠狠| 亚洲免费观看在线观看| 久久不见久久见免费视频7| 99精品欧美一区| 精品国产自在久精品国产| 亚洲女同ⅹxx女同tv| 麻豆国产欧美一区二区三区| 91社区在线播放| 久久综合九色综合97婷婷女人 | 精品欧美一区二区三区精品久久| 国产精品久久二区二区| 免费国产亚洲视频| 91丨九色porny丨蝌蚪| 欧美精品一区二区久久婷婷 | 日韩码欧中文字| 国产一区二区三区电影在线观看 | 久久精品视频一区二区三区| 午夜日韩在线观看| caoporen国产精品视频| 欧美精品一区二区三区四区| 亚洲曰韩产成在线| 99国产欧美另类久久久精品| 精品福利二区三区| 日韩电影网1区2区| 欧美亚洲动漫精品| 亚洲日本欧美天堂| 成人免费观看视频| 国产欧美综合在线观看第十页| 日韩精品免费视频人成| 欧美色图在线观看| 亚洲视频一二三区| 99久久伊人精品| 国产精品色眯眯| 国产91综合网| 日本一区二区免费在线| 精品一区二区在线播放| 91精品国产综合久久久久久漫画| 亚洲综合久久久| 色狠狠综合天天综合综合| 国产精品免费视频网站| 国产成人精品影院| 欧美国产1区2区| 成人精品一区二区三区四区|