Skip to content

Commit 8dc9280

Browse files
committed
Merge branch 'feature/set_mac_address' into 'master'
esp_hosted_ng: Add support for ndo_set_mac_address See merge request app-frameworks/esp_hosted!291
2 parents d5b4888 + 1449038 commit 8dc9280

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

esp_hosted_ng/host/esp_cfg80211.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,11 @@ static void esp_cfg80211_set_wakeup(struct wiphy *wiphy,
491491
/*esp_dbg("\n");*/
492492
}
493493

494-
//TODO get MAX_TAX_POWER from Firmware for future chips
495-
#define MAX_TAX_POWER (20 * 100)
494+
/* TODO get MAX_TX_POWER_MBM from Firmware for future chips */
495+
#define MAX_TX_POWER_MBM (20 * 100)
496496
static bool is_txpwr_valid(int mbm)
497497
{
498-
if (mbm > MAX_TAX_POWER)
498+
if (mbm > MAX_TX_POWER_MBM)
499499
return false;
500500

501501
return true;
@@ -534,7 +534,7 @@ static int esp_cfg80211_set_tx_power(struct wiphy *wiphy,
534534
switch (type) {
535535
case NL80211_TX_POWER_AUTOMATIC:
536536
priv->tx_pwr_type = NL80211_TX_POWER_AUTOMATIC;
537-
priv->tx_pwr = mbm_to_esp_pwr(MAX_TAX_POWER);
537+
priv->tx_pwr = mbm_to_esp_pwr(MAX_TX_POWER_MBM);
538538
break;
539539
case NL80211_TX_POWER_LIMITED:
540540
if (!is_txpwr_valid(mbm)) {

esp_hosted_ng/host/esp_cmd.c

+32
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static int wait_and_decode_cmd_resp(struct esp_wifi_device *priv,
239239
break;
240240

241241
case CMD_GET_MAC:
242+
case CMD_SET_MAC:
242243
if (ret == 0)
243244
ret = decode_mac_addr(priv, cmd_node);
244245
break;
@@ -1382,6 +1383,37 @@ int cmd_get_mac(struct esp_wifi_device *priv)
13821383
return 0;
13831384
}
13841385

1386+
int cmd_set_mac(struct esp_wifi_device *priv, uint8_t *mac_addr)
1387+
{
1388+
u16 cmd_len;
1389+
struct command_node *cmd_node = NULL;
1390+
struct cmd_config_mac_address *cmd;;
1391+
1392+
if (!priv || !priv->adapter) {
1393+
esp_err("Invalid argument\n");
1394+
return -EINVAL;
1395+
}
1396+
1397+
cmd_len = sizeof(struct cmd_config_mac_address);
1398+
1399+
cmd_node = prepare_command_request(priv->adapter, CMD_SET_MAC, cmd_len);
1400+
1401+
if (!cmd_node) {
1402+
esp_err("Failed to get command node\n");
1403+
return -ENOMEM;
1404+
}
1405+
1406+
cmd = (struct cmd_config_mac_address *) (cmd_node->cmd_skb->data +
1407+
sizeof(struct esp_payload_header));
1408+
1409+
memcpy(cmd->mac_addr, mac_addr, MAC_ADDR_LEN);
1410+
queue_cmd_node(priv->adapter, cmd_node, ESP_CMD_DFLT_PRIO);
1411+
queue_work(priv->adapter->cmd_wq, &priv->adapter->cmd_work);
1412+
1413+
RET_ON_FAIL(wait_and_decode_cmd_resp(priv, cmd_node));
1414+
1415+
return 0;
1416+
}
13851417

13861418
int esp_commands_teardown(struct esp_adapter *adapter)
13871419
{

esp_hosted_ng/host/include/esp_cmd.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int process_cmd_resp(struct esp_adapter *adapter, struct sk_buff *skb);
3131
int cmd_scan_request(struct esp_wifi_device *priv,
3232
struct cfg80211_scan_request *request);
3333
int cmd_get_mac(struct esp_wifi_device *priv);
34+
int cmd_set_mac(struct esp_wifi_device *priv, uint8_t *mac_addr);
3435
int process_cmd_event(struct esp_wifi_device *priv, struct sk_buff *skb);
3536
int cmd_connect_request(struct esp_wifi_device *priv,
3637
struct cfg80211_connect_params *params);

esp_hosted_ng/host/include/esp_kernel_port.h

-8
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ static inline void *skb_put_data(struct sk_buff *skb, const void *data,
160160
}
161161
#endif
162162

163-
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0))
164-
#define NDO_TX_TIMEOUT_PROTOTYPE() \
165-
void esp_tx_timeout(struct net_device *ndev)
166-
#else
167-
#define NDO_TX_TIMEOUT_PROTOTYPE() \
168-
void esp_tx_timeout(struct net_device *ndev, unsigned int txqueue)
169-
#endif
170-
171163
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0))
172164
#define do_exit(code) kthread_complete_and_exit(NULL, code)
173165
#endif

esp_hosted_ng/host/main.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,23 @@ static struct net_device_stats *esp_get_stats(struct net_device *ndev)
287287
return &priv->stats;
288288
}
289289

290-
#if 0
291290
static int esp_set_mac_address(struct net_device *ndev, void *data)
292291
{
293292
struct esp_wifi_device *priv = netdev_priv(ndev);
294-
//struct sockaddr *mac_addr = data;
293+
struct sockaddr *sa = (struct sockaddr *)data;
294+
int ret;
295295

296296
if (!priv || !priv->adapter)
297297
return -EINVAL;
298298

299-
esp_info("%u "MACSTR"\n", __LINE__, MAC2STR(priv->mac_address));
300-
eth_hw_addr_set(ndev, priv->mac_address/*mac_addr->sa_data*/);
299+
esp_info("%u "MACSTR"\n", __LINE__, MAC2STR(sa->sa_data));
301300

302-
return 0;
303-
}
304-
#endif
301+
ret = cmd_set_mac(priv, sa->sa_data);
305302

306-
static NDO_TX_TIMEOUT_PROTOTYPE()
307-
{
303+
if (ret == 0)
304+
eth_hw_addr_set(ndev, priv->mac_address/*mac_addr->sa_data*/);
305+
306+
return ret;
308307
}
309308

310309
static void esp_set_rx_mode(struct net_device *ndev)
@@ -379,8 +378,8 @@ static const struct net_device_ops esp_netdev_ops = {
379378
.ndo_open = esp_open,
380379
.ndo_stop = esp_stop,
381380
.ndo_start_xmit = esp_hard_start_xmit,
381+
.ndo_set_mac_address = esp_set_mac_address,
382382
.ndo_validate_addr = eth_validate_addr,
383-
.ndo_tx_timeout = esp_tx_timeout,
384383
.ndo_get_stats = esp_get_stats,
385384
.ndo_set_rx_mode = esp_set_rx_mode,
386385
};

0 commit comments

Comments
 (0)