-
Notifications
You must be signed in to change notification settings - Fork 1
/
WLANConfigurator.ts
105 lines (95 loc) · 3.21 KB
/
WLANConfigurator.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { WLANDevConfiguration } from '../../driver/efm/WLANDevConfiguration';
import { WLANConfigurator } from '../../driver/generic/wlan';
import { WLANIFaceCfg } from '../../driver/generic/WLANIFaceCfg';
import { RPCProvider } from '../jsonrpcv2';
export class RPCWLANConfigurator extends WLANConfigurator {
private rpc: RPCProvider;
private targetId: string;
constructor(rpc: RPCProvider, targetId: string) {
super();
this.rpc = rpc;
this.targetId = targetId;
}
/**
* Get WLAN device list
*
* @returns WLAN device name list
*/
public async getDeviceList(): Promise<string[]> {
return (await this.rpc.remoteCall({
jsonrpc: '2.0',
target: this.targetId,
class: 'WLANConfigurator',
method: 'getDeviceList',
params: [],
})) as string[];
}
/**
* Get WLAN device configuration
*
* @param devname - WLAN device name
* @returns WLAN device configuration
*/
public async getDeviceCfg(devname: string): Promise<WLANDevConfiguration> {
const res = (await this.rpc.remoteCall({
jsonrpc: '2.0',
target: this.targetId,
class: 'WLANConfigurator',
method: 'getDeviceCfg',
params: [devname],
}));
const wldev = new WLANDevConfiguration();
wldev.restore(res as any);
return wldev;
}
/**
* Apply WLAN device configuration to specific WLAN device
*
* @param devname - WLAN device name
* @param cfg - WLAN device configuration
*/
public async setDeviceCfg(devname: string, cfg: WLANDevConfiguration): Promise<void> {
await this.rpc.remoteCall({
jsonrpc: '2.0',
target: this.targetId,
class: 'WLANConfigurator',
method: 'setDeviceCfg',
params: [devname, cfg.serialize()],
});
}
/**
* Get specific interface configuration using wlan devname and ifname
*
* @param devname - WLAN device which holds given interface
* @param ifname - WLAN interface which belongs to given WLAN device
* @returns WLAN interface configuration
*/
public async getIFaceCfg(devname: string, ifname: string): Promise<WLANIFaceCfg> {
const res = (await this.rpc.remoteCall({
jsonrpc: '2.0',
target: this.targetId,
class: 'WLANConfigurator',
method: 'getDeviceCfg',
params: [devname],
}));
const wlifcfg = new WLANIFaceCfg();
wlifcfg.restore(res as any);
return wlifcfg;
}
/**
* Apply given config to given WLAN interface.
*
* @param devname - WLAN device which holds given interface
* @param ifname - WLAN interface which belongs to given WLAN device
* @param cfg - WLAN interface configuration
*/
public async setIFaceCfg(devname: string, ifname: string, cfg: WLANIFaceCfg): Promise<void> {
await this.rpc.remoteCall({
jsonrpc: '2.0',
target: this.targetId,
class: 'WLANConfigurator',
method: 'setDeviceCfg',
params: [devname, ifname, cfg.serialize()],
});
}
}