static void net_iface_init(struct net_if *iface) { u8_t *mac = net_iface_get_mac(net_if_get_device(iface)); net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr), NET_LINK_ETHERNET); }
static void slip_iface_init(struct net_if *iface) { struct slip_context *slip = net_if_get_device(iface)->driver_data; struct net_linkaddr *ll_addr = slip_get_mac(slip); slip->init_done = true; slip->iface = iface; if (CONFIG_SLIP_MAC_ADDR[0] != 0) { if (_slip_mac_addr_from_str(slip, CONFIG_SLIP_MAC_ADDR) < 0) { goto use_random_mac; } } else { use_random_mac: /* 00-00-5E-00-53-xx Documentation RFC 7042 */ slip->mac_addr[0] = 0x00; slip->mac_addr[1] = 0x00; slip->mac_addr[2] = 0x5E; slip->mac_addr[3] = 0x00; slip->mac_addr[4] = 0x53; slip->mac_addr[5] = sys_rand32_get(); } net_if_set_link_addr(iface, ll_addr->addr, ll_addr->len, NET_LINK_ETHERNET); }
static void ipsp_connected(struct bt_l2cap_chan *chan) { struct bt_context *ctxt = CHAN_CTXT(chan); struct bt_conn_info info; #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) char src[BT_ADDR_LE_STR_LEN]; char dst[BT_ADDR_LE_STR_LEN]; #endif bt_conn_get_info(chan->conn, &info); #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) bt_addr_le_to_str(info.le.src, src, sizeof(src)); bt_addr_le_to_str(info.le.dst, dst, sizeof(dst)); NET_DBG("Channel %p Source %s connected to Destination %s", chan, src, dst); #endif /* Swap bytes since net APIs expect big endian address */ sys_memcpy_swap(ctxt->src.val, info.le.src->a.val, sizeof(ctxt->src)); sys_memcpy_swap(ctxt->dst.val, info.le.dst->a.val, sizeof(ctxt->dst)); net_if_set_link_addr(ctxt->iface, ctxt->src.val, sizeof(ctxt->src.val)); /* Set iface up */ net_if_up(ctxt->iface); }
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); } }
static void upipe_iface_init(struct net_if *iface) { struct device *dev = net_if_get_device(iface); struct upipe_context *upipe = dev->driver_data; u8_t *mac = get_mac(dev); net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154); upipe_dev = dev; upipe->iface = iface; ieee802154_init(iface); }
static void nrf5_iface_init(struct net_if *iface) { struct device *dev = net_if_get_device(iface); struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev); SYS_LOG_DBG(""); nrf5_get_eui64(nrf5_radio->mac); net_if_set_link_addr(iface, nrf5_radio->mac, sizeof(nrf5_radio->mac), NET_LINK_IEEE802154); nrf5_radio->iface = iface; ieee802154_init(iface); }
static void ipsp_connected(struct bt_l2cap_chan *chan) { struct bt_context *ctxt = CHAN_CTXT(chan); struct bt_conn_info info; struct net_linkaddr ll; struct in6_addr in6; #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) char src[BT_ADDR_LE_STR_LEN]; char dst[BT_ADDR_LE_STR_LEN]; #endif bt_conn_get_info(chan->conn, &info); #if defined(CONFIG_NET_DEBUG_L2_BLUETOOTH) bt_addr_le_to_str(info.le.src, src, sizeof(src)); bt_addr_le_to_str(info.le.dst, dst, sizeof(dst)); NET_DBG("Channel %p Source %s connected to Destination %s", chan, src, dst); #endif /* Swap bytes since net APIs expect big endian address */ sys_memcpy_swap(ctxt->src.val, info.le.src->a.val, sizeof(ctxt->src)); sys_memcpy_swap(ctxt->dst.val, info.le.dst->a.val, sizeof(ctxt->dst)); net_if_set_link_addr(ctxt->iface, ctxt->src.val, sizeof(ctxt->src.val), NET_LINK_BLUETOOTH); ll.addr = ctxt->dst.val; ll.len = sizeof(ctxt->dst.val); /* Add remote link-local address to the nbr cache to avoid sending ns: * https://tools.ietf.org/html/rfc7668#section-3.2.3 * A Bluetooth LE 6LN MUST NOT register its link-local address. */ net_ipv6_addr_create_iid(&in6, &ll); net_ipv6_nbr_add(ctxt->iface, &in6, &ll, false, NET_IPV6_NBR_STATE_REACHABLE); /* Set iface up */ net_if_up(ctxt->iface); }
static void eth0_iface_init(struct net_if *iface) { struct device *const dev = net_if_get_device(iface); struct eth_sam_dev_data *const dev_data = DEV_DATA(dev); const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev); u32_t gmac_ncfgr_val; u32_t link_status; int result; dev_data->iface = iface; /* Initialize GMAC driver, maximum frame length is 1518 bytes */ gmac_ncfgr_val = GMAC_NCFGR_MTIHEN /* Multicast Hash Enable */ | GMAC_NCFGR_LFERD /* Length Field Error Frame Discard */ | GMAC_NCFGR_RFCS /* Remove Frame Check Sequence */ | GMAC_NCFGR_RXCOEN; /* Receive Checksum Offload Enable */ result = gmac_init(cfg->regs, gmac_ncfgr_val); if (result < 0) { SYS_LOG_ERR("Unable to initialize ETH driver"); return; } #ifdef CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM /* Read MAC address from an external EEPROM */ get_mac_addr_from_i2c_eeprom(dev_data->mac_addr); #endif SYS_LOG_INF("MAC: %x:%x:%x:%x:%x:%x", dev_data->mac_addr[0], dev_data->mac_addr[1], dev_data->mac_addr[2], dev_data->mac_addr[3], dev_data->mac_addr[4], dev_data->mac_addr[5]); /* Set MAC Address for frame filtering logic */ mac_addr_set(cfg->regs, 0, dev_data->mac_addr); /* Register Ethernet MAC Address with the upper layer */ net_if_set_link_addr(iface, dev_data->mac_addr, sizeof(dev_data->mac_addr), NET_LINK_ETHERNET); /* Initialize GMAC queues */ /* Note: Queues 1 and 2 are not used, configured to stay idle */ priority_queue_init_as_idle(cfg->regs, &dev_data->queue_list[2]); priority_queue_init_as_idle(cfg->regs, &dev_data->queue_list[1]); result = queue_init(cfg->regs, &dev_data->queue_list[0]); if (result < 0) { SYS_LOG_ERR("Unable to initialize ETH queue"); return; } /* PHY initialize */ result = phy_sam_gmac_init(&cfg->phy); if (result < 0) { SYS_LOG_ERR("ETH PHY Initialization Error"); return; } /* PHY auto-negotiate link parameters */ result = phy_sam_gmac_auto_negotiate(&cfg->phy, &link_status); if (result < 0) { SYS_LOG_ERR("ETH PHY auto-negotiate sequence failed"); return; } /* Set up link parameters */ link_configure(cfg->regs, link_status); }
static void loopback_init(struct net_if *iface) { /* RFC 7042, s.2.1.1. address to use in documentation */ net_if_set_link_addr(iface, "\x00\x00\x5e\x00\x53\xff", 6, NET_LINK_DUMMY); }