コード例 #1
0
ファイル: tftp_server.c プロジェクト: Archcady/mbed-os
static void
send_data(void)
{
  u16_t *payload;
  int ret;

  if(tftp_state.last_data != NULL) {
    pbuf_free(tftp_state.last_data);
  }
  
  tftp_state.last_data = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + TFTP_MAX_PAYLOAD_SIZE, PBUF_RAM);
  if(tftp_state.last_data == NULL) {
    return;
  }

  payload = (u16_t *) tftp_state.last_data->payload;
  payload[0] = PP_HTONS(TFTP_DATA);
  payload[1] = lwip_htons(tftp_state.blknum);

  ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE);
  if (ret < 0) {
    send_error(&tftp_state.addr, tftp_state.port, TFTP_ERROR_ACCESS_VIOLATION, "Error occured while reading the file.");
    close_handle();
    return;
  }

  pbuf_realloc(tftp_state.last_data, (u16_t)(TFTP_HEADER_LENGTH + ret));
  resend_data();
}
コード例 #2
0
ファイル: tftp_server.c プロジェクト: EmuxEvans/lwip_contrib
void tftp_tmr(void)
{
    tftp_state.timer++;

    if (tftp_state.handle == NULL)
        return;

    if ((tftp_state.timer - tftp_state.last_pkt) >
        (TFTP_TIMEOUT_MSECS / TFTP_TIMER_MSECS))
    {
        if (tftp_state.last_data != NULL &&
            tftp_state.retries < TFTP_MAX_RETRIES)
        {
            LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE,
                    ("tftp: timeout, retrying\n"));

            resend_data(tftp_state.upcb, tftp_state.addr,
                        tftp_state.port, &tftp_state);
            tftp_state.retries++;
        } else {
            LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE,
                    ("tftp: timeout\n"));
            close_handle(&tftp_state);
        }

    }
}
コード例 #3
0
ファイル: tftp.c プロジェクト: olsner/lwip
static void
send_data(const ip_addr_t *addr, u16_t port)
{
  u16_t *payload;
  int ret;

  if (tftp_state.last_data != NULL) {
    pbuf_free(tftp_state.last_data);
  }

  tftp_state.last_data = init_packet(TFTP_DATA, tftp_state.blknum, TFTP_MAX_PAYLOAD_SIZE);
  if (tftp_state.last_data == NULL) {
    return;
  }

  payload = (u16_t *) tftp_state.last_data->payload;

  ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE);
  if (ret < 0) {
    send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Error occured while reading the file.");
    close_handle();
    return;
  }

  pbuf_realloc(tftp_state.last_data, (u16_t)(TFTP_HEADER_LENGTH + ret));
  resend_data(addr, port);
}
コード例 #4
0
ファイル: tftp_server.c プロジェクト: EmuxEvans/lwip_contrib
static void send_data(struct udp_pcb *upcb, ip_addr_t *addr, u16_t port,
                      struct tftp_state *ts)
{
    ts->last_data = pbuf_alloc(PBUF_RAM, 4 + 512, PBUF_RAM);
    u16_t *payload = (u16_t *) ts->last_data->payload;
    payload[0] = htons(DATA);
    payload[1] = htons(ts->blknum);

    int ret = ts->ctx->read(ts->handle, &payload[2], 512);
    if (ret < 0) {
        send_error(upcb, addr, port, ERROR_ACCESS_VIOLATION,
                   "Error occured while reading the file.");
        pbuf_free(ts->last_data);
        ts->last_data = NULL;
        close_handle(ts);
        return;
    }

    pbuf_realloc(ts->last_data, 4 + ret);
    resend_data(upcb, addr, port, ts);
}
コード例 #5
0
ファイル: tftp_server.c プロジェクト: Archcady/mbed-os
static void
tftp_tmr(void* arg)
{
  LWIP_UNUSED_ARG(arg);
  
  tftp_state.timer++;

  if (tftp_state.handle == NULL) {
    return;
  }

  sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL);

  if ((tftp_state.timer - tftp_state.last_pkt) > (TFTP_TIMEOUT_MSECS / TFTP_TIMER_MSECS)) {
    if ((tftp_state.last_data != NULL) && (tftp_state.retries < TFTP_MAX_RETRIES)) {
      LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout, retrying\n"));
      resend_data();
      tftp_state.retries++;
    } else {
      LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout\n"));
      close_handle();
    }
  }
}