Example #1
0
static void net_configure(void)
{
  struct in_addr addr;
#if defined(CONFIG_EXAMPLE_POLL_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif

  /* Configure uIP */
  /* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_POLL_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xb0;
  mac[3] = 0x0b;
  mac[4] = 0xba;
  mac[5] = 0xbe;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_POLL_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_POLL_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_POLL_NETMASK);
  uip_setnetmask("eth0", &addr);
}
Example #2
0
int igmp_main(int argc, char *argv[])
{
  struct in_addr addr;
#if defined(CONFIG_EXAMPLES_IGMP_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif

  message("Configuring Ethernet...\n");

  /* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLES_IGMP_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_NETMASK);
  uip_setnetmask("eth0", &addr);

  /* Not much of a test for now */
  /* Join the group */

  message("Join group...\n");
  addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_GRPADDR);
  ipmsfilter("eth0", &addr, MCAST_INCLUDE);

  /* Wait a while */

  message("Wait for timeout...\n");
  sleep(5);

  /* Leave the group */

  message("Leave group...\n");
  ipmsfilter("eth0", &addr, MCAST_EXCLUDE);

  /* Wait a while */

  sleep(5);
  message("Exiting...\n");
  return 0;
}
Example #3
0
int sendmail_main(int argc, char *argv[])
{
  struct in_addr addr;
#if defined(CONFIG_EXAMPLES_SENDMAIL_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif
  void *handle;

  printf("sendmail: To: %s\n", g_recipient);
  printf("sendmail: From: %s\n", g_sender);
  printf("sendmail: Subject: %s\n", g_subject);
  printf("sendmail: Body: %s\n", g_msg_body);

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLES_SENDMAIL_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_SENDMAIL_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_SENDMAIL_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_SENDMAIL_NETMASK);
  uip_setnetmask("eth0", &addr);

  /* Then send the mail */

  uip_ipaddr(addr.s_addr, 127, 0, 0, 1);
  handle = smtp_open();
  if (handle)
    {
      smtp_configure(handle, g_host_name, &addr.s_addr);
      smtp_send(handle, g_recipient, NULL, g_sender, g_subject,
                g_msg_body, strlen(g_msg_body));
      smtp_close(handle);
    }
  return 0;
}
Example #4
0
int MAIN_NAME(int argc, char *argv[])
{
  struct in_addr addr;
#ifdef CONFIG_EXAMPLE_NETTEST_NOMAC
  uint8_t mac[IFHWADDRLEN];
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_NETTEST_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xb0;
  mac[3] = 0x0b;
  mac[4] = 0xba;
  mac[5] = 0xbe;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_NETMASK);
  uip_setnetmask("eth0", &addr);

#ifdef CONFIG_EXAMPLE_NETTEST_SERVER
  recv_server();
#else
  send_client();
#endif

  return 0;
}
Example #5
0
int MAIN_NAME(int argc, char *argv[])
{
  struct in_addr addr;
#if defined(CONFIG_EXAMPLE_DHCPD_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_DHCPD_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xb0;
  mac[3] = 0x0b;
  mac[4] = 0xba;
  mac[5] = 0xbe;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_DHCPD_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_DHCPD_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_DHCPD_NETMASK);
  uip_setnetmask("eth0", &addr);

  /* Then start the server */
  
  dhcpd_run();
  return 0;
}
Example #6
0
int wget_main(int argc, char *argv[])
{
  struct in_addr addr;
#if defined(CONFIG_EXAMPLES_WGET_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLES_WGET_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WGET_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WGET_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WGET_NETMASK);
  uip_setnetmask("eth0", &addr);

  /* Then start the server */
  
  wget(CONFIG_EXAMPLES_WGET_URL, g_iobuffer, 512, callback, NULL);
  return 0;
}
Example #7
0
static void fptd_netinit(void)
{
#ifndef CONFIG_EXAMPLES_FTPD_NONETINIT
  struct in_addr addr;
#ifdef CONFIG_EXAMPLES_FTPD_NOMAC
  uint8_t mac[IFHWADDRLEN];
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLES_FTPD_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_FTPD_IPADDR);
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_FTPD_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_FTPD_NETMASK);
  uip_setnetmask("eth0", &addr);
