Exemple #1
0
nsapi_error_t mbed_lwip_init(emac_interface_t *emac)
{
    // Check if we've already brought up lwip
    if (!mbed_lwip_get_mac_address()) {
        // Set up network
        mbed_lwip_set_mac_address();

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_has_addr, 0);

        tcpip_init(mbed_lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        memset(&lwip_netif, 0, sizeof lwip_netif);
        if (!netif_add(&lwip_netif,
#if LWIP_IPV4
                       0, 0, 0,
#endif
                       emac, MBED_NETIF_INIT_FN, tcpip_input)) {
            return NSAPI_ERROR_DEVICE_ERROR;
        }

        netif_set_default(&lwip_netif);

        netif_set_link_callback(&lwip_netif, mbed_lwip_netif_link_irq);
        netif_set_status_callback(&lwip_netif, mbed_lwip_netif_status_irq);

#if !DEVICE_EMAC
        eth_arch_enable_interrupts();
#endif
    }

    return NSAPI_ERROR_OK;
}
Exemple #2
0
void fifoInit(fifo_t * fifo)
{
  fifo->dataslot  = 0;
  fifo->emptyslot = 0;
  fifo->len       = 0;
  fifo->sem    = sys_sem_new(1);  /* critical section 1=free to enter */
  fifo->getSem = sys_sem_new(0);  /* 0 = no one waiting */
  fifo->getWaiting = FALSE;
}
Exemple #3
0
void fifoInit(fifo_t * fifo)
{
	fifo->dataslot  = 0;
	fifo->emptyslot = 0;
	fifo->len       = 0;
	if(sys_sem_new(&fifo->sem, 1) != ERR_OK) {  /* critical section 1=free to enter */
		LWIP_ASSERT("Failed to create semaphore", 0);
	}
	if(sys_sem_new(&fifo->getSem, 0) != ERR_OK) {  /* 0 = no one waiting */
		LWIP_ASSERT("Failed to create semaphore", 0);
	}
	fifo->getWaiting = FALSE;
}
Exemple #4
0
nsapi_error_t mbed_lwip_bringdown_2(bool ppp)
{
    // Check if we've connected
    if (lwip_connected == NSAPI_STATUS_DISCONNECTED) {
        return NSAPI_ERROR_PARAMETER;
    }

#if LWIP_DHCP
    // Disconnect from the network
    if (lwip_dhcp) {
        dhcp_release(&lwip_netif);
        dhcp_stop(&lwip_netif);
        lwip_dhcp = false;
        lwip_dhcp_has_to_be_set = false;
    }
#endif

    if (ppp) {
        /* this is a blocking call, returns when PPP is properly closed */
       err_t err = ppp_lwip_disconnect();
       if (err) {
           return mbed_lwip_err_remap(err);
       }
       MBED_ASSERT(!netif_is_link_up(&lwip_netif));
       /*if (netif_is_link_up(&lwip_netif)) {
           if (sys_arch_sem_wait(&lwip_netif_unlinked, 15000) == SYS_ARCH_TIMEOUT) {
               return NSAPI_ERROR_DEVICE_ERROR;
           }
       }*/
    } else {
        netif_set_down(&lwip_netif);
    }

#if LWIP_IPV6
    mbed_lwip_clear_ipv6_addresses(&lwip_netif);
#endif

    sys_sem_free(&lwip_netif_has_any_addr);
    sys_sem_new(&lwip_netif_has_any_addr, 0);
#if PREF_ADDR_TIMEOUT
    sys_sem_free(&lwip_netif_has_pref_addr);
    sys_sem_new(&lwip_netif_has_pref_addr, 0);
#endif
#if BOTH_ADDR_TIMEOUT
    sys_sem_free(&lwip_netif_has_both_addr);
    sys_sem_new(&lwip_netif_has_both_addr, 0);
#endif
    lwip_has_addr_state = 0;
    lwip_connected = NSAPI_STATUS_DISCONNECTED;
    return 0;
}
int
lwip_close(int s)
{
  struct lwip_socket *sock;

  LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s));
  if (!socksem)
      socksem = sys_sem_new(1);

  /* We cannot allow multiple closes of the same socket. */
  sys_sem_wait(socksem);

  sock = get_socket(s);
  if (!sock) {
      sys_sem_signal(socksem);
      set_errno(EBADF);
      return -1;
  }

  netconn_delete(sock->conn);
  if (sock->lastdata) {
    netbuf_delete(sock->lastdata);
  }
  sock->lastdata = NULL;
  sock->lastoffset = 0;
  sock->conn = NULL;
  sys_sem_signal(socksem);
  sock_set_errno(sock, 0);
  return 0;
}
static int
alloc_socket(struct netconn *newconn)
{
  int i;

  if (!socksem)
      socksem = sys_sem_new(1);

  /* Protect socket array */
  sys_sem_wait(socksem);

  /* allocate a new socket identifier */
  for(i = 0; i < NUM_SOCKETS; ++i) {
    if (!sockets[i].conn) {
      sockets[i].conn = newconn;
      sockets[i].lastdata = NULL;
      sockets[i].lastoffset = 0;
      sockets[i].rcvevent = 0;
      sockets[i].sendevent = 1; /* TCP send buf is empty */
      sockets[i].flags = 0;
      sockets[i].err = 0;
      sys_sem_signal(socksem);
      return i;
    }
  }
  sys_sem_signal(socksem);
  return -1;
}
Exemple #7
0
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
  sys_sem_t sem;
  LWIP_UNUSED_ARG(arg);

  if(sys_sem_new(&sem, 0) != ERR_OK) {
    LWIP_ASSERT("Failed to create semaphore", 0);
  }
  tcpip_init(tcpip_init_done, &sem);
  sys_sem_wait(&sem);
  printf("TCP/IP initialized.\n");

