Пример #1
0
/*---------------------------------------------------------------------------*/
static void
send_discover(void)
{
  u8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;

  create_msg(m);

  end = add_msg_type(&m->options[4], DHCPDISCOVER);
  end = add_req_options(end);
  end = add_end(end);

  uip_send(uip_appdata, (int)(end - (u8_t *)uip_appdata));
}
Пример #2
0
/*---------------------------------------------------------------------------*/
static void
send_request(void)
{
  u8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;

  create_msg(m);
  
  end = add_msg_type(&m->options[4], DHCPREQUEST);
  end = add_server_id(end);
  end = add_req_ipaddr(end);
  end = add_end(end);
  
  uip_send(uip_appdata, end - (u8_t *)uip_appdata);
}
Пример #3
0
/*---------------------------------------------------------------------------*/
static void
send_request(void)
{
  uint8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)&dhcp_msg_buf;

  create_msg(m);
  
  end = add_msg_type(&m->options[4], DHCPREQUEST);
  end = add_server_id(end);
  end = add_req_ipaddr(end);
  end = add_end(end);
  
  uosFileWrite(s.conn, (void*)m, end - (uint8_t*)m);
}
Пример #4
0
int sc_report_handler::stop_after(const char * msg_type_, int limit)
{
    sc_msg_def * md = mdlookup(msg_type_);

    if ( !md )
        md = add_msg_type(msg_type_);

    int old = md->limit_mask & 1 ? md->limit: UINT_MAX;

    if ( limit < 0 )
        md->limit_mask &= ~1;
    else
    {
        md->limit_mask |= 1;
        md->limit = limit;
    }
    return old;
}
Пример #5
0
void sc_report_handler::report(sc_severity severity_,
                               const char * msg_type_,
                               const char * msg_,
                               const char * file_,
                               int line_)
{
    sc_msg_def * md = mdlookup(msg_type_);

    if ( !md )
        md = add_msg_type(msg_type_);

    sc_actions actions = execute(md, severity_);
    sc_report rep(severity_, md, msg_, file_, line_);

    if ( actions & SC_CACHE_REPORT )
        cache_report(rep);

    handler(rep, actions);
}
Пример #6
0
int sc_report_handler::stop_after(const char * msg_type_,
                                  sc_severity severity_,
                                  int limit)
{
    sc_msg_def * md = mdlookup(msg_type_);

    if ( !md )
        md = add_msg_type(msg_type_);

    int mask = 1 << (severity_ + 1);
    int old = md->limit_mask & mask ?  md->sev_limit[severity_]: UINT_MAX;

    if ( limit < 0 )
        md->limit_mask &= ~mask;
    else
    {
        md->limit_mask |= mask;
        md->sev_limit[severity_] = limit;
    }
    return old;
}
Пример #7
0
/* Prepare initial DHCPv4 message and add options as per message type */
static struct net_buf *prepare_message(struct net_if *iface, uint8_t type)
{
	struct net_buf *buf;
	struct net_buf *frag;
	struct dhcp_msg *msg;

	buf = net_nbuf_get_reserve_tx(0);
	if (!buf) {
		return NULL;
	}

	frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, NULL));
	if (!frag) {
		goto fail;
	}

	net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag));
	net_nbuf_set_iface(buf, iface);
	net_nbuf_set_family(buf, AF_INET);
	net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr));

	net_buf_frag_add(buf, frag);

	/* Leave room for IPv4 + UDP headers */
	net_buf_add(buf->frags, NET_IPV4UDPH_LEN);

	if (net_buf_tailroom(frag) < sizeof(struct dhcp_msg)) {
		goto fail;
	}

	msg = (struct dhcp_msg *)(frag->data + NET_IPV4UDPH_LEN);
	memset(msg, 0, sizeof(struct dhcp_msg));

	msg->op = DHCPV4_MSG_BOOT_REQUEST;

	msg->htype = HARDWARE_ETHERNET_TYPE;
	msg->hlen = HARDWARE_ETHERNET_LEN;

	msg->xid = htonl(iface->dhcpv4.xid);
	msg->flags = htons(DHCPV4_MSG_BROADCAST);

	if (iface->dhcpv4.state == NET_DHCPV4_INIT) {
		memset(msg->ciaddr, 0, sizeof(msg->ciaddr));
	} else {
		memcpy(msg->ciaddr, iface->dhcpv4.requested_ip.s4_addr, 4);
	}

	memcpy(msg->chaddr, iface->link_addr.addr, iface->link_addr.len);

	net_buf_add(frag, sizeof(struct dhcp_msg));

	if (!add_sname(buf) ||
	    !add_file(buf) ||
	    !add_cookie(buf) ||
	    !add_msg_type(buf, type)) {
		goto fail;
	}

	return buf;

