Using wpa_supplication methods via JNI call to WifiNative

261 views
Skip to first unread message

Vitor Bernardo

unread,
Oct 16, 2013, 1:30:26 PM10/16/13
to andro...@googlegroups.com
Dear Android-ndk's,

We are trying to access to some wpa_supplicant functions that are not available in the API. 
The main goal is to access to the WiFi power management functions / states  (i.e., controlling the WiFi sleep mode/state).

Instead of sending commands direct to the wpa_supplicant, we first try to access to the wpa_supplicant functions calling WifiNative methods through the NDK approach using JNI. 

Currently, we can run without problems the "isDriverLoaded()" functions from WifiNative using JNI approach, but the commands really related with wpa_supplicant have a strange behaviour. For instance, when calling "listNetworksCommands()" or similar calls the returned string is ALWAYS null. 

Is there a logic problem in this approach? Should send / create a direct interface to wpa_supplicant using the control interface or can we use this approach?

--
Best Regards,
Vítor Bernardo & Bruno Correia

Robert Perez

unread,
Jun 11, 2014, 4:23:02 AM6/11/14
to andro...@googlegroups.com
Hi,
Please, can you explain how to call isDriverLoaded via JNI?
Is the only function that I need in my app :)
Thanks

Bruno Correia

unread,
Jun 13, 2014, 5:58:55 AM6/13/14
to andro...@googlegroups.com
Hi Robert,

I will assume that you have some knowledge about using NDK and JNI in Android. If not, there are very good tutorial and examples in the web, just google it.

If you check the android_net_wifi_Wifi.cpp file in the Android source code (the file which implements the methods used by the WifiNative, you will see at the bottom, the JNI registration of every function.

For your case, you have:  { "isDriverLoaded", "()Z",  (void *)android_net_wifi_isDriverLoaded}.

Next, you have three main methods that you can use in JNI to call any JNI registered function. First, you need to find the class via FindClass function. Then, you need to find the specific method that you want, using the GetStaticMethodID. The final step is just call that function via CallStaticBooleanMethod (Boolean because your method returns a jboolean).

Some code to help you (not tested):
jclass wifiClass = (*env)->FindClass(env, "android/net/wifi/WifiNative");
jmethodID methodID = (*env)->GetStaticMethodID(env, wifiClass,"isDriverLoaded","()Z");
(*env)->CallStaticBooleanMethod(env, wifiClass, methodID);

Best regards
Reply all
Reply to author
Forward
0 new messages