#if LWIP_SOCKET
  if(ping_flag) {
    sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  }
#endif

  printf("Applications started.\n");


#ifdef MEM_PERF
  mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
#if 0
    stats_display();
#endif
  /* Block forever. */
  sys_thread_new("pppos_rx_thread", pppos_rx_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  sys_sem_wait(&sem);
}
Exemple #8
0
/*-----------------------------------------------------------------------------------*/
void
pbuf_init(void)
{
  struct pbuf *p, *q;
  uint8_t i;

  pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
  ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT == 0);

#ifdef PBUF_STATS
  stats.pbuf.avail = PBUF_POOL_SIZE;
#endif /* PBUF_STATS */

  /* Set up ->next pointers to link the pbufs of the pool together. */
  p = pbuf_pool;

  for(i = 0; i < PBUF_POOL_SIZE; ++i) {
    p->next = (struct pbuf *)((uint8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
    p->len = p->tot_len = PBUF_POOL_BUFSIZE;
    p->payload = MEM_ALIGN((void *)((uint8_t *)p + sizeof(struct pbuf)));
    q = p;
    p = p->next;
  }

  /* The ->next pointer of last pbuf is NULL to indicate that there
     are no more pbufs in the pool. */
  q->next = NULL;

  pbuf_pool_alloc_lock = 0;
  pbuf_pool_free_lock = 0;
  pbuf_pool_free_sem = sys_sem_new(1);

}
Exemple #9
0
/*-----------------------------------------------------------------------------------*/
err_t
unixif_init_client(struct netif *netif)
{
  struct unixif *unixif;
  unixif = (struct unixif *)malloc(sizeof(struct unixif));
  if (!unixif) {
    return ERR_MEM;
  }
  netif->state = unixif;
  netif->name[0] = 'u';
  netif->name[1] = 'n';
  netif->output = unixif_output;

  unixif->fd = unix_socket_client("/tmp/lwip-lower");
  if (unixif->fd == -1) {
    perror("unixif_init");
    abort();
  }
  unixif->q = list_new(UNIXIF_QUEUELEN);
  if(sys_sem_new(&unixif->sem, 0) != ERR_OK) {
    LWIP_ASSERT("Failed to create semaphore", 0);
  }
  sys_thread_new("unixif_thread", unixif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  sys_thread_new("unixif_thread2", unixif_thread2, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  return ERR_OK;
}
void
mem_init(void)
{
  struct mem *mem;

#if 1
  /* Adam original */
#else
  /* Christiaan alignment fix */
  ram = (u8_t*)ram_heap;
#endif
  memset(ram, 0, MEM_SIZE);
  mem = (struct mem *)ram;
  mem->next = MEM_SIZE;
  mem->prev = 0;
  mem->used = 0;
  ram_end = (struct mem *)&ram[MEM_SIZE];
  ram_end->used = 1;
  ram_end->next = MEM_SIZE;
  ram_end->prev = MEM_SIZE;

  mem_sem = sys_sem_new(1);

  lfree = (struct mem *)ram;

#if MEM_STATS
  lwip_stats.mem.avail = MEM_SIZE;
#endif /* MEM_STATS */
}
Exemple #11
0
/*
 * mcf5272fecif_init(struct netif *netif):
 *
 * Should be called at the beginning of the program to set up the
 * network interface. It calls the function low_level_init() to do the
 * actual setup of the hardware.
 *
 * Note that there is only one fec in a 5272!
 *
 */
err_t
mcf5272fecif_init(struct netif *netif)
{
    sys_sem_t sem;
    
    /* Allocate our interface control block */
    /* IMPORTANT NOTE: This works for 5272, but if you are using a cpu with data cache
     * then you need to make sure you get this memory from non-cachable memory. */
    mcf5272if = (mcf5272if_t *) calloc(1, sizeof(mcf5272if_t));
    if (mcf5272if)
    {
        netif->state = mcf5272if;
        mcf5272if->netif = netif;
        netif->name[0] = IFNAME0;
        netif->name[1] = IFNAME1;
        netif->output = mcf5272fecif_output;
        netif->linkoutput = low_level_output;
        netif->mtu = MTU_FEC - 18;      // mtu without ethernet header and crc
        mcf5272if->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
        netif->hwaddr_len = 6; /* Ethernet interface */
        mcf5272if->imm = mcf5272_get_immp();
        
        low_level_init(netif);

        etharp_init();
        sem = sys_sem_new(0);
        etharp_timer_init(&sem);
        sys_sem_wait(sem);
        sys_sem_free(sem);
        
        return ERR_OK;
    }
    else
        return ERR_MEM;
}
Exemple #12
0
sys_mbox_t sys_mbox_new(int size)
{
	if (size > _MBOX_SIZE)
		return NULL;
#ifdef LWIP_ARCH_DEBUG
	cprintf("[%d] mbox_new size: %d\n", current->pid, size);
#endif
	struct mbox *m = kmalloc(sizeof(struct mbox));
	if (size == 0) size = _MBOX_SIZE;
	m->free = sys_sem_new(size);
	m->used = sys_sem_new(0);
	m->lock = sys_sem_new(1); // since we do not have spinlock, ...
	m->head = 0;
	m->next = 0;
	return m;
}
Exemple #13
0
static inline int InitializeLWIP(void){
	sys_sem_t	Sema;
	int		iRet;

	dbgprintf("PS2IP: Module Loaded.\n");

	if ((iRet=RegisterLibraryEntries(&_exp_ps2ip))!=0)
	{
		printf("PS2IP: RegisterLibraryEntries returned: %d\n", iRet);
	}

	RxPBufsFree=LWIP_STACK_MAX_RX_PBUFS;
	NetManRxPacketBufferPoolFreeStart=0;
	recv_pbuf_queue_start=recv_pbuf_queue_end=NULL;

	sys_sem_new(&Sema, 0);
	dbgprintf("PS2IP: Calling tcpip_init\n");
	tcpip_init(InitDone,&Sema);

	sys_arch_sem_wait(&Sema, 0);
	sys_sem_free(&Sema);

	dbgprintf("PS2IP: tcpip_init called\n");
#if NOSYS
	InitTimer();
#endif

	dbgprintf("PS2IP: System Initialised\n");

	return 0;
}
Exemple #14
0
/**
 * \brief CGI request search engine.
 *
 * \param name CGI request name.
 * \param table CGI handler table.
 * \return A valid function handler for the specified CGI request, NULL otherwise.
 */
http_handler_t cgi_search(const char *name, HttpCGI *table)
{
	/* Allocate the CGI semaphore. */
	/* This is necessary to avoid race conditions on tx_buf.*/
	if (!sys_sem_valid(&cgi_sem)) {
		sys_sem_new(&cgi_sem, 1);
	}

	if (!table) {
		return NULL;
	}

	int i = 0;
	const char *ext = get_ext(name);

	while (table[i].name) {
		if (ext && table[i].type == CGI_MATCH_EXT) {
			if (!strcmp(table[i].name, ext)) {
				break;
			}
		} else if (table[i].type == CGI_MATCH_NAME) {
			if (strstr(name, table[i].name) != NULL) {
				break;
			}
		} else { /* (table[i].type == CGI_MATCH_WORD) */
			if (!strcmp(table[i].name, name)) {
				break;
			}
		}

		i++;
	}

	return table[i].handler;
}
Exemple #15
0
/*-----------------------------------------------------------------------------------*/
void
mem_init(void)
{
  struct mem *mem;

  bzero(ram, MEM_SIZE);
  mem = (struct mem *)ram;
  mem->next = MEM_SIZE;
  mem->prev = 0;
  mem->used = 0;
  ram_end = (struct mem *)&ram[MEM_SIZE];
  ram_end->used = 1;
  ram_end->next = MEM_SIZE;
  ram_end->prev = MEM_SIZE;

  fflush(stdout);
  mem_sem = sys_sem_new(1);
  assert(mem_sem);

  lfree = (struct mem *)ram;

#if MEM_RECLAIM
  mrlist = NULL;
#endif /* MEM_RECLAIM */
  
#ifdef MEM_STATS
  stats.mem.avail = (uint16_t)MEM_SIZE;
#endif /* MEM_STATS */
}
Exemple #16
0
/**
 * Initializes the pbuf module.
 *
 * A large part of memory is allocated for holding the pool of pbufs.
 * The size of the individual pbufs in the pool is given by the size
 * parameter, and the number of pbufs in the pool by the num parameter.
 *
 * After the memory has been allocated, the pbufs are set up. The
 * ->next pointer in each pbuf is set up to point to the next pbuf in
 * the pool.
 *
 */
void
pbuf_init(void)
{
  struct pbuf *p, *q = NULL;
  u16_t i;

  pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
  LWIP_ASSERT("pbuf_init: pool aligned", (mem_ptr_t)pbuf_pool % MEM_ALIGNMENT == 0);

#if PBUF_STATS
  lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
#endif /* PBUF_STATS */

  /* Set up ->next pointers to link the pbufs of the pool together */
  p = pbuf_pool;

  for(i = 0; i < PBUF_POOL_SIZE; ++i) {
    p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
    p->len = p->tot_len = PBUF_POOL_BUFSIZE;
    p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf)));
    p->flags = PBUF_FLAG_POOL;
    q = p;
    p = p->next;
  }

  /* The ->next pointer of last pbuf is NULL to indicate that there
     are no more pbufs in the pool */
  q->next = NULL;

#if !SYS_LIGHTWEIGHT_PROT
  pbuf_pool_alloc_lock = 0;
  pbuf_pool_free_lock = 0;
  pbuf_pool_free_sem = sys_sem_new(1);
#endif
}
Exemple #17
0
/**
 * Zero the heap and initialize start, end and lowest-free
 */
	void
