forked from alexmoon/wifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
249 lines (249 loc) · 7.26 KB
/
index.d.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/// <reference types="node" />
import { EventEmitter } from 'events';
/**
* WpaCtrl to control wpa_supplicant
*
* @see {@link http://w1.fi/wpa_supplicant/devel/ctrl_iface_page.html} for full documentation of the commands that can be sent
* and events that can be emitted.
*/
declare class WpaCtrl extends EventEmitter {
private ifName;
private socketPath;
private pendingCmd;
private pendingScan;
private client?;
private clientPath?;
/**
* constructs WpaCtrl
* @param ifName interface name eg. wlan0
* @param [ctrlPath='/run/wpa_supplicant'] - The location of the wpa_supplicant control interface.
*/
constructor(ifName: string, ctrlPath?: string);
/**
* connect to wpa control interface
*/
connect(): Promise<void>;
/**
* close the wpa control interface
*/
close(): void;
/**
* message event handler
* @param msg message recieved from wpa_ctrl
*/
private _onMessage(buf);
/**
* add parsed parameters to the event data object
* @param event
* @param params
*/
private _addParsedEventData(params);
/**
* send request to wpa_supplicant control interface
* @param msg wpa_supplicant commands
*/
sendCmd(msg: string): Promise<any>;
/**
* parse response from wpa_supplicant control interface
* @param msg wpa_supplicant response
*/
private _parseResponse(msg, resolve, reject);
/**
* scan for wifi AP
*/
scan(): Promise<WpaCtrl.IScanResult[]>;
/**
* request for wifi scan results
*/
scanResults(): Promise<WpaCtrl.IScanResult[]>;
/**
* scan results handler
* @param msg scan results message
*/
private _parseScanResult(msg);
/**
* list network handler, list all configured networks or devices
* @param msg network or devices list
*/
private _parseListNetwork(msg);
/**
* add new network
*/
addNetwork(): Promise<number>;
/**
* request to list networks
*/
listNetworks(): Promise<WpaCtrl.INetworkResult[]>;
/**
* request for status
*/
status(): Promise<WpaCtrl.IStatus>;
/**
* status handler, parses status messages and emits status event
* @param msg status message
*/
private _parseStatus(msg);
/**
* set network variable
*
* @param networkId network id recieved from list networks
* @param variable variable to set
* @param value value for the variable
*/
setNetworkVariable(networkId: number, variable: string, value: string): Promise<void>;
/**
* set network ssid
* @param networkId network id recieved from list networks
* @param ssid ssid of the network
*/
setNetworkSSID(networkId: number, ssid: string): Promise<void>;
/**
* set network pre-shared key
* @param networkId networkId network id recieved from list networks
* @param preSharedKey pre-shared key
* @param ssid ssid of the network
*/
setNetworkPreSharedKey(networkId: number, preSharedKey: string, ssid: string): Promise<void>;
/**
* set network identity
* @param networkId network id recieved from list networks
* @param identity identity string for EAP
*/
setNetworkIdentity(networkId: number, identity: string): Promise<void>;
/**
* set network password
* @param networkId network id recieved from list networks
* @param password password string for EAP
*/
setNetworkPassword(networkId: number, password: string): Promise<void>;
/**
* enable configured network
* @param networkId networkId network id recieved from list networks
*/
enableNetwork(networkId: number): Promise<void>;
/**
* select network to connect
* @param networkId networkId network id recieved from list networks
*/
selectNetwork(networkId: number): Promise<void>;
/**
* save the current configuration
*/
saveConfig(): Promise<void>;
/**
* reload the configuration from disk
*/
reconfigure(): Promise<void>;
/**
* Force reassociation
*/
reassociate(): Promise<void>;
/**
* disconnect from AP
*/
disconnectAP(): Promise<void>;
/**
* search for peers
*/
peerFind(): Promise<void>;
/**
* stop peer search
*/
peerStopFind(): Promise<void>;
/**
* fetch Peer Information
* @param peerAddress peer device address
*/
peerInfo(peerAddress: string): Promise<WpaCtrl.IPeerInfo>;
/**
* connect to peer with PBC(Push Button Control) authentication mechanism
* @param peerAddress Mac Address of peer
* @param isOwner Your role, are you group owner? if yes then true else false
*/
peerConnectPBC(peerAddress: string, isOwner: boolean): Promise<void>;
/**
* connect to peer with PIN(password) authentication mechanism
* @param peerAddress Mac Address of peer
* @param pin password for authentication
* @param isOwner Your role, are you group owner? if yes then true else false
*/
peerConnectPIN(peerAddress: string, pin: string, isOwner: boolean): Promise<void>;
/**
* peer info event handler
* @param msg event message
*/
private _parsePeerInfo(msg);
/**
* list network interfaces on system
*/
listInterfaces(): Promise<WpaCtrl.IInterfaces>;
/**
* Remove virtual interface eg: p2p-p2p0-1
* @param iFaceName interface name
* @param callback callback function
*/
removeVitualInterface(iFaceName: string): Promise<void>;
/**
* Flush peer data
*/
flushPeers(): Promise<void>;
}
declare namespace WpaCtrl {
interface IInterfaceInfo {
hwAddr?: string;
ipaddress?: string;
broadcastAddress?: string;
}
interface IInterfaces {
[iface: string]: IInterfaceInfo | undefined;
}
interface ICryptoFlag {
proto: string;
keyMgmt?: string[];
cipher?: string[];
preauth: boolean;
}
interface IScanResult {
bssid: string;
freq: number;
rssi: number;
flags: Array<string | ICryptoFlag>;
ssid: string;
}
interface INetworkResult {
networkId: number;
ssid: string;
bssid: string;
flags: string[];
}
interface IStatus {
[key: string]: string | undefined;
}
type IPeerInfo = IStatus;
interface IBaseEventParams {
event: string;
level: number;
raw?: string;
}
interface ICtrlReqEventParams extends IBaseEventParams {
event: 'CTRL-REQ';
field: string;
networkId: number;
prompt: string;
}
interface IP2PDeviceEventParams extends IBaseEventParams {
event: 'P2P-DEVICE-FOUND' | 'P2P-DEVICE-LOST';
deviceAddress?: string;
deviceName?: string;
}
interface IP2PInterfaceEventParams extends IBaseEventParams {
event: 'P2P-GROUP-STARTED';
peerInterface?: string;
}
interface IP2PAddressEventParams extends IBaseEventParams {
event: 'P2P-INVITATION-RECEIVED';
peerAddress?: string;
}
type IEventParams = IBaseEventParams | ICtrlReqEventParams | IP2PDeviceEventParams | IP2PInterfaceEventParams | IP2PAddressEventParams;
}
export = WpaCtrl;