-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwifi.c
90 lines (81 loc) · 1.9 KB
/
wifi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright (C) Bouffalo Lab 2016-2023
* SPDX-License-Identifier: GPL-2.0-only
*/
#include "wifi.h"
#include <linux/etherdevice.h>
#include <linux/version.h>
#ifdef BL_INTF_SDIO
#include "bl_sdio_eth.h"
#elif defined(BL_INTF_USB)
#include "bl_usb_eth.h"
#elif defined(BL_INTF_XRAM)
#include "bl_xram_eth.h"
#endif
const char *bl_mode_to_str(const bl_wifi_mode_t mode)
{
const char *str[] = {
[BL_MODE_NONE] = "NONE",
[BL_MODE_STA] = "STA",
[BL_MODE_AP] = "AP",
[BL_MODE_STA_AP] = "STA_AP",
[BL_MODE_SNIFFER] = "SNIFFER",
[BL_MODE_MAX] = "UNKNOWN",
};
if (BL_MODE_NONE <= mode && mode < BL_MODE_MAX) {
return str[mode];
} else {
return str[BL_MODE_MAX];
}
}
int bl_mode_xfer(bl_wifi_mode_t *mode, const bl_wifi_mode_t new_mode, bl_wifi_mode_t *old_mode)
{
int ret = 0;
if (old_mode) {
*old_mode = *mode;
}
if (new_mode == *mode) {
goto exit;
}
if (*mode == BL_MODE_NONE) {
*mode = new_mode;
} else if (*mode == BL_MODE_STA) {
*mode = new_mode;
} else if (*mode == BL_MODE_AP) {
*mode = new_mode;
} else {
ret = -1;
}
exit:
return ret;
}
void bl_change_eth_mac(void *dev)
{
u8 *mac;
struct bl_eth_device *d = dev;
#ifndef BL_INTF_XRAM
mac = d->sta_mac;
if (d->mode == BL_MODE_AP)
mac = d->ap_mac;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
eth_hw_addr_set(d->net, mac);
#else
memcpy(d->net->dev_addr, mac, ETH_ALEN);
#endif
#else
size_t i;
for (i = 0; i < 2; ++i) {
struct net_device *nd = d->net[i];
if (i == BL_STA_IFACE_IDX) {
mac = d->sta_mac;
} else {
mac = d->ap_mac;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
eth_hw_addr_set(nd, mac);
#else
memcpy(nd->dev_addr, mac, ETH_ALEN);
#endif
}
#endif
}