fail:
	net_nbuf_unref(buf);
	return NULL;
}
Пример #8
0
static void ICACHE_FLASH_ATTR send_ack(struct dhcps_msg *m)
{

		u8_t *end;
	    struct pbuf *p, *q;
	    u8_t *data;
	    u16_t cnt=0;
	    u16_t i;
        create_msg(m);

        end = add_msg_type(&m->options[4], DHCPACK);
        end = add_offer_options(end);
        end = add_end(end);

	    p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
#if DHCPS_DEBUG
		os_printf("udhcp: send_ack>>p->ref = %d\n", p->ref);
#endif
	    if(p != NULL){

#if DHCPS_DEBUG
	        os_printf("dhcps: send_ack>>pbuf_alloc succeed\n");
	        os_printf("dhcps: send_ack>>p->tot_len = %d\n", p->tot_len);
	        os_printf("dhcps: send_ack>>p->len = %d\n", p->len);
#endif
	        q = p;
	        while(q != NULL){
	            data = (u8_t *)q->payload;
	            for(i=0; i<q->len; i++)
	            {
	                data[i] = ((u8_t *) m)[cnt++];
#if DHCPS_DEBUG
					os_printf("%02x ",data[i]);
					if((i+1)%16 == 0){
						os_printf("\n");
					}
#endif
	            }

	            q = q->next;
	        }
	    }else{

#if DHCPS_DEBUG
	        os_printf("dhcps: send_ack>>pbuf_alloc failed\n");
#endif
	        return;
	    }
#if DHCPS_DEBUG
	    err_t SendAck_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
        os_printf("dhcps: send_ack>>udp_sendto result %x\n",SendAck_err_t);
#else
        udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#endif

	    if(p->ref != 0){
#if DHCPS_DEBUG
	        os_printf("udhcp: send_ack>>free pbuf\n");
#endif
	        pbuf_free(p);
	    }
}
Пример #9
0
static void dhcpdHandlePacket(void) {
  struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;

  if (!ipaddr_set) {
    uip_ipaddr( ipaddr,                 10, 200, 0, 1);
    uip_ipaddr( dhcpd_client_ipaddr,    10, 200, 0, 2);
    uip_ipaddr( dhcpd_broadcast_ipaddr, 10, 200, 0, 3);
    uip_sethostaddr(ipaddr);
    ipaddr_set = 1;
  }

  printf("This is a DHCP broadcast op=%d ",m->op);
  if (m->op == DHCP_REQUEST) {
    //printf("xid = %02x %02x %02x %02x ",(m->xid)[0],(m->xid)[1],(m->xid)[2],(m->xid)[3]);
    //printf("secs = %02x ",m->secs);
    //printf("flags (bc?) = %02x ",m->flags);
    if (memcmp(m->options,magic_cookie,4)==0)
      printf("found magic cookie ");
    else {
      printf("magic cookie missing! ");
      return;
    }
    int type = parse_options(&m->options[4], uip_datalen());
    //printf("DHCP message type %d ",type);
    if (type == DHCPDISCOVER) {
      printf("<<discover>> ");
      memcpy((uint8_t*) &dhcp_header,m,sizeof(dhcp_header));
      dhcpd_state = DHCPD_SEND_OFFER;
      udp_poll_request = 1;
      return;


      m->op = DHCP_REPLY;
      uip_ipaddr_t ipaddr;
      //uip_ipaddr( m->yiaddr, 192, 168, 12, 2);
      uip_ipaddr_copy(m->yiaddr,dhcpd_client_ipaddr);
      memset(m->ciaddr,0,4);
      //memset(m->siaddr,0,4);
      uip_ipaddr_copy(m->siaddr,uip_hostaddr);

      u8_t *end;
      end = add_msg_type(&m->options[4], DHCPOFFER);
      //end = add_subnetmask(end, 255,255,255,0);
      end = add_subnetmask(end, 255,255,255, 0xfc); // a /30 address
      end = add_lease_time(end);
      end = add_server_id_myself(end);
      //end = add_dns_server_myself(end);
      //end = add_domain_name(end);
      end = add_end(end);

      uip_send(uip_appdata, end - (u8_t *)uip_appdata);
    }
    if (type == DHCPREQUEST) {
      printf("<<request>> ");
      memcpy((uint8_t*) &dhcp_header,m,sizeof(dhcp_header));
      dhcpd_state = DHCPD_SEND_ACK;
      udp_poll_request = 1;
      return;

      m->op = DHCP_REPLY;
      uip_ipaddr_t ipaddr;
      //uip_ipaddr( m->yiaddr,  192, 168, 12, 2);
      uip_ipaddr_copy(m->yiaddr,dhcpd_client_ipaddr);
      memset(m->ciaddr,0,4);
      //memset(m->siaddr,0,4);
      uip_ipaddr_copy(m->siaddr,uip_hostaddr);


      u8_t *end;
      end = add_msg_type(&m->options[4], DHCPACK);
      //end = add_subnetmask(end, 255,255,255,0);
      //end = add_subnetmask(end, 255,255,255, 0xfC); // a /30 address
      //end = add_subnetmask(end, 255,255,255, 0xfe); // a /31 address
      end = add_subnetmask(end, 255,255,255, 0xfc); // a /30 address
      end = add_lease_time(end);
      end = add_server_id_myself(end);
      //end = add_dns_server_myself(end);
      //end = add_domain_name(end);
      end = add_end(end);

      uip_send(uip_appdata, end - (u8_t *)uip_appdata);
      dhcpd_address_assigned(); // notify the rest of teh system
    }
  }
}