mem_init(void)
{
	struct mem *mem;

	LWIP_ASSERT("Sanity check alignment",
			(SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT-1)) == 0);

	/* align the heap */
	ram = LWIP_MEM_ALIGN(ram_heap);
	/* initialize the start of the heap */
	mem = (struct mem *)ram;
	mem->next = MEM_SIZE_ALIGNED;
	mem->prev = 0;
	mem->used = 0;
	/* initialize the end of the heap */
	ram_end = (struct mem *)&ram[MEM_SIZE_ALIGNED];
	ram_end->used = 1;
	ram_end->next = MEM_SIZE_ALIGNED;
	ram_end->prev = MEM_SIZE_ALIGNED;

	mem_sem = sys_sem_new(1);

	/* initialize the lowest-free pointer to the start of the heap */
	lfree = (struct mem *)ram;

#if MEM_STATS
	lwip_stats.mem.avail = MEM_SIZE_ALIGNED;
#endif /* MEM_STATS */
}
Exemple #18
0
void ip_stack_init(void)
{
    /* Netif configuration */
    static ip_addr_t ipaddr, netmask, gw;

    IP4_ADDR(&gw, 10, 0, 0, 11); // toradex board IP
    IP4_ADDR(&ipaddr, 10, 0, 0, 10);
    IP4_ADDR(&netmask, 255,255,255,255);

    /* Creates the "Init done" semaphore. */
    sys_sem_new(&lwip_init_done, 0);

    /* We start the init of the IP stack. */
    tcpip_init(ipinit_done_cb, NULL);

    /* We wait for the IP stack to be fully initialized. */
    printf("Waiting for LWIP init...\n");
    sys_sem_wait(&lwip_init_done);

    /* Deletes the init done semaphore. */
    sys_sem_free(&lwip_init_done);
    printf("LWIP init complete\n");

    /* Adds a tap pseudo interface for unix debugging. */
    netif_add(&slipf, &ipaddr, &netmask, &gw, NULL, slipif_init, tcpip_input);

    netif_set_default(&slipf);
    netif_set_up(&slipf);

}
Exemple #19
0
/**
 * Much like tcpip_apimsg, but calls the lower part of a netifapi_*
 * function.
 *
 * @param netifapimsg a struct containing the function to call and its parameters
 * @return error code given back by the function that was called
 */
