|
| 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