1. Are you ready for the Galaxy S20? Here is everything we know so far!

Unable to Start Driver from Android App

Discussion in 'Android Development' started by arjun.laxman, Feb 3, 2011.

  1. arjun.laxman

    arjun.laxman Lurker
    Thread Starter

    Hi,
    I am writing an Android Application for the first time. I need to start a Tun driver from Android App. I have two shared libraries created. One is JNI shared library and the other is the cross-compiled library which actually does creating of a tunneling module,assigning IP Address, starting the tun driver and configuring by setting the IP address and setting up a route for it.
    After getting server IP address and server port through App, I call JNI function to start tun module. The JNI library in turn calls the function in the cross-compiled library which actually does the job.
    But the issue is the permission to start the device files. I faced issue while creating a socket, so I set the permission android.permission.INTERNET in AndroidManifest.xml. I was able to create socket and DHCP too worked. Now, I am facing an issue to start the Tun driver. I am able to open the device file "/dev/tun" but unable to set the properties to it by calling ioctl(fd, TUNSETIFF, &ifr) due to Permission problems.
    If I make the cross-compiled library an executable and start it on ADB shell prompt of the mobile phone using SU permissions, it works perfectly fine. But through Android App, I am not able to do so due to some permission issue. I have tried giving all sorts of permissions in AndroidManifest.xml file, but no progress. I am stuck with this problem for days and any help will be greatly appreciated.

    Thanks in advance.

    Regards,
    Arjun
     



    1. Download the Forums for Android™ app!


      Download

       
  2. miXer

    miXer Android Enthusiast

    Have logcat open when running the app in the emulator, and copy the entire exception thrown there and paste it here.
     
  3. arjun.laxman

    arjun.laxman Lurker
    Thread Starter

    Following is the log:

    I/PowerManagerService( 2437): Ulight 3->7|0
    V/WindowManager( 2437): Dsptch > Window{4814cc18 com.example.Tunneling/com.examp
    le.Tunneling.Tun_utils paused=false}
    V/WindowManager( 2437): Dsptch > Window{4814cc18 com.example.Tunneling/com.examp
    le.Tunneling.Tun_utils paused=false}
    V/InputDevice( 2437): ID[0]=0(0) Up(1=>0)
    E/Tunneling( 6732): Submit button clicked
    E/Tunneling( 6732): Save button clicked
    D/dalvikvm( 6732): Trying to load lib /data/data/com.example.Tunneling/lib/libNT
    Client.so 0x47b49bc8
    D/dalvikvm( 6732): Added shared lib /data/data/com.example.Tunneling/lib/libNTCl
    ient.so 0x47b49bc8
    D/dalvikvm( 6732): No JNI_OnLoad found in /data/data/com.example.Tunneling/lib/l
    ibNTClient.so 0x47b49bc8, skipping init
    D/dalvikvm( 6732): Trying to load lib /data/data/com.example.Tunneling/lib/libTu
    nneling.so 0x47b49bc8
    D/dalvikvm( 6732): Added shared lib /data/data/com.example.Tunneling/lib/libTunn
    eling.so 0x47b49bc8
    D/dalvikvm( 6732): No JNI_OnLoad found in /data/data/com.example.Tunneling/lib/l
    ibTunneling.so 0x47b49bc8, skipping init
    E/Tunneling( 6732): Start_tun()
    E/Tunneling( 6732): Server address is 168.219.193.188
    E/Tunneling( 6732): Server port is 5000
    E/Tunneling( 6732): Read per once is 1500
    E/Tunneling( 6732): Entering Start_Tunneling_module()
    E/Tunneling( 6732): After Setting the initial DebugLevel and Format
    E/Tunneling( 6732): Got the Server Ip Address is 168.219.193.188
    E/Tunneling( 6732): Trying to Start up the Tunneling Client
    E/Tunneling( 6732): start remote server with [5000] port
    E/Tunneling( 6732): Network Initialize success
    E/Tunneling( 6732): sock value is 37,psock value is37
    E/Tunneling( 6732): SOCKET::Open() created successfully, the m_hSock is 37, ret is 0
    E/Tunneling( 6732): DHCP:: Source Address and Port is (null):5000
    E/Tunneling( 6732): REMOTE MESSAGE IN :[168.219.193.188(5000)] - 44 Byte
    E/Tunneling( 6732): STUN RESPONSE PACKET ==>> now processing
    E/Tunneling( 6732): GET [DHCP_RESPONSE]--
    E/Tunneling( 6732): GetDHCP =>
    E/Tunneling( 6732): <=GetDHCP
    E/Tunneling( 6732): GET [DHCP_RESPONSE]++
    E/Tunneling( 6732):
    E/Tunneling( 6732): Address Allocation Success
    E/Tunneling( 6732): Trying to start the Tun Driver
    E/Tunneling( 6732): Cannot Set Driver OTUNSETIFF
    E/Tunneling( 6732): Cannot Open tun driver
     
  4. miXer

    miXer Android Enthusiast

    There is no exception thrown here. It looks like you have all the permissions right.
     
    arjun.laxman likes this.
  5. arjun.laxman

    arjun.laxman Lurker
    Thread Starter

    I printed the return value of the ioctl by using strerror(errno) called :


    These were the logs::

    E/Tunneling(10040): DHCP:: Source Address and Port is (null):5000
    E/Tunneling(10040): REMOTE MESSAGE IN :[168.219.193.188(5000)] - 44 Byte
    E/Tunneling(10040): STUN RESPONSE PACKET ==>> now processing
    E/Tunneling(10040): GET [DHCP_RESPONSE]--
    E/Tunneling(10040): GetDHCP =>
    E/Tunneling(10040): <=GetDHCP
    E/Tunneling(10040): GET [DHCP_RESPONSE]++
    E/Tunneling(10040):
    E/Tunneling(10040): Address Allocation Success
    E/Tunneling(10040): Trying to start the Tun Driver
    E/Tunneling(10040): Cannot Set Driver OTUNSETIFF Operation not permitted
    E/Tunneling(10040): Cannot Open tun driver
     
  6. arjun.laxman

    arjun.laxman Lurker
    Thread Starter

    I printed the return value of the ioctl by using strerror(errno) called :

    These were the logs::

    E/Tunneling(10040): DHCP:: Source Address and Port is (null):5000
    E/Tunneling(10040): REMOTE MESSAGE IN :[168.219.193.188(5000)] - 44 Byte
    E/Tunneling(10040): STUN RESPONSE PACKET ==>> now processing
    E/Tunneling(10040): GET [DHCP_RESPONSE]--
    E/Tunneling(10040): GetDHCP =>
    E/Tunneling(10040): <=GetDHCP
    E/Tunneling(10040): GET [DHCP_RESPONSE]++
    E/Tunneling(10040):
    E/Tunneling(10040): Address Allocation Success
    E/Tunneling(10040): Trying to start the Tun Driver
    E/Tunneling(10040): Cannot Set Driver OTUNSETIFF Operation not permitted
    E/Tunneling(10040): Cannot Open tun driver[/QUOTE]
     
Loading...

Share This Page

Loading...