err_t
tcpip_netifapi(struct netifapi_msg* netifapimsg)
{
  TCPIP_MSG_VAR_DECLARE(msg);

  if (sys_mbox_valid(&mbox)) {
    err_t err;
    TCPIP_MSG_VAR_ALLOC(msg);

    err = sys_sem_new(&netifapimsg->msg.sem, 0);
    if (err != ERR_OK) {
      netifapimsg->msg.err = err;
      return err;
    }
    
    TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_NETIFAPI;
    TCPIP_MSG_VAR_REF(msg).msg.netifapimsg = netifapimsg;
    sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg));
    sys_sem_wait(&netifapimsg->msg.sem);
    sys_sem_free(&netifapimsg->msg.sem);
    TCPIP_MSG_VAR_FREE(msg);
    return netifapimsg->msg.err;
  }
  return ERR_VAL;
}
Exemple #20
0
/** Initializes thread synchronization instance */
void snmp_threadsync_init(struct snmp_threadsync_instance *instance, snmp_threadsync_synchronizer_fn sync_fn)
{
  err_t err = sys_mutex_new(&instance->sem_usage_mutex);
  LWIP_ASSERT("Failed to set up mutex", err == ERR_OK);
  err = sys_sem_new(&instance->sem, 0);
  LWIP_ASSERT("Failed to set up semaphore", err == ERR_OK);
  instance->sync_fn = sync_fn;
}
Exemple #21
0
/**
 *  \brief start lwIP layer.
 */
