Esempio n. 1
0
/*--------------------------------------------------------------------*/
static void
init(void)
{
  /*
   * Set out output function as the function to be called from uIP to
   * send a packet.
   */
  tcpip_set_outputfunc(uip_driver_send);
}
void
slipnet_init(void)
{
  tcpip_set_outputfunc(tip_output);
  slip_set_input_callback(slip_input_call);

  slip_arch_init(115200);
  process_start(&slip_process, NULL);
 
}
Esempio n. 3
0
void
packet_filter_init(void)
{
  wireless_outputfunc = tcpip_get_outputfunc();
  tcpip_set_outputfunc(bridge_output);

  tcpip_inputfunc = tcpip_get_inputfunc();

  tcpip_set_inputfunc(wireless_input);
}
Esempio n. 4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(uip_fw_process, ev, data)
{
  PROCESS_BEGIN();

  tcpip_set_outputfunc(uip_fw_output);

  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);

  PROCESS_END();
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tapdev_process, ev, data)
{
  PROCESS_POLLHANDLER(pollhandler());

  PROCESS_BEGIN();

  tapdev_init();
#if !UIP_CONF_IPV6
  tcpip_set_outputfunc(tapdev_output);
#else
  tcpip_set_outputfunc(tapdev_send);
#endif
  process_poll(&tapdev_process);

  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);

  tapdev_exit();

  PROCESS_END();
}
Esempio n. 6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(wpcap_process, ev, data)
{
  PROCESS_POLLHANDLER(pollhandler());

  PROCESS_BEGIN();

  wpcap_init();

#if !UIP_CONF_IPV6
  tcpip_set_outputfunc(wpcap_output);
#else
#if !FALLBACK_HAS_ETHERNET_HEADERS
  tcpip_set_outputfunc(wpcap_send);
#endif
#endif /* !UIP_CONF_IPV6 */

  process_poll(&wpcap_process);

  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);

  wpcap_exit();

  PROCESS_END();
}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ethernet_process, ev, data)
{
  PROCESS_POLLHANDLER(pollhandler());

  PROCESS_BEGIN();

  ethernet_init((struct ethernet_config *)data);

  tcpip_set_outputfunc(ethernet_output);

  process_poll(&ethernet_process);

  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);

  ethernet_exit();

  PROCESS_END();
}
Esempio n. 8
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(rtl8019_process, ev, data)
{
  PROCESS_POLLHANDLER(pollhandler());

  PROCESS_BEGIN();

  RTL8019dev_init();

  tcpip_set_outputfunc(rtl8019_output);

  process_poll(&rtl8019_process);
  
  PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);

  RTL8019dev_exit();

  PROCESS_END();
}
Esempio n. 9
0
static int network_initialization(void)
{
	/* Initialize and start Contiki uIP stack */
	clock_init();

	rtimer_init();
	ctimer_init();

	process_init();
	tcpip_set_outputfunc(net_tcpip_output);

	process_start(&tcpip_process, NULL);
	process_start(&simple_udp_process, NULL);
	process_start(&etimer_process, NULL);

	slip_start();

	return 0;
}
Esempio n. 10
0
void network_setup() {
  printf("network_setup\n");
  
  uip_ipaddr_t ipaddr;
  uip_ipaddr_t gatewayAddr;
  uip_ipaddr_t netmaskAddr;

  uip_lladdr.addr[0] = MAC_ADDRESS[0];
  uip_lladdr.addr[1] = MAC_ADDRESS[1];
  uip_lladdr.addr[2] = MAC_ADDRESS[2];
  uip_lladdr.addr[3] = MAC_ADDRESS[3];
  uip_lladdr.addr[4] = MAC_ADDRESS[4];
  uip_lladdr.addr[5] = MAC_ADDRESS[5];

  uip_ipaddr(&ipaddr, 192, 168, 0, 101);
  uip_sethostaddr(&ipaddr);

  uip_ipaddr(&gatewayAddr, 192, 168, 0, 1);
  uip_setdraddr(&gatewayAddr);

  uip_ipaddr(&netmaskAddr, 255, 255, 255, 0);
  uip_setnetmask(&netmaskAddr);

  tcpip_set_outputfunc(enc28j60_tcp_output);
  enc28j60_init(uip_lladdr.addr);
  
  uip_init();

  uip_arp_init();
  
  printf("Start RS232UDP Process\n");
  process_start(&rs232udp_process, NULL);

  printf("Start network Process\n");
  process_start(&network_process, NULL);

  printf("END network_setup\n");
}
Esempio n. 11
0
int main(int argc, char **argv)
{
	printf("uIPv6 test project\n");

    uip_ipaddr_t ipaddr;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    if((ipaddr.u16[0] != 0) ||
       (ipaddr.u16[1] != 0) ||
       (ipaddr.u16[2] != 0) ||
       (ipaddr.u16[3] != 0)) {

      uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);

      uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
      uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
    }
	
	printf("Process subsystem init\n");
	process_init();
	printf("Ok\n");

	printf("Start etimer process\n");
	process_start(&etimer_process, NULL);
	printf("Ok\n");

	printf("Init ctimer\n");
	ctimer_init();
	printf("Ok\n");

	printf("Init tapdev\n");
	tapdev_init();
	tcpip_set_outputfunc(tapdev_send);
	printf("Ok\n");

	printf("Start tcpip process\n");
	process_start(&tcpip_process, NULL);
	printf("Ok\n");

	printf("Start TCP server on 8080 port\n");
	process_start(&tcp_server, NULL);
	printf("Ok\n");

	uint8_t i;
	for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
		if(uip_ds6_if.addr_list[i].isused) {
			printf("IPV6 Addresss: ");
			printf("%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X",
					uip_ds6_if.addr_list[i].ipaddr.u8[0],
					uip_ds6_if.addr_list[i].ipaddr.u8[1],
					uip_ds6_if.addr_list[i].ipaddr.u8[2],
					uip_ds6_if.addr_list[i].ipaddr.u8[3],
					uip_ds6_if.addr_list[i].ipaddr.u8[4],
					uip_ds6_if.addr_list[i].ipaddr.u8[5],
					uip_ds6_if.addr_list[i].ipaddr.u8[6],
					uip_ds6_if.addr_list[i].ipaddr.u8[7],
					uip_ds6_if.addr_list[i].ipaddr.u8[8],
					uip_ds6_if.addr_list[i].ipaddr.u8[9],
					uip_ds6_if.addr_list[i].ipaddr.u8[10],
					uip_ds6_if.addr_list[i].ipaddr.u8[11],
					uip_ds6_if.addr_list[i].ipaddr.u8[12],
					uip_ds6_if.addr_list[i].ipaddr.u8[13],
					uip_ds6_if.addr_list[i].ipaddr.u8[14],
					uip_ds6_if.addr_list[i].ipaddr.u8[15]);
			printf("\n");
		}
	}

	while(1){
		process_run();
		etimer_request_poll();
		uip_len = tapdev_poll();

		if(uip_len > 0){
			if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)){
				tcpip_input();
			}
		}
	}
}
Esempio n. 12
0
static uint8_t
bridge_output(const uip_lladdr_t * dest)
{
  int ethernetDest = 0;
  int wsnDest = 0;
  if(uip_len == 0) {
    LOG6LBR_ERROR("Trying to send empty packet\n");
    return 0;
  }
  if(!IS_BROADCAST_ADDR(dest)) {
    LOG6LBR_LLADDR_PRINTF(PACKET, PF_OUT, dest, "bridge_output: Sending packet to ");
  } else {
    LOG6LBR_PRINTF(PACKET, PF_OUT, "bridge_output: Sending packet to Broadcast\n");
  }

  if(uip_ipaddr_prefixcmp(&eth_net_prefix, &UIP_IP_BUF->destipaddr, 64)) {
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &eth_net_prefix, "dest prefix eth : ");
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &UIP_IP_BUF->destipaddr, "dest eth : ");
    //Packet destinated to the Ethernet subnet
    ethernetDest = 1;
  } else if(uip_ipaddr_prefixcmp(&wsn_net_prefix, &UIP_IP_BUF->destipaddr, 64)) {
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &wsn_net_prefix, "dest prefix wsn : ");
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &UIP_IP_BUF->destipaddr, "dest prefix wsn : ");
    //Packet destinated to the WSN subnet
    wsnDest = 1;
  } else if(IS_EUI64_ADDR(dest)) {
    //Destination unknown but next-hop is in WSN subnet
    wsnDest = 1;
  } else if (IS_EUI48_ADDR(dest)) {
    //Destination unknown but next-hop is in Ethernet subnet
    ethernetDest = 1;
  } else {
    //Obviously we can not guess the target segment for a multicast packet
    //So we have to check the packet source prefix (and match it on the Ethernet segment prefix)
    //or, in case of link-local packet, check packet type and/or packet data
#if UIP_CONF_IPV6_RPL
    //in RPL mode, RA and RS packets are used to configure the Ethernet subnet
    if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 &&
        (UIP_ICMP_BUF->type == ICMP6_RA || UIP_ICMP_BUF->type == ICMP6_RS)) {
      ethernetDest = 1;
    } else if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6
        && UIP_ICMP_BUF->type == ICMP6_NS
        && uip_ipaddr_prefixcmp(&eth_net_prefix,
                                &UIP_ND6_NS_BUF->tgtipaddr, 64)) {
      ethernetDest = 1;
#else
    //in NDP mode, RA and RS packets are used to configure the WSN subnet
    if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 &&
        (UIP_ICMP_BUF->type == ICMP6_RA || UIP_ICMP_BUF->type == ICMP6_RS)) {
      wsnDest = 1;
    } else if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6
        && UIP_ICMP_BUF->type == ICMP6_NS
        && uip_ipaddr_prefixcmp(&wsn_net_prefix,
                                &UIP_ND6_NS_BUF->tgtipaddr, 64)) {
      wsnDest = 1;
#endif
    } else if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 &&
        UIP_ICMP_BUF->type == ICMP6_RPL) {
      //RPL packets are always for WSN subnet
      wsnDest = 1;
    } else if(uip_ipaddr_prefixcmp(&eth_net_prefix, &UIP_IP_BUF->srcipaddr, 64)) {
      //Packet type unknown, but source is from Ethernet subnet
      ethernetDest = 1;
    } else if(uip_ipaddr_prefixcmp(&wsn_net_prefix, &UIP_IP_BUF->srcipaddr, 64)) {
      //Packet type unknown, but source is from WSN subnet
      wsnDest = 1;
    } else {
      // We could not guess the destination, forward to both
      ethernetDest = 1;
      wsnDest = 1;
    }
  }
  if(wsnDest) {
#if CETIC_6LBR_ONE_ITF
    eth_output(&wsn_mac_addr, dest);
#else
    wireless_output(NULL, dest);
#endif
  }
  if(ethernetDest) {
    eth_output(NULL, dest);
  }
  return 0;
}
#endif

