Skip to content

Commit 9c4810d

Browse files
author
Eran Leshem
committed
Add WlanApi module
1 parent 0deb54b commit 9c4810d

File tree

3 files changed

+344
-0
lines changed

3 files changed

+344
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Next Release (5.19.0)
88
Features
99
--------
1010
* [#1696](https://github.com/java-native-access/jna/pull/1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@baier233](https://github.com/baier233).
11+
* [#1697](https://github.com/java-native-access/jna/pull/1697): Add WlanApi module - [@eranl](https://github.com/eranl).
1112

1213
Bug Fixes
1314
---------
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* Copyright (c) 2025 Eran Leshem, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
package com.sun.jna.platform.win32;
25+
26+
import com.sun.jna.Library;
27+
import com.sun.jna.Structure;
28+
29+
/**
30+
* Module Name:
31+
* windot11.h
32+
* Abstract:
33+
* Definitions for native 802.11 miniport driver specifications.
34+
*
35+
* @author Eran Leshem
36+
*/
37+
public interface Windot11 extends Library {
38+
int DOT11_SSID_MAX_LENGTH = 32; // 32 bytes
39+
40+
interface DOT11_BSS_TYPE {
41+
int dot11_BSS_type_infrastructure = 1;
42+
int dot11_BSS_type_independent = 2;
43+
int dot11_BSS_type_any = 3;
44+
}
45+
46+
@Structure.FieldOrder({"uSSIDLength", "ucSSID"})
47+
class DOT11_SSID extends Structure {
48+
public WinDef.ULONG uSSIDLength;
49+
public byte[] ucSSID = new byte[DOT11_SSID_MAX_LENGTH];
50+
}
51+
52+
@Structure.FieldOrder("ucDot11MacAddress")
53+
class DOT11_MAC_ADDRESS extends Structure {
54+
public WinDef.UCHAR[] ucDot11MacAddress = new WinDef.UCHAR[6];
55+
}
56+
57+
interface DOT11_PHY_TYPE {
58+
int dot11_phy_type_unknown = 0;
59+
int dot11_phy_type_any = dot11_phy_type_unknown;
60+
int dot11_phy_type_fhss = 1;
61+
int dot11_phy_type_dsss = 2;
62+
int dot11_phy_type_irbaseband = 3;
63+
int dot11_phy_type_ofdm = 4;
64+
int dot11_phy_type_hrdsss = 5;
65+
int dot11_phy_type_erp = 6;
66+
int dot11_phy_type_ht = 7;
67+
int dot11_phy_type_IHV_start = 0x80000000;
68+
int dot11_phy_type_IHV_end = 0xffffffff;
69+
}
70+
71+
// DOT11_AUTH_ALGO_LIST
72+
interface DOT11_AUTH_ALGORITHM {
73+
int DOT11_AUTH_ALGO_80211_OPEN = 1;
74+
int DOT11_AUTH_ALGO_80211_SHARED_KEY = 2;
75+
int DOT11_AUTH_ALGO_WPA = 3;
76+
int DOT11_AUTH_ALGO_WPA_PSK = 4;
77+
int DOT11_AUTH_ALGO_WPA_NONE = 5; // used in NatSTA only
78+
int DOT11_AUTH_ALGO_RSNA = 6;
79+
int DOT11_AUTH_ALGO_RSNA_PSK = 7;
80+
int DOT11_AUTH_ALGO_WPA3 = 8;
81+
int DOT11_AUTH_ALGO_WPA3_ENT_192 = DOT11_AUTH_ALGO_WPA3;
82+
int DOT11_AUTH_ALGO_WPA3_SAE = 9;
83+
int DOT11_AUTH_ALGO_OWE = 10;
84+
int DOT11_AUTH_ALGO_WPA3_ENT = 11;
85+
int DOT11_AUTH_ALGO_IHV_START = 0x80000000;
86+
int DOT11_AUTH_ALGO_IHV_END = 0xffffffff;
87+
}
88+
89+
// Cipher algorithm Ids (for little endian platform)
90+
interface DOT11_CIPHER_ALGORITHM {
91+
int DOT11_CIPHER_ALGO_NONE = 0x00;
92+
int DOT11_CIPHER_ALGO_WEP40 = 0x01;
93+
int DOT11_CIPHER_ALGO_TKIP = 0x02;
94+
int DOT11_CIPHER_ALGO_CCMP = 0x04;
95+
int DOT11_CIPHER_ALGO_WEP104 = 0x05;
96+
int DOT11_CIPHER_ALGO_BIP = 0x06;
97+
int DOT11_CIPHER_ALGO_GCMP = 0x08;
98+
int DOT11_CIPHER_ALGO_GCMP_256 = 0x09;
99+
int DOT11_CIPHER_ALGO_CCMP_256 = 0x0a;
100+
int DOT11_CIPHER_ALGO_BIP_GMAC_128 = 0x0b;
101+
int DOT11_CIPHER_ALGO_BIP_GMAC_256 = 0x0c;
102+
int DOT11_CIPHER_ALGO_BIP_CMAC_256 = 0x0d;
103+
int DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100;
104+
int DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100;
105+
int DOT11_CIPHER_ALGO_WEP = 0x101;
106+
int DOT11_CIPHER_ALGO_IHV_START = 0x80000000;
107+
int DOT11_CIPHER_ALGO_IHV_END = 0xffffffff;
108+
}
109+
}
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/* Copyright (c) 2025 Eran Leshem, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
package com.sun.jna.platform.win32;
25+
26+
import com.sun.jna.Library;
27+
import com.sun.jna.Native;
28+
import com.sun.jna.Pointer;
29+
import com.sun.jna.Structure;
30+
import com.sun.jna.ptr.IntByReference;
31+
import com.sun.jna.ptr.PointerByReference;
32+
import com.sun.jna.win32.W32APITypeMapper;
33+
34+
/**
35+
* Module Name:
36+
* wlanapi.h
37+
* Abstract:
38+
* Definitions and data structures for wlan auto config client side API.
39+
*
40+
* @author Eran Leshem
41+
*/
42+
public interface WlanApi extends Library {
43+
WlanApi INSTANCE = Native.load("wlanapi", WlanApi.class);
44+
int WLAN_MAX_NAME_LENGTH = 256;
45+
46+
@Structure.FieldOrder({"dwNumberOfItems", "dwIndex", "InterfaceInfo"})
47+
class WLAN_INTERFACE_INFO_LIST extends Structure {
48+
public int dwNumberOfItems;
49+
public int dwIndex;
50+
public WLAN_INTERFACE_INFO[] InterfaceInfo = new WLAN_INTERFACE_INFO[1];
51+
52+
public WLAN_INTERFACE_INFO_LIST() {
53+
setAutoSynch(false);
54+
}
55+
56+
public WLAN_INTERFACE_INFO_LIST(Pointer p) {
57+
super(p);
58+
}
59+
60+
@Override
61+
public void read() {
62+
// First element contains array size
63+
dwNumberOfItems = getPointer().getInt(0);
64+
if (dwNumberOfItems > 0) {
65+
InterfaceInfo = (WLAN_INTERFACE_INFO[]) new WLAN_INTERFACE_INFO().toArray(dwNumberOfItems);
66+
super.read();
67+
} else {
68+
InterfaceInfo = new WLAN_INTERFACE_INFO[0];
69+
}
70+
}
71+
}
72+
73+
/**
74+
* Sruct WLAN_INTERFACE_INFO defines the basic information for an interface.
75+
*/
76+
@Structure.FieldOrder({"InterfaceGuid", "strInterfaceDescription", "isState"})
77+
class WLAN_INTERFACE_INFO extends Structure {
78+
public Guid.GUID InterfaceGuid;
79+
public char[] strInterfaceDescription = new char[WLAN_MAX_NAME_LENGTH];
80+
81+
/**
82+
* See {@link WLAN_INTERFACE_STATE} for possible values
83+
*/
84+
public int isState;
85+
}
86+
87+
/**
88+
* Structure WLAN_CONNECTION_ATTRIBUTES defines attributes of a wireless connection.
89+
*/
90+
@Structure.FieldOrder({"isState", "wlanConnectionMode", "strProfileName", "wlanAssociationAttributes",
91+
"wlanSecurityAttributes"})
92+
class WLAN_CONNECTION_ATTRIBUTES extends Structure {
93+
/**
94+
* See {@link WLAN_INTERFACE_STATE} for possible values
95+
*/
96+
public int isState;
97+
98+
/**
99+
* See {@link WLAN_CONNECTION_MODE} for possible values
100+
*/
101+
public int wlanConnectionMode;
102+
public char[] strProfileName = new char[WLAN_MAX_NAME_LENGTH];
103+
public WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes;
104+
public WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes;
105+
106+
public WLAN_CONNECTION_ATTRIBUTES(Pointer p) {
107+
super(p);
108+
}
109+
}
110+
111+
/**
112+
* The states of the network (interface).
113+
*/
114+
interface WLAN_INTERFACE_STATE {
115+
int wlan_interface_state_not_ready = 0;
116+
int wlan_interface_state_connected = 1;
117+
int wlan_interface_state_ad_hoc_network_formed = 2;
118+
int wlan_interface_state_disconnecting = 3;
119+
int wlan_interface_state_disconnected = 4;
120+
int wlan_interface_state_associating = 5;
121+
int wlan_interface_state_discovering = 6;
122+
int wlan_interface_state_authenticating = 7;
123+
}
124+
125+
interface WLAN_CONNECTION_MODE {
126+
int wlan_connection_mode_profile = 0;
127+
int wlan_connection_mode_temporary_profile = 1;
128+
int wlan_connection_mode_discovery_secure = 2;
129+
int wlan_connection_mode_discovery_unsecure = 3;
130+
int wlan_connection_mode_auto = 4;
131+
int wlan_connection_mode_invalid = 5;
132+
}
133+
134+
/**
135+
* Structure WLAN_ASSOCIATION_ATTRIBUTES defines attributes of a wireless association.
136+
* The unit for Rx/Tx rate is Kbits/second.
137+
*/
138+
@Structure.FieldOrder({"dot11Ssid", "dot11BssType", "dot11Bssid", "dot11PhyType", "uDot11PhyIndex",
139+
"wlanSignalQuality", "ulRxRate", "ulTxRate"})
140+
class WLAN_ASSOCIATION_ATTRIBUTES extends Structure {
141+
public Windot11.DOT11_SSID dot11Ssid;
142+
143+
/**
144+
* See {@link Windot11.DOT11_BSS_TYPE} for possible values
145+
*/
146+
public int dot11BssType;
147+
public Windot11.DOT11_MAC_ADDRESS dot11Bssid;
148+
149+
/**
150+
* See {@link Windot11.DOT11_BSS_TYPE} for possible values
151+
*/
152+
public int dot11PhyType;
153+
public WinDef.ULONG uDot11PhyIndex;
154+
public WinDef.ULONG wlanSignalQuality; // WLAN_SIGNAL_QUALITY
155+
public WinDef.ULONG ulRxRate;
156+
public WinDef.ULONG ulTxRate;
157+
158+
public WLAN_ASSOCIATION_ATTRIBUTES(Pointer p) {
159+
super(p);
160+
}
161+
}
162+
163+
@Structure.FieldOrder({"bSecurityEnabled", "bOneXEnabled", "dot11AuthAlgorithm", "dot11CipherAlgorithm"})
164+
class WLAN_SECURITY_ATTRIBUTES extends Structure {
165+
public boolean bSecurityEnabled;
166+
public boolean bOneXEnabled;
167+
168+
/**
169+
* See {@link Windot11.DOT11_AUTH_ALGORITHM} for possible values
170+
*/
171+
public int dot11AuthAlgorithm;
172+
173+
/**
174+
* See {@link Windot11.DOT11_CIPHER_ALGORITHM} for possible values
175+
*/
176+
public int dot11CipherAlgorithm;
177+
178+
public WLAN_SECURITY_ATTRIBUTES() {
179+
super(W32APITypeMapper.UNICODE);
180+
}
181+
}
182+
183+
/**
184+
* OpCodes for set/query interfaces.
185+
*/
186+
interface WLAN_INTF_OPCODE {
187+
int wlan_intf_opcode_autoconf_start = 0x000000000;
188+
int wlan_intf_opcode_autoconf_enabled = 1;
189+
int wlan_intf_opcode_background_scan_enabled = 2;
190+
int wlan_intf_opcode_media_streaming_mode = 3;
191+
int wlan_intf_opcode_radio_state = 4;
192+
int wlan_intf_opcode_bss_type = 5;
193+
int wlan_intf_opcode_interface_state = 6;
194+
int wlan_intf_opcode_current_connection = 7;
195+
int wlan_intf_opcode_channel_number = 8;
196+
int wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs = 9;
197+
int wlan_intf_opcode_supported_adhoc_auth_cipher_pairs = 10;
198+
int wlan_intf_opcode_supported_country_or_region_string_list = 11;
199+
int wlan_intf_opcode_current_operation_mode = 12;
200+
int wlan_intf_opcode_supported_safe_mode = 13;
201+
int wlan_intf_opcode_certified_safe_mode = 14;
202+
int wlan_intf_opcode_hosted_network_capable = 15;
203+
int wlan_intf_opcode_autoconf_end = 0x0fffffff;
204+
int wlan_intf_opcode_msm_start = 0x10000100;
205+
int wlan_intf_opcode_statistics = 0x10000101;
206+
int wlan_intf_opcode_rssi = 0x10000102;
207+
int wlan_intf_opcode_msm_end = 0x1fffffff;
208+
int wlan_intf_opcode_security_start = 0x20010000;
209+
int wlan_intf_opcode_security_end = 0x2fffffff;
210+
int wlan_intf_opcode_ihv_start = 0x30000000;
211+
int wlan_intf_opcode_ihv_end = 0x3fffffff;
212+
}
213+
214+
interface WLAN_OPCODE_VALUE_TYPE {
215+
int wlan_opcode_value_type_query_only = 0;
216+
int wlan_opcode_value_type_set_by_group_policy = 1;
217+
int wlan_opcode_value_type_set_by_user = 2;
218+
int wlan_opcode_value_type_invalid = 3;
219+
}
220+
221+
int WlanOpenHandle(int dwClientVersion, Pointer pReserved, IntByReference pdwNegotiatedVersion,
222+
WinNT.HANDLEByReference phClientHandle);
223+
int WlanCloseHandle(WinNT.HANDLE hClientHandle, Pointer pReserved);
224+
int WlanEnumInterfaces(WinNT.HANDLE hClientHandle, Pointer pReserved, PointerByReference ppInterfaceList);
225+
226+
/**
227+
* @param OpCode See {@link WLAN_INTF_OPCODE} for possible values
228+
* @param pWlanOpcodeValueType See {@link WLAN_OPCODE_VALUE_TYPE} for possible values
229+
*/
230+
int WlanQueryInterface(WinNT.HANDLE hClientHandle, Guid.GUID pInterfaceGuid, int OpCode,
231+
Pointer pReserved, IntByReference pDataSize, PointerByReference ppData,
232+
IntByReference pWlanOpcodeValueType);
233+
void WlanFreeMemory(Pointer pMemory);
234+
}

0 commit comments

Comments
 (0)