#endif /* CONFIG_EXAMPLES_FTPD_NONETINIT */
}
Example #8
0
int user_start(int argc, char *argv[])
{
    struct in_addr addr;
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_EXAMPLE_UIP_NOMAC)
    uint8_t mac[IFHWADDRLEN];
#endif
#ifdef CONFIG_EXAMPLE_UIP_DHCPC
    void *handle;
#endif

    /* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_UIP_NOMAC
    mac[0] = 0x00;
    mac[1] = 0xe0;
    mac[2] = 0xb0;
    mac[3] = 0x0b;
    mac[4] = 0xba;
    mac[5] = 0xbe;
    uip_setmacaddr("eth0", mac);
#endif

    /* Set up our host address */

#ifdef CONFIG_EXAMPLE_UIP_DHCPC
    addr.s_addr = 0;
#else
    addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_IPADDR);
#endif
    uip_sethostaddr("eth0", &addr);

    /* Set up the default router address */

    addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_DRIPADDR);
    uip_setdraddr("eth0", &addr);

    /* Setup the subnet mask */

    addr.s_addr = HTONL(CONFIG_EXAMPLE_UIP_NETMASK);
    uip_setnetmask("eth0", &addr);

#ifdef CONFIG_EXAMPLE_UIP_DHCPC
    /* Set up the resolver */

    resolv_init();

    /* Get the MAC address of the NIC */

    uip_getmacaddr("eth0", mac);

    /* Set up the DHCPC modules */

    handle = dhcpc_open(&mac, IFHWADDRLEN);

    /* Get an IP address.  Note:  there is no logic here for renewing the address in this
     * example.  The address should be renewed in ds.lease_time/2 seconds.
     */

    printf("Getting IP address\n");
    if (handle)
    {
        struct dhcpc_state ds;
        (void)dhcpc_request(handle, &ds);
        uip_sethostaddr("eth1", &ds.ipaddr);
        if (ds.netmask.s_addr != 0)
        {
            uip_setnetmask("eth0", &ds.netmask);
        }
        if (ds.default_router.s_addr != 0)
        {
            uip_setdraddr("eth0", &ds.default_router);
        }
        if (ds.dnsaddr.s_addr != 0)
        {
            resolv_conf(&ds.dnsaddr);
        }
        dhcpc_close(handle);
        printf("IP: %s\n", inet_ntoa(ds.ipaddr));
    }
#endif

#ifdef CONFIG_NET_TCP
    printf("Starting webserver\n");
    httpd_init();
    httpd_listen();
#endif

    while(1)
    {
        sleep(3);
        printf("main: Still running\n");
#if CONFIG_NFILE_DESCRIPTORS > 0
        fflush(stdout);
#endif
    }
    return 0;
}
Example #9
0
int discover_main(int argc, char *argv[])
{
  /* If this task is excecutated as an NSH built-in function, then the
   * network has already been configured by NSH's start-up logic.
   */

#ifndef CONFIG_NSH_BUILTIN_APPS
  struct in_addr addr;
#if defined(CONFIG_EXAMPLES_DISCOVER_DHCPC) || defined(CONFIG_EXAMPLES_DISCOVER_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif
#ifdef CONFIG_EXAMPLES_DISCOVER_DHCPC
  void *handle;
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLES_DISCOVER_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

#ifdef CONFIG_EXAMPLES_DISCOVER_DHCPC
  addr.s_addr = 0;
#else
  addr.s_addr = HTONL(CONFIG_EXAMPLES_DISCOVER_IPADDR);
#endif
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_DISCOVER_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_DISCOVER_NETMASK);
  uip_setnetmask("eth0", &addr);

