static void eth_iface_init(struct net_if *iface) { struct eth_context *ctx = net_if_get_device(iface)->driver_data; struct net_linkaddr *ll_addr = eth_get_mac(ctx); ctx->iface = iface; ethernet_init(iface); if (ctx->init_done) { return; } net_lldp_set_lldpdu(iface); ctx->init_done = true; #if defined(CONFIG_ETH_NATIVE_POSIX_RANDOM_MAC) /* 00-00-5E-00-53-xx Documentation RFC 7042 */ ctx->mac_addr[0] = 0x00; ctx->mac_addr[1] = 0x00; ctx->mac_addr[2] = 0x5E; ctx->mac_addr[3] = 0x00; ctx->mac_addr[4] = 0x53; ctx->mac_addr[5] = sys_rand32_get(); /* The TUN/TAP setup script will by default set the MAC address of host * interface to 00:00:5E:00:53:FF so do not allow that. */ if (ctx->mac_addr[5] == 0xff) { ctx->mac_addr[5] = 0x01; } #else if (CONFIG_ETH_NATIVE_POSIX_MAC_ADDR[0] != 0) { if (net_bytes_from_str(ctx->mac_addr, sizeof(ctx->mac_addr), CONFIG_ETH_NATIVE_POSIX_MAC_ADDR) < 0) { LOG_ERR("Invalid MAC address %s", CONFIG_ETH_NATIVE_POSIX_MAC_ADDR); } } #endif net_if_set_link_addr(iface, ll_addr->addr, ll_addr->len, NET_LINK_ETHERNET); ctx->if_name = ETH_NATIVE_POSIX_DRV_NAME; ctx->dev_fd = eth_iface_create(ctx->if_name, false); if (ctx->dev_fd < 0) { LOG_ERR("Cannot create %s (%d)", ctx->if_name, ctx->dev_fd); } else { /* Create a thread that will handle incoming data from host */ create_rx_handler(ctx); eth_setup_host(ctx->if_name); eth_start_script(ctx->if_name); } }
/* broadcast_send * * Fire off a broadcast packet with information about this DAC. */ void broadcast_send(void) { /* Because lwip is an enormous steaming pile of the finest software * engineering, it is not possible to just allocate *one* pbuf * during initialization - udp_send modifies the pbuf it is given * and changes, among other things, its total length. (??!) So we * allocatea fresh one each time. */ udp_new(&broadcast_pcb); udp_bind(&broadcast_pcb, IP_ADDR_ANY, BROADCAST_PORT); udp_connect(&broadcast_pcb, IP_ADDR_BROADCAST, BROADCAST_PORT); struct pbuf * p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dac_broadcast), PBUF_RAM); /* Shamefully bail out. */ if (!p) return; struct dac_broadcast *pkt = (struct dac_broadcast *) p->payload; eth_get_mac(pkt->mac_address); fill_status(&pkt->status); pkt->buffer_capacity = DAC_BUFFER_POINTS - 1; pkt->max_point_rate = DAC_MAX_POINT_RATE; pkt->hw_revision = 0; // XXX TODO pkt->sw_revision = 1; // XXX TODO - integrate into build system udp_send(&broadcast_pcb, p); pbuf_free(p); udp_remove(&broadcast_pcb); }