how to send ioctls to wifi driver using Android Apps?

3,252 views
Skip to first unread message

karan

unread,
Apr 19, 2012, 6:54:35 AM4/19/12
to android-ndk
hi i have been developing android app which needs to communicate with
wifi driver internally through ioctls.We have native shared library
which takes care of talking to driver.Developed the android app and
JNI library which is linked with the shared library.
The issue is that the app able to call the ioctl function but its
returning a negative value which means failed to invoke.The same thing
is working with the a native c test application executed through adb
shell which also uses the same shared library.
Do android application need any special permissions which needs to be
added in manifest.xml file??OR is there any alternate solution to it?

Any help would be appreciated...

Thanks

Chris Stratton

unread,
Apr 19, 2012, 3:24:15 PM4/19/12
to andro...@googlegroups.com
See the other thread.  You cannot do this, except on modified android versions.

Thomas Martitz

unread,
Apr 20, 2012, 6:22:55 AM4/20/12
to andro...@googlegroups.com

The app needs R/W permissions on the special (device) file you use
ioctl() on. Keep in mind that Android has a separate user for each app,
so the device file needs to be effectively world read- and writeable.

Best regards.

karunakar reddy

unread,
Apr 20, 2012, 10:46:11 AM4/20/12
to andro...@googlegroups.com
Thanks for ur reply.
The issue is as network devices doesn't have any device files as char and block.here i am using a socket to communicate to send ioctls to wifi driver.Is there any way to change the permissions of the  socket?i have added the INTERNET permission to create the socket in manifest file.Please help me out... Or if it not possible i can go with runnig the c executable through java code giving the super user permissions to it..



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Chris Stratton

unread,
Apr 20, 2012, 11:02:42 AM4/20/12
to andro...@googlegroups.com
On Friday, April 20, 2012 10:46:11 AM UTC-4, karan wrote:
The issue is as network devices doesn't have any device files as char and block.

On the contrary it usually does.  But you as an application (rather than system) programmer you probably shouldn't touch those (and android won't let you anyway).
 
here i am using a socket to communicate to send ioctls to wifi driver.

What makes you think that the socket interface exposes wifi-unique parameters?

Perhaps you should tell us what ioctl you are trying to use and what you are hoping to accomplish by using it?  Post a _brief_ code snippet with the values of all data structure elements.

karunakar reddy

unread,
Apr 20, 2012, 2:14:58 PM4/20/12
to andro...@googlegroups.com

myself a system programmer,i not that aware of this android apps.Here we are trying to interact with the wifi driver.
SIOCIWFIRSTPRIV is the ioctl which i am trying to send.
My code 
able to get the socket fd by adding INTERNET permission in the manifest file.
fd =  sock = socket(AF_INET, SOCK_DGRAM, 0);

res = ioctl(fd,SIOCIWFIRSTPRIV,&buffer);
when executed this ioctl using JNI code is returning OPERATION NOT PERMITTED as the error code.
But the same thing works when called using a c executable.
Is this a restriction for android apps??In some forums they have strictly said we cant do it directly through android apps.They suggested to use the test application ie c executable.If further info required i wil provide
Thanks for reply..



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/E7tbTebOrfIJ.

To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

Chris Stratton

unread,
Apr 20, 2012, 2:37:28 PM4/20/12
to andro...@googlegroups.com
On Friday, April 20, 2012 2:14:58 PM UTC-4, karan wrote:
myself a system programmer,i not that aware of this android apps.

Then you are asking in the wrong place.  Neither android-developers nor android-ndk is appropriate for system programming tasks, but only for what can be accomplished with sdk or ndk apps respectively.
 
Here we are trying to interact with the wifi driver.
SIOCIWFIRSTPRIV is the ioctl which i am trying to send.

That's appears to be a private command, so what it does and what it requires is uniqe to a given driver which you haven't specified.
 
when executed this ioctl using JNI code is returning OPERATION NOT PERMITTED as the error code.
But the same thing works when called using a c executable.
Is this a restriction for android apps??In some forums they have strictly said we cant do it directly through android apps.They suggested to use the test application ie c executable.If further info required i wil provide

If the issue is privilege, the proper way to do it is to incorporate it into the right part of the platform code.  Or if you are hacking a special app for a "rooted" device then use whatever hack lets you run a helper executable as root on that device.  Neither is on topic in this group, though for incorporating it into a custom android build you can try android-porting.

Debayan Banerjee

unread,
Feb 27, 2014, 6:27:23 AM2/27/14
to andro...@googlegroups.com
HI

I am trying to make a simple ioctl call in my application to wifi driver . Getting IOCTL error = -2

target device nexus 5 , chip - BCM4339  , rooted device , Kitkat , AOSP Hammerhead , kernel - 3.4.0

I am writing c code and build as executable

sample code
--------------------
/* open socket to kernel */
    if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
        syserr("socket");
        printf("\n %s %s %d socket return : %d \n",__FILE__,__FUNCTION__,__LINE__,s);
    }


    /* do it */
    ioc.cmd = cmd;
    printf("\n %s %s %d Command passed : %d \n",__FILE__,__FUNCTION__,__LINE__,cmd);
    ioc.buf = buf;
    ioc.len = len;
    ioc.set = set;
       //  strncpy(ifr.ifr_name, name, IFNAMSIZ);
          //  ifr.ifr_data = (caddr_t) &ioc;
      
    ifr->ifr_data = (caddr_t) &ioc;
    //if ((ret = ioctl(s,SIOCIWFIRSTPRIV,ifr)) < 0) {
     // if (ioctl(s, SIOCGIFCONF, ifr) < 0) {
     if ((ret = ioctl(s, SIOCDEVPRIVATE, ifr)) < 0) {
       printf("\n %s %s %d  \n",__FILE__,__FUNCTION__,__LINE__);
        if (cmd != WLC_GET_MAGIC) {
          printf("\n %s %s %d IOCTL_ERROR : %d \n",__FILE__,__FUNCTION__,__LINE__,IOCTL_ERROR);
            ret = IOCTL_ERROR;
        }
    }


------------------------------------------------------------------------------------------------------

Socket is forming but unable to communicate with driver . Can anybody please tell me what i am missing ??



Regards
Debayan
Reply all
Reply to author
Forward
0 new messages