#ifdef CONFIG_EXAMPLES_DISCOVER_DHCPC
  /* Set up the resolver */

  dns_bind();

  /* Get the MAC address of the NIC */

  uip_getmacaddr("eth0", mac);

  /* Set up the DHCPC modules */

  handle = dhcpc_open(&mac, IFHWADDRLEN);

  /* Get an IP address.  Note:  there is no logic here for renewing the address in this
   * example.  The address should be renewed in ds.lease_time/2 seconds.
   */

  printf("Getting IP address\n");
  if (handle)
    {
      struct dhcpc_state ds;
      (void)dhcpc_request(handle, &ds);
      uip_sethostaddr("eth1", &ds.ipaddr);

      if (ds.netmask.s_addr != 0)
        {
          uip_setnetmask("eth0", &ds.netmask);
        }

      if (ds.default_router.s_addr != 0)
        {
          uip_setdraddr("eth0", &ds.default_router);
        }

      if (ds.dnsaddr.s_addr != 0)
        {
          dns_setserver(&ds.dnsaddr);
        }

      dhcpc_close(handle);
      printf("IP: %s\n", inet_ntoa(ds.ipaddr));
    }

#endif /* CONFIG_EXAMPLES_DISCOVER_DHCPC */
#endif /* CONFIG_NSH_BUILTIN_APPS */

  if (discover_start(NULL) < 0)
    {
      ndbg("Could not start discover daemon.\n");
      return ERROR;
    }

  return OK;
}
Example #10
0
static inline void wlan_bringup(void)
{
#if defined(CONFIG_EXAMPLES_WLAN_DHCPC) || defined(CONFIG_EXAMPLES_WLAN_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif
  struct in_addr addr;
#ifdef CONFIG_EXAMPLES_WLAN_DHCPC
  void *handle;
#endif

  /* Many embedded network interfaces must have a software assigned
   * MAC
   */

#ifdef CONFIG_EXAMPLES_WLAN_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WLAN_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_WLAN_NETMASK);
  uip_setnetmask("eth0", &addr);

  /* Set up our host address */

#ifdef CONFIG_EXAMPLES_WLAN_DHCPC
  addr.s_addr = 0;
#else
  addr.s_addr = HTONL(CONFIG_EXAMPLES_WLAN_IPADDR);
#endif
  uip_sethostaddr("eth0", &addr);

#ifdef CONFIG_EXAMPLES_WLAN_DHCPC
  /* Set up the resolver */

  resolv_init();

  /* Get the MAC address of the NIC */

  uip_getmacaddr("eth0", mac);

  /* Set up the DHCPC modules */

  handle = dhcpc_open(&mac, IFHWADDRLEN);

  /* Get an IP address.  Note:  there is no logic here for renewing
   * the address in this example.  The address should be renewed in
   * ds.lease_time/2 seconds.
   */

  printf("Getting IP address\n");
  if (handle)
    {
      struct dhcpc_state ds;
      (void)dhcpc_request(handle, &ds);
      uip_sethostaddr("eth1", &ds.ipaddr);
      if (ds.netmask.s_addr != 0)
        {
          uip_setnetmask("eth0", &ds.netmask);
        }
      if (ds.default_router.s_addr != 0)
        {
          uip_setdraddr("eth0", &ds.default_router);
        }
      if (ds.dnsaddr.s_addr != 0)
        {
          resolv_conf(&ds.dnsaddr);
        }
      dhcpc_close(handle);
      printf("IP: %s\n", inet_ntoa(ds.ipaddr));
    }
#endif
}
Example #11
0
int thttp_main(int argc, char *argv[])
{
  struct in_addr addr;
#ifdef CONFIG_EXAMPLE_THTTPD_NOMAC
  uint8_t mac[IFHWADDRLEN];
#endif
  char *thttpd_argv = "thttpd";
  int ret;

  /* Configure SLIP */

#ifdef CONFIG_NET_SLIP
  ret = slip_initialize(SLIP_DEVNO, CONFIG_NET_SLIPTTY);
  if (ret < 0)
    {
      message("ERROR: SLIP initialization failed: %d\n", ret);
      exit(1);
    }
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLE_THTTPD_NOMAC
  message("Assigning MAC\n");

  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr(NET_DEVNAME, mac);
#endif

  /* Set up our host address */

  message("Setup network addresses\n");
  addr.s_addr = HTONL(CONFIG_THTTPD_IPADDR);
  uip_sethostaddr(NET_DEVNAME, &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_THTTPD_DRIPADDR);
  uip_setdraddr(NET_DEVNAME, &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLE_THTTPD_NETMASK);
  uip_setnetmask(NET_DEVNAME, &addr);

  /* Initialize the NXFLAT binary loader */

  message("Initializing the NXFLAT binary loader\n");
  ret = nxflat_initialize();
  if (ret < 0)
    {
      message("ERROR: Initialization of the NXFLAT loader failed: %d\n", ret);
      exit(2);
    }

  /* Create a ROM disk for the ROMFS filesystem */

  message("Registering romdisk\n");
  ret = romdisk_register(0, (uint8_t*)romfs_img, NSECTORS(romfs_img_len), SECTORSIZE);
  if (ret < 0)
    {
      message("ERROR: romdisk_register failed: %d\n", ret);
      nxflat_uninitialize();
      exit(1);
    }

  /* Mount the file system */

  message("Mounting ROMFS filesystem at target=%s with source=%s\n",
         MOUNTPT, ROMFSDEV);

  ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL);
  if (ret < 0)
    {
      message("ERROR: mount(%s,%s,romfs) failed: %s\n",
              ROMFSDEV, MOUNTPT, errno);
      nxflat_uninitialize();
    }

  /* Start THTTPD.  At present, symbol table info is passed via global variables */

  g_thttpdsymtab   = exports;
  g_thttpdnsymbols = NEXPORTS;

  message("Starting THTTPD\n");
  msgflush();
  thttpd_main(1, &thttpd_argv);
  message("THTTPD terminated\n");
  msgflush();
  return 0;
}
Example #12
0
static int tcpecho_netsetup()
{
  /* If this task is excecutated as an NSH built-in function, then the
   * network has already been configured by NSH's start-up logic.
   */

#ifndef CONFIG_NSH_BUILTIN_APPS
  struct in_addr addr;
#if defined(CONFIG_EXAMPLES_TCPECHO_DHCPC) || defined(CONFIG_EXAMPLES_TCPECHO_NOMAC)
  uint8_t mac[IFHWADDRLEN];
#endif
#ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC
  struct dhcpc_state ds;
  void *handle;
#endif

/* Many embedded network interfaces must have a software assigned MAC */

#ifdef CONFIG_EXAMPLES_TCPECHO_NOMAC
  mac[0] = 0x00;
  mac[1] = 0xe0;
  mac[2] = 0xde;
  mac[3] = 0xad;
  mac[4] = 0xbe;
  mac[5] = 0xef;
  uip_setmacaddr("eth0", mac);
#endif

  /* Set up our host address */

#ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC
  addr.s_addr = 0;
#else
  addr.s_addr = HTONL(CONFIG_EXAMPLES_TCPECHO_IPADDR);
#endif
  uip_sethostaddr("eth0", &addr);

  /* Set up the default router address */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_TCPECHO_DRIPADDR);
  uip_setdraddr("eth0", &addr);

  /* Setup the subnet mask */

  addr.s_addr = HTONL(CONFIG_EXAMPLES_TCPECHO_NETMASK);
  uip_setnetmask("eth0", &addr);

#ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC
  /* Set up the resolver */

  resolv_init();

  /* Get the MAC address of the NIC */

  uip_getmacaddr("eth0", mac);

  /* Set up the DHCPC modules */

  handle = dhcpc_open(&mac, IFHWADDRLEN);

  /* Get an IP address.  Note:  there is no logic here for renewing the address in this
   * example.  The address should be renewed in ds.lease_time/2 seconds.
   */

  if (!handle)
    {
      return ERROR;
    }

  if (dhcpc_request(handle, &ds) != OK)
    {
      return ERROR;
    }

  uip_sethostaddr("eth1", &ds.ipaddr);

  if (ds.netmask.s_addr != 0)
    {
      uip_setnetmask("eth0", &ds.netmask);
    }

  if (ds.default_router.s_addr != 0)
    {
      uip_setdraddr("eth0", &ds.default_router);
    }

  if (ds.dnsaddr.s_addr != 0)
    {
      resolv_conf(&ds.dnsaddr);
    }

  dhcpc_close(handle);
  printf("IP: %s\n", inet_ntoa(ds.ipaddr));

#endif /* CONFIG_EXAMPLES_TCPECHO_DHCPC */
#endif /* CONFIG_NSH_BUILTIN_APPS */

  return OK;
}