ioctl permission denied

1,974 views
Skip to first unread message

seema

unread,
Jul 1, 2011, 5:55:28 AM7/1/11
to android-ndk
Hello All,

I want to make an ioctl call for scanning and bringing up the
interface. I get "PERMISSION DENIED". My application has root access.
My device is rooted. I have also given the required permissions in the
AndroidManifest.xml file. What do I do? Can anybody help?


Regards,
Seema

Kevin Galligan

unread,
Jul 1, 2011, 9:22:32 AM7/1/11
to andro...@googlegroups.com

Post code. How are you giving your app root access? How are you calling the c code?


--
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...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

seema

unread,
Jul 6, 2011, 12:35:46 AM7/6/11
to android-ndk
Hello All,

Here is the JNI code I am using for scanning:
-------------------------------------------------------------------
struct iw_scan_req scanopt;
struct iwreq wrq;

memset(&scanopt, 0, sizeof(scanopt));

wrq.u.data.pointer = &scanopt;
wrq.u.data.flags = 0;
wrq.u.data.length = 0;

strncpy(wrq->ifr_name, "tiwlan0", IFNAMSIZ);
ioctl(skfd, SIOCSIWSCAN, wrq); // Operation Not permitted error
----------------------------------------------------------------------

The phone is rooted. The AndroidManifest.xml file has the following
permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /
>
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I also acquire root privileges in my Java code:
try {
p = Runtime.getRuntime().exec("su");
} catch (IOException e) {
e.printStackTrace();
}

Can anyone please help?
How do I perform scan using jni code?

Regards,
Seema

Kevin Galligan

unread,
Jul 6, 2011, 7:51:49 AM7/6/11
to andro...@googlegroups.com

As far as I know, you need to execute a different process with su. Create a c/c++ program, and build it to an executable.  Then call that from your app. The new process will have root. Not your current process.

This means you don't get to use jni. You'd need to communicate with an external process somehow (sockets, whatever).

If you figure out how to give your current proc root, that would be awesome. Please post that.

seema

unread,
Jul 6, 2011, 10:28:47 AM7/6/11
to android-ndk
Okay. Thank you. I will try if I can grant root permission to the
current process.
If anyone know about it please let me know

Thanks and Regards,
Seema

On Jul 6, 4:51 pm, Kevin Galligan <kgalli...@gmail.com> wrote:
> As far as I know, you need to execute a different process with su. Create a
> c/c++ program, and build it to an executable.  Then call that from your app.
> The new process will have root. Not your current process.
>
> This means you don't get to use jni. You'd need to communicate with an
> external process somehow (sockets, whatever).
>
> If you figure out how to give your current proc root, that would be awesome.
> Please post that.

Kevin Galligan

unread,
Jul 6, 2011, 10:35:25 AM7/6/11
to andro...@googlegroups.com
I'm pretty sure you can't, so if/when you come to that conclusion, its
going to look something like this. At least this is how we did it:

java.lang.Process sh = Runtime.getRuntime().exec("su -c sh");
OutputStream os = sh.getOutputStream();

//Gobble the outputs
StreamThread it = new StreamThread(sh.getInputStream());
StreamThread et = new StreamThread(sh.getErrorStream());
it.start();
et.start();

String yourProc = "yourprocname";

//Write your commands
os.write((yourProc + "\n").getBytes("ASCII"));

siva prasad reddy

unread,
Jul 6, 2011, 8:42:09 AM7/6/11
to andro...@googlegroups.com
Thanks for your reply!!
I got it.!!!
--
Regards
-------------
Siva Prasad Reddy S,
Associate Software Engineer - Trainee,
ArijaSoft,
Hyderabad.



Reply all
Reply to author
Forward
0 new messages