Skip to content

Commit

Permalink
Base project taken from Allseen git repo, and a simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
ikeralbeniz committed Dec 29, 2016
1 parent 4ccbd6a commit 9ef59bf
Show file tree
Hide file tree
Showing 38 changed files with 3,161 additions and 29 deletions.
47 changes: 38 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
*.class
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# Mobile Tools for Java (J2ME)
.mtj.tmp/
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml

# Package Files #
*.jar
*.war
*.ear
# Sensitive or high-churn files:
.idea/dataSources/
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Gradle:
.idea/gradle.xml

# Mongo Explorer plugin:
.idea/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
11 changes: 11 additions & 0 deletions .idea/libraries/net_java_dev_jna_jna_platform_4_2_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 12 additions & 18 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
MIT License
ISC License

Copyright (c) 2016 Iker Perez de Albeniz
Copyright (c) 2016 Iker Perez de Albeniz. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,63 @@
# jwlanapi
A Java Wrapper for Windows wlanapi
# JWlanAPI
JWlanApi is a JNA wrapper for [Micosoft Windows Native Wifi API](https://msdn.microsoft.com/library/windows/desktop/ms706556(v=vs.85).aspx). The goal of this project is to provide an easy and reliable Wi-Fi connection manager for Windows based on Java (voiding using ***netsh*** or similar approaches).

The base code is taken from [AllSeen/Alljoyn](https://allseenalliance.org/) proyect, and more specifically based on the [code commited by at4wireless](https://github.com/allseenalliance/compliance-tests/tree/master/java/components/validation-ctt/HEAD/ctt_testcases/src/com/at4wireless/alljoyn/wifiapi).

## Current Status
Current code is a bit buggy, some method are not working and also more code is needed to handles some data and serialize them properly.

TO BE DONE:

* Make ***connect*** method work
* Make ***connectedSsid*** method work (current conected signal SSID)
* ScanResult signal level, frequency and capabilities values are not correctly handled.
* Serialize ScanResult capabilities (currently a string with int values, ned to use [DOT11_AUTH_ALGORITHM](https://msdn.microsoft.com/en-us/library/windows/desktop/ms705989(v=vs.85).aspx) and [DOT11_CIPHER_ALGORITHM](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706003(v=vs.85).aspx) enums)
* Change all method to asynchronous result handling with custom listeners.

## Example Code

Using this library is quite easy, here you have a simple code snippet.

```java
import net.java.dev.wlanapi.ScanResult;
import net.java.dev.wlanapi.WifiManager;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* Created by i.perezdealbeniz on 29/12/2016.
*/
public class SimpleTest {

public static void main(String[] args) throws InterruptedException {
System.out.println("Java wlanapi.dll Wrapper Test:\n");
System.out.println("******************************\n");
WifiManager wlan_manager = new WifiManager();

System.out.printf("Wifi Enabled: %s\n\n",wlan_manager.isWifiEnabled());

System.out.println("Detected Wifi Networks:\n");
List<ScanResult> scan_results = wlan_manager.waitForScanResults(5,
TimeUnit.SECONDS);
for(int i=0; i < scan_results.size(); i++){
System.out.println("\t SSID : "+scan_results.get(i).SSID);
System.out.println("\t\t BSSID : "+scan_results.get(i).BSSID);
System.out.println("\t\t Frequency (MHz): "+
Integer.toString(scan_results.get(i).frequency));
System.out.println("\t\t Signal Level (db) : "+
Integer.toString(scan_results.get(i).level));
System.out.println("\t\t Capabilities : "+
scan_results.get(i).capabilities);
System.out.println();
}

System.out.println("Configured Wifi Networks:");
List<String> configured_networks = wlan_manager.getConfiguredNetworks();
for(int i=0; i < scan_results.size(); i++){
System.out.println("\t"+ Integer.toString(i)+"\t"+scan_results.get(i));
}
}

}
```
12 changes: 12 additions & 0 deletions jwlanapi.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="net.java.dev.jna:jna-platform:4.2.2" level="project" />
</component>
</module>
66 changes: 66 additions & 0 deletions src/net/java/dev/wlanapi/Dot11BssidList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright AllSeen Alliance. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*******************************************************************************/
package net.java.dev.wlanapi;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.Structure;

/**
* Contains a list of basic service set (BSS) identifiers.
*/
public class Dot11BssidList extends Structure
{
public static class ByReference extends Dot11BssidList implements Structure.ByReference
{

}

/**
* An NDIS_OBJECT_HEADER structure that contains the type, version, and size information of an NDIS structure. For most DOT11_BSSID_LIST structures, set
* the Type member to NDIS_OBJECT_TYPE_DEFAULT, set the Revision member to DOT11_BSSID_LIST_REVISION_1, and set the Size member to
* sizeof(DOT11_BSSID_LIST).
*/
public NdisObjectHeader Header;

/**
* The number of entries in this structure.
*/
public long uNumOfEntries;

/**
* The total number of entries supported.
*/
public long uTotalNumOfEntries;

/**
* A list of BSS identifiers. A BSS identifier is stored as a DOT11_MAC_ADDRESS type.
*/
public char[][] BSSIDs;

/*public Dot11BssidList()
{
BSSIDs = new char[1][6];
}*/

@Override
protected List<String> getFieldOrder()
{
return Arrays.asList("Header", "uNumOfEntries", "uTotalNumOfEntries", "BSSIDs");
}

}
32 changes: 32 additions & 0 deletions src/net/java/dev/wlanapi/Dot11PhyType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright AllSeen Alliance. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*******************************************************************************/
package net.java.dev.wlanapi;

public enum Dot11PhyType
{
UNKNOWN,
ANY,
FHSS,
DSSS,
IRBASEBAND,
OFDM,
HRDSSS,
ERP,
HT,
VHT,
IHV_start, //0x80000000
IHV_end //0xffffffff
}
62 changes: 62 additions & 0 deletions src/net/java/dev/wlanapi/Dot11Ssid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright AllSeen Alliance. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*******************************************************************************/
package net.java.dev.wlanapi;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.Structure;

/**
* Contains the SSID of an interface
*/
public class Dot11Ssid extends Structure
{
public static class ByReference extends Dot11Ssid implements Structure.ByReference
{

}

public static int DOT11_SSID_MAX_LENGTH = 32;

/**
* The length, in bytes, of the ucSSID array.
*/
public int uSSIDLength;

/**
* The SSID. DOT11_SSID_MAX_LENGTH is set to 32.
*/
public byte[] ucSSID;

public Dot11Ssid()
{
ucSSID = new byte[DOT11_SSID_MAX_LENGTH];
}

/*public Dot11Ssid(Pointer p)
{
uSSIDLength = p.getInt(0);
ucSSID = p.getByteArray(4, uSSIDLength);
}*/

@Override
protected List<String> getFieldOrder()
{
return Arrays.asList("uSSIDLength", "ucSSID");
}
}

Loading

0 comments on commit 9ef59bf

Please sign in to comment.