Skip to content

Commit be89484

Browse files
dean-at-evoskartben
authored andcommitted
drivers: ethernet: enc28j60: Add set config for runtime macaddr
Allow runtime setting of the MAC address for this driver. Signed-off-by: Dean Sellers <dsellers@evos.com.au>
1 parent ae4c6fe commit be89484

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

drivers/ethernet/eth_enc28j60.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,39 @@ static enum ethernet_hw_caps eth_enc28j60_get_capabilities(const struct device *
757757
;
758758
}
759759

760+
static int eth_enc28j60_set_config(const struct device *dev,
761+
enum ethernet_config_type type,
762+
const struct ethernet_config *config)
763+
{
764+
struct eth_enc28j60_runtime *context = dev->data;
765+
766+
/* Compile time check that the memcpy below won't overflow */
767+
BUILD_ASSERT(sizeof(context->mac_address) <= sizeof(config->mac_address.addr),
768+
"ENC28j60 Runtime MAC address buffer too small");
769+
770+
if (type == ETHERNET_CONFIG_TYPE_MAC_ADDRESS) {
771+
memcpy(context->mac_address, config->mac_address.addr,
772+
sizeof(config->mac_address.addr));
773+
eth_enc28j60_init_mac(dev);
774+
775+
if (context->iface != NULL) {
776+
net_if_set_link_addr(context->iface, context->mac_address,
777+
sizeof(context->mac_address),
778+
NET_LINK_ETHERNET);
779+
}
780+
781+
LOG_INF("Set cfg - MAC %02x:%02x:%02x:%02x:%02x:%02x",
782+
context->mac_address[0], context->mac_address[1],
783+
context->mac_address[2], context->mac_address[3],
784+
context->mac_address[4], context->mac_address[5]);
785+
786+
return 0;
787+
}
788+
789+
/* Only mac address config supported */
790+
return -ENOTSUP;
791+
}
792+
760793
static void eth_enc28j60_iface_init(struct net_if *iface)
761794
{
762795
const struct device *dev = net_if_get_device(iface);
@@ -783,7 +816,7 @@ static void eth_enc28j60_iface_init(struct net_if *iface)
783816

784817
static const struct ethernet_api api_funcs = {
785818
.iface_api.init = eth_enc28j60_iface_init,
786-
819+
.set_config = eth_enc28j60_set_config,
787820
.get_capabilities = eth_enc28j60_get_capabilities,
788821
.send = eth_enc28j60_tx,
789822
};

0 commit comments

Comments
 (0)