/*---------------------------------------------------------------------------*/

void
packet_filter_init(void)
{
  wireless_outputfunc = tcpip_get_outputfunc();
  tcpip_set_outputfunc(bridge_output);

  tcpip_inputfunc = tcpip_get_inputfunc();

  tcpip_set_inputfunc(wireless_input);
}
Esempio n. 13
0
void enc28j60_setup(ENC28J60 *enc28j60) {
  GPIO_InitParams gpio;

  enc28j60->_enc28j60_bank = 0xff;

  RCC_peripheralClockEnableForPort(enc28j60->csPort);
  RCC_peripheralClockEnableForPort(enc28j60->resetPort);

  GPIO_initParamsInit(&gpio);
  gpio.mode = GPIO_Mode_output;
  gpio.outputType = GPIO_OutputType_pushPull;
  gpio.speed = GPIO_Speed_high;

  gpio.port = enc28j60->csPort;
  gpio.pin = enc28j60->csPin;
  GPIO_init(&gpio);
  _enc28j60_csDeassert(enc28j60);

  gpio.port = enc28j60->resetPort;
  gpio.pin = enc28j60->resetPin;
  GPIO_init(&gpio);

  timer_set(&enc28j60->_enc28j60_periodicTimer, CLOCK_SECOND / 4);

  // perform system reset
  _enc28j60_resetAssert(enc28j60);
  IWDG_RESET;
  sleep_ms(50);
  _enc28j60_resetDeassert(enc28j60);
  IWDG_RESET;
  sleep_ms(1000);

  _enc28j60_writeOp(enc28j60, ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
  IWDG_RESET;
  sleep_ms(50);

  // check CLKRDY bit to see if reset is complete
  // The CLKRDY does not work. See Rev. B4 Silicon Errata point. Just wait.
  IWDG_RESET;
  while (1) {
    uint8_t r = _enc28j60_readReg(enc28j60, ESTAT);
    if (r & ESTAT_CLKRDY) {
      break;
    }
#ifdef ENC28J60_DEBUG
    printf("?ESTAT: 0x%02x\n", r);
#endif
    sleep_ms(100);
  }
  IWDG_RESET;

  // do bank 0 stuff
  // initialize receive buffer
  // 16-bit transfers, must write low byte first
  // set receive buffer start address
  enc28j60->_enc28j60_nextPacketPtr = RXSTART_INIT;

  // Rx start
  _enc28j60_writeRegPair(enc28j60, ERXSTL, RXSTART_INIT);

  // set receive pointer address
  _enc28j60_writeRegPair(enc28j60, ERXRDPTL, RXSTART_INIT);

  // RX end
  _enc28j60_writeRegPair(enc28j60, ERXNDL, RXSTOP_INIT);

  // TX start
  _enc28j60_writeRegPair(enc28j60, ETXSTL, TXSTART_INIT);

  // TX end
  //_enc28j60_writeRegPair(enc28j60, ETXNDL, TXSTOP_INIT);

  IWDG_RESET;

  // do bank 2 stuff
  // enable MAC receive
  // and bring MAC out of reset (writes 0x00 to MACON2)
  _enc28j60_writeRegPair(enc28j60, MACON1, MACON1_MARXEN | MACON1_TXPAUS | MACON1_RXPAUS);

  // bring MAC out of reset
  _enc28j60_writeRegPair(enc28j60, MACON2, 0x00);

  // enable automatic padding to 60bytes and CRC operations
  _enc28j60_writeOp(enc28j60, ENC28J60_BIT_FIELD_SET, MACON3, MACON3_PADCFG0 | MACON3_TXCRCEN | MACON3_FRMLNEN);

  // set inter-frame gap (non-back-to-back)
  _enc28j60_writeRegPair(enc28j60, MAIPGL, 0x0C12);

  // set inter-frame gap (back-to-back)
  _enc28j60_writeReg(enc28j60, MABBIPG, 0x12);

  // Set the maximum packet size which the controller will accept
  // Do not send packets longer than MAX_FRAMELEN:
  _enc28j60_writeRegPair(enc28j60, MAMXFLL, MAX_FRAMELEN);

  IWDG_RESET;

  // do bank 1 stuff, packet filter:
  // For broadcast packets we allow only ARP packtets
  // All other packets should be unicast only for our mac (MAADR)
  //
  // The pattern to match on is therefore
  // Type     ETH.DST
  // ARP      BROADCAST
  // 06 08 -- ff ff ff ff ff ff -> ip checksum for theses bytes=f7f9
  // in binary these poitions are:11 0000 0011 1111
  // This is hex 303F->EPMM0=0x3f,EPMM1=0x30
  //TODO define specific pattern to receive dhcp-broadcast packages instead of setting ERFCON_BCEN!
  _enc28j60_writeReg(enc28j60, ERXFCON, 0);//ERXFCON_UCEN | ERXFCON_CRCEN | ERXFCON_PMEN | ERXFCON_BCEN);
  _enc28j60_writeRegPair(enc28j60, EPMM0, 0x303f);
  _enc28j60_writeRegPair(enc28j60, EPMCSL, 0xf7f9);

  IWDG_RESET;

  // do bank 3 stuff
  // write MAC address
  // NOTE: MAC address in ENC28J60 is byte-backward
  _enc28j60_writeReg(enc28j60, MAADR5, enc28j60->macAddress[0]);
  _enc28j60_writeReg(enc28j60, MAADR4, enc28j60->macAddress[1]);
  _enc28j60_writeReg(enc28j60, MAADR3, enc28j60->macAddress[2]);
  _enc28j60_writeReg(enc28j60, MAADR2, enc28j60->macAddress[3]);
  _enc28j60_writeReg(enc28j60, MAADR1, enc28j60->macAddress[4]);
  _enc28j60_writeReg(enc28j60, MAADR0, enc28j60->macAddress[5]);

  IWDG_RESET;

  // no loopback of transmitted frames
  _enc28j60_phyWrite(enc28j60, PHCON2, PHCON2_HDLDIS);

  // switch to bank 0
  _enc28j60_setBank(enc28j60, ECON1);

  // enable interrutps
  _enc28j60_writeOp(enc28j60, ENC28J60_BIT_FIELD_SET, EIE, EIE_INTIE | EIE_PKTIE);

  // enable packet reception
  _enc28j60_writeOp(enc28j60, ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN);

  // Configure leds
  _enc28j60_phyWrite(enc28j60, PHLCON, 0x476);

  _enc28j60_debugDump(enc28j60);

  tcpip_set_outputfunc(enc28j60_tcp_output);

  IWDG_RESET;

  sleep_ms(100);
  IWDG_RESET;
}