static void prvlwIPInit( void )
{
  sys_sem_t sem;

#if ( (LWIP_VERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
	sem = sys_sem_new(0);   /* Create a new semaphore. */
	tcpip_init(tcpip_init_done, &sem);
	sys_sem_wait(sem);      /* Block until the lwIP stack is initialized. */
	sys_sem_free(sem);      /* Free the semaphore. */
#else
	err_t err_sem;
	err_sem = sys_sem_new(&sem, 0); /* Create a new semaphore. */
	tcpip_init(tcpip_init_done, &sem);
	sys_sem_wait(&sem);     /* Block until the lwIP stack is initialized. */
	sys_sem_free(&sem);     /* Free the semaphore. */
#endif
}
Exemple #22
0
/*************************************************************************************************
 * ethernet_init_LwIP
 *
 * starts the LwIP layer
 */
static void ethernet_init_LwIP(void)
{
	sys_sem_t sem;

	#if ( (LWIP_VERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
	  sem = sys_sem_new(0); // Create a new semaphore.
	  tcpip_init(ethernet_tcpip_init_done, &sem);
	  sys_sem_wait(sem);    // Block until the lwIP stack is initialized.
	  sys_sem_free(sem);    // Free the semaphore.
	#else
	  err_t  err_sem;
	  err_sem = sys_sem_new(&sem, 0); // Create a new semaphore.
	  tcpip_init(ethernet_tcpip_init_done, &sem);
	  sys_sem_wait(&sem);    // Block until the lwIP stack is initialized.
	  sys_sem_free(&sem);    // Free the semaphore.
	#endif
}
void
sys_msleep(u32_t ms)
{
  sys_sem_t delaysem = sys_sem_new(0);

  sys_sem_wait_timeout(delaysem, ms);

  sys_sem_free(delaysem);
}
static err_t
accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
{
  sys_mbox_t mbox;
  struct netconn *newconn;
  struct netconn *conn;
  
#if API_MSG_DEBUG
#if TCP_DEBUG
  tcp_debug_print_state(newpcb->state);
#endif /* TCP_DEBUG */
#endif /* API_MSG_DEBUG */
  conn = (struct netconn *)arg;
  mbox = conn->acceptmbox;
  newconn = memp_malloc(MEMP_NETCONN);
  if (newconn == NULL) {
    return ERR_MEM;
  }
  newconn->recvmbox = sys_mbox_new();
  if (newconn->recvmbox == SYS_MBOX_NULL) {
    memp_free(MEMP_NETCONN, newconn);
    return ERR_MEM;
  }
  newconn->mbox = sys_mbox_new();
  if (newconn->mbox == SYS_MBOX_NULL) {
    sys_mbox_free(newconn->recvmbox);
    memp_free(MEMP_NETCONN, newconn);
    return ERR_MEM;
  }
  newconn->sem = sys_sem_new(0);
  if (newconn->sem == SYS_SEM_NULL) {
    sys_mbox_free(newconn->recvmbox);
    sys_mbox_free(newconn->mbox);
    memp_free(MEMP_NETCONN, newconn);
    return ERR_MEM;
  }
  /* Allocations were OK, setup the PCB etc */
  newconn->type = NETCONN_TCP;
  newconn->pcb.tcp = newpcb;
  setup_tcp(newconn);
  newconn->acceptmbox = SYS_MBOX_NULL;
  newconn->err = err;
  /* Register event with callback */
  if (conn->callback)
  {
    (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
  }
  /* We have to set the callback here even though
   * the new socket is unknown. Mark the socket as -1. */
  newconn->callback = conn->callback;
  newconn->socket = -1;
  newconn->recv_avail = 0;
  
  sys_mbox_post(mbox, newconn);
  return ERR_OK;
}
Exemple #25
0
int lwip_bringup(void)
{
    // Check if we've already connected
    if (lwip_get_ip_address()) {
        return NSAPI_ERROR_PARAMETER;
    }

    // Check if we've already brought up lwip
    if (!lwip_get_mac_address()) {
        // Set up network
        lwip_set_mac_address();

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_up, 0);

        tcpip_init(lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        memset(&lwip_netif, 0, sizeof lwip_netif);
        netif_add(&lwip_netif, 0, 0, 0, NULL, eth_arch_enetif_init, tcpip_input);
        netif_set_default(&lwip_netif);

        netif_set_link_callback  (&lwip_netif, lwip_netif_link_irq);
        netif_set_status_callback(&lwip_netif, lwip_netif_status_irq);

        eth_arch_enable_interrupts();
    }

    // Zero out socket set
    lwip_arena_init();

    // Connect to the network
    dhcp_start(&lwip_netif);

    // Wait for an IP Address
    u32_t ret = sys_arch_sem_wait(&lwip_netif_up, 15000);
    if (ret == SYS_ARCH_TIMEOUT) {
        return NSAPI_ERROR_DHCP_FAILURE;
    }

    return 0;
}
Exemple #26
0
void _init(void){
  sys_sem_t sem;

  if(sys_sem_new(&sem, 0) != ERR_OK) {
    LWIP_ASSERT("failed to create semaphore", 0);
  }
  tcpip_init(tcpip_init_done, &sem);
  sys_sem_wait(&sem);
  sys_sem_free(&sem);
}
void LwipNetInterface::initInterface(void) {

	LWIP_PLATFORM_DIAG(("Interface initialization\n"));

	if (sys_sem_new(&this->syncSem, 0) != ERR_OK) {
		LWIP_ASSERT("failed to create semaphore", 0);
	}
	tcpip_init(this->ipStackInitDone, this);
	sys_sem_wait(&this->syncSem);
	sys_sem_free(&this->syncSem);
}
Exemple #28
0
/**
 * Sleep for some ms. Timeouts are NOT processed while sleeping.
 *
 * @param ms number of milliseconds to sleep
 */
void sys_msleep(u32_t ms)
{
	if (ms > 0) {
		sys_sem_t delaysem;
		err_t err = sys_sem_new(&delaysem, 0);
		if (err == ERR_OK) {
			sys_arch_sem_wait(&delaysem, ms);
			sys_sem_free(&delaysem);
		}
	}
}
Exemple #29
0
int
lwip_dnssd_gethostbyname(const char *name, ip_addr_t *addr, u8_t addrtype, err_t *err)
{
  DNSServiceErrorType result;
  DNSServiceRef ref;
  struct addr_clbk_msg msg;
  char *p;

  /* @todo: use with IPv6 */
  LWIP_UNUSED_ARG(addrtype);

#if CONSUME_LOCAL_ONLY
  /* check if this is a .local host. If it is, then we consume the query */
  p = strstr(name, LOCAL_DOMAIN);
  if (p == NULL) {
    return 0; /* not consumed */
  }
  p += (sizeof(LOCAL_DOMAIN) - 1);
  /* check to make sure .local isn't a substring (only allow .local\0 or .local.\0) */
  if ((*p != '.' && *p != '\0') ||
      (*p == '.' && *(p + 1) != '\0')) {
    return 0; /* not consumed */
  }
#endif /* CONSUME_LOCAL_ONLY */

  msg.err = sys_sem_new(&msg.sem, 0);
  if (msg.err != ERR_OK) {
    goto query_done;
  }

  msg.err = ERR_TIMEOUT;
  result = DNSServiceGetAddrInfo(&ref, 0, 0, kDNSServiceProtocol_IPv4, name, addr_info_callback, &msg);
  if (result == kDNSServiceErr_NoError) {
    sys_arch_sem_wait(&msg.sem, GETADDR_TIMEOUT_MS);
    DNSServiceRefDeallocate(ref);

    /* We got a response */
    if (msg.err == ERR_OK) {
      struct sockaddr_in* addr_in = (struct sockaddr_in *)&msg.addr;
      if (addr_in->sin_family == AF_INET) {
        inet_addr_to_ip4addr(ip_2_ip4(addr), &addr_in->sin_addr);
      } else {
        /* @todo add IPv6 support */
        msg.err = ERR_VAL;
      }
    }
  }
  sys_sem_free(&msg.sem);

/* Query has been consumed and is finished */
query_done:
*err = msg.err;
return 1;
}
Exemple #30
0
static void mbed_lwip_core_init(void)
{

    // Check if we've already brought up lwip
    if (!lwip_inited) {
	// Seed lwip random
        lwip_seed_random();

        // Initialise TCP sequence number
        uint32_t tcp_isn_secret[4];
        for (int i = 0; i < 4; i++) {
            tcp_isn_secret[i] = LWIP_RAND();
        }
        lwip_init_tcp_isn(0, (u8_t *) &tcp_isn_secret);

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_unlinked, 0);
        sys_sem_new(&lwip_netif_has_any_addr, 0);
#if PREF_ADDR_TIMEOUT
        sys_sem_new(&lwip_netif_has_pref_addr, 0);
#endif
#if BOTH_ADDR_TIMEOUT
        sys_sem_new(&lwip_netif_has_both_addr, 0);
#endif
        tcpip_init(mbed_lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        lwip_inited = true;
    }
}