My goal is to send HDMI CEC commands from a standard (i.e non-system) app running on an Android box equipped with Pulse-Eight's USB dongle.
Following these instructions I successfully managed to compile libcec for Android and execute it as root on the box, with this command:
echo <my-cec-command> | cec-client -s /dev/ttyACM0
where /dev/ttyACM0 is the device file created by the system when plugging the dongle.
However the permissions of this file prevent the command to be executed by a non-root user (therefore it cannot be executed from my Android app).
On the other hand the app can actually access the USB dongle via the USB Host API of the Android SDK (provided the user grants the permission) and can even be wrapped into a USB serial controller with UsbSerial library.
But I don't see any way to make the bridge between the connection provided by Android's USB Host API and libcec/cec-client. Do you have any idea or suggestion?
The best solution that I have found so far is to use USB Host API + UsbSerial library to read/write CEC packets on the adapter's serial port with pure Java code (no embedded libCEC).
I did some retro-engineering on libCEC to find out the appropriate commands for basic operations like switching TV on & off and setting active source.
And I finally came up with the following UsbCecConnection java class: https://gist.github.com/sdabet/ac4d7711d1a529806cb7b695530b1fac
I want to connect two devices using Wifi-Direct.
One is a pc with Linux (during my test I'm using Linux Mint 17.2), the other is an Android smartphone (Samsung Galaxy S3 with Android 4.3. Not rooted and don't want to root).
Reading a number of guides on the internet, I decided to use wpa_supplicant in Linux and to create an app for Android.
This is one of the best guides I found for wpa_supplicant:
https://web.archive.org/web/20210114180304/https://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts
When I run iw list I see that the "Supported interface modes:" allows P2P_client and P2P_GO.
My wpa_supplicant.conf contains:
ctrl_interface=/var/run/wpa_supplicant
update_config=1
ap_scan=1
device_name=My-pc
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1
p2p_go_intent=15
p2p_go_ht40=1
The app is very similar to this example (it's from a book) https://github.com/retomeier/Wrox-ProfessionalAndroid-4E/blob/9741a8b62005d49519b1decfea21e7213fdd94a3/Snippets_ch18/app/src/main/java/com/professionalandroid/apps/myapplication/WiFiDirectActivity.java
It works as expected. When I try it with two Android devices, they can see each other and connect (it appear the Wifi-Direct icon).
Now I am trying to connect Android and Linux, but I guess I don't really understand how wpa_supplicant works.
I also saw this question that is very similar to what I asked, but it doesn't really answer my doubts...
Direct Wifi Communication between android smartphone and other devices
My problem is that I can't understand how to do the handshake between the two devices and how to set up the network.
Wpa_supplicant is my problem. I run:
sudo wpa_supplicant -wlan0 -Dnl80211 -c/etc/wpa_supplicant.conf
sudo wpa_cli
But I had a lot of problems:
The device_name (and other parameters) weren't set as I specifiend in the .conf file
wpa_supplicant continues to try to connect to all the networks
p2p_find was really slow...
so I went into /usr/share/dbus-1/system-services and moved away the two files
fi.epitest.hostap.WPASupplicant.service
fi.w1.wpa_supplicant1.service
Now I can
sudo killall wpa_supplicant
and it really dies, disconnecting me from Wifi without reconnecting the following second.
Now I can launch wpa_supplicant and the three problems are resolved.
I go into wpa_cli, launch "p2p_find" and at the same time, I enable the search from within the app.
Android and Linux can now see each other.
P2P-DEVICE-FOUND 00:11:22:44:88:ff p2p_dev_addr=00:11:22:44:88:ff
pri_dev_type=10-0050F204-5 name='GT-I9300' config_methods=0x188
dev_capab=0x24 group_capab=0x0 vendor_elems=1 new=0
With "p2p_peers" I can see the cellphone MAC.
> aa:bb:cc:dd:ee:ff
Here I can't go ahead. I tried various possibilities, but none of them worked. My objective is to have Linux as Group Owner.
Question 1.1: Which is the correct way to handshake the two devices?
Question 1.2: When I try p2p_connect I often get "Michael MIC failure detected" between the results, what does it means in this contest?
Question 1.3: Android currently tries to connect with PBC. There is a way to connect with PIN?
Seeing that I couldn't connect Android/Linux, I tried to do some practice with Linux/Linux (Linux Mint as GO, Ubuntu as Client), following examples from internet like the ones in the first link.
I have a number of problems even here.
In Mint I try
p2p_connect MAC_UBUNTU pin auth
in Ubuntu I try
p2p_connect MAC_MINT PIN_GENERATED_BY_MINT
When I write the psp_connect in Mint, it creates a new interface p2p_wlan0 _0, and it returns
P2P-DEVICE-LOST p2p_dev_addr=MAC_UBUNTU
then the p2p_connect launched from Ubuntu fails.
Question 2.1 Why it switches interface when creating the group?
Question 2.2 What is the correct way to handle this change? After the change I can't p2p_find Ubuntu anymore (I have to wait some time or restart everything)
Question 2.3 Should Ubuntu change it's interface?
Question 2.3 In the new interface I should set the IP for both Ubuntu and Mint... how should I do this with static IPs?
Question 2.4 If I want to set up for example a DHCP server and client?
Question 1.4 And with Android(client) / Linux(GO)?
I worked a lot on this problem and here is the answers that I found:
Answer 1.1 There are a lot of possibilities and the correct one depends on what you are trying to achieve.
You can find the various possibilities here: http://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts
I wanted Linux as a GO and Android as a client, so what worked for me in Linux is:
// Kill current supplicant and avoid its automatic recreation
system("mv /usr/share/dbus-1/system-services/fi.* .");
system("killall udhcpd");
system("wpa_cli -i wlan0 terminate -B");
usleep(300000);
// Start new supplicant
system("wpa_supplicant -Dnl80211 -iwlan0 -c /etc/p2p_supplicant.conf -B");
system("wpa_cli -iwlan0 p2p_group_add");
system("ifconfig p2p-wlan0-0 192.168.1.2");
// Connect with a peer
for (;;) {
system("wpa_cli -ip2p-wlan0-0 wps_pbc");
system("udhcpd /etc/udhcpd.conf");
// Here start your TCP server on a port
Server server([port]);
server.startServer();
}
N.B. To destroy P2P connection and restart the normal one I use this script:
#!/bin/bash
wpa_cli -i wlan0 terminate -B
wpa_cli -i p2p-wlan0-0 terminate -B
cp ./fi.* /usr/share/dbus-1/system-services/
service network-manager restart
Here the server listens for a connection and the android client connects to it. I used a very easy TCP server found on the first website and it worked like a charm.
It's important to start the udhcpd or you won't get the "connected" icon in Android.
For the Android side, I followed what I saw on http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html and it worked perfectly.
Answer 1.2 From wpa_cli you can get a lot of different warnings and errors. I saw that simply calling the function (like I did in the previous snippet) made everything work despite the warnings. I ignored them.
Answer 1.3 The connection using PIN works, when I tried it I wasn't starting the udhcpd and that crashed my connection every time. It was not due to PIN or PBC.
Answer 2.1 Both the server and the client are switching interface.
It is a very similar behaviour to what you usually do with sockets. You create a listening socket, somebody connects, you create a new socket to handle that client in a separate thread while the listening socket is still there, waiting for other users.
You do the same with interfaces. Starting a wpa_cli that monitors the wlan0 interface and one that monitors the p2p-wlan0-0 interface gives a good idea of what is happening during the change.
Answer 2.2 The client "went" to the other interface and is now ready to receive an IP. Start the DHCP and TCP servers!
Answer 2.3 Don't use static IP. Only only for the server is ok, the client should use a DHCP IP. Maybe there is a way to handle static IPs, but it was not useful for my objectives.
Answer 2.4 Done. That was the problem all along
Answer 1.4 This works perfectly even with Android/linux.
Sorry if I made some mistake in my answer, I still don't get the whole picture of WiFi-Direct connections, I simply hope that this can help someone else.
(May not be a complete answer, but right direction)
The issue is on the Linux side. I'm encountering similar issues between a Cyanogenmod (Android 5) and Fedora 22, attempting to use Wifi Direct (Wifi P2P) for Intel's Wireless Display Software for Linux OS (WDS).
Specifically, Intel's connman diverged (written from scratch) back in 2009 from what had been standard in Linux, NetworkManager. Connman appears to be the only implementation of Wifi Direct (Wifi P2P) for Linux, and had been written for the embedded (mobile) market.
Due to an RPM issue, connman remains untested on my system, but the software should provide the dbus communications Linux needs.
Website: https://01.org/connman
Did you simply tried to activated your hotspot option on Android? Then connect with the Ubuntu device, check the connected IP on the Android hotspot options and give it to your app.
It work for me for remote controling my Ubuntu system.
I new to Android embedded technology. I am working on Android device to external modem communication.
There will a external modem connected to Android device with USB.
now need to run modem command on external modem using Android application.
Should i start with http://code.google.com/p/usb-serial-for-android/ or http://source.android.com/accessories/index.html. Is there any other way to achieve it.
Please let me know your comments based that i will go forward.
Thank you.
I work in a project to make a telephone caller blocker using old 56k serial modem connected to an Android TV stick using an usb to serial adapter. I use USb terminal apk to senh Hayes AT commands to the modem, and it works flawlessly. I can configure the modem with AT#CID=1 to retrieve caller id data. The final process must include a self config part to make the modem act as caller id, a database part, that stores calls and compares with black and white list numbers, and a on hook modem command to block the call. I think that a very beginner android developer can reach it easy, but I have no ability in android. In arduino, I have made the same system working flawlessly.
I want to develop an android application that can access blocked website. I thought about changing DNS address but Android give permission only for wifi dns address changing. I have also searched about using proxy sites but i couldn't make it . I'm searching for more compatible solution .
I'm waiting your suggestions. Thanks in advance.
There are many types of block which can be applied to a user on a mobile network.
The one you are referring to is done via DNS and I suspect you want to do such a thing because Android does not provide an interface to change DNS when you are using a mobile connection.
In that case is necessary to use root privileges. Your app will be running only on a rooted device. So you need to learn how to run a command using su. A good way to learn is to take a look to an open source root app such as Ad-Away.
To change DNS for a mobile network is necessary to know the Android version: in KitKat the DNS resolution is done through the netd daemon which ignores changes made via setprop. In Android <4.4 many DNS changer apps used commands like these
setprop dhcp.eth0.dns1 8.8.8.8
setprop dhcp.eth0.dns2 8.8.4.4
For Android 4.4 I wrote an app called Override DNS which uses a different set of commands.
Internet censorship can be done on other different levels.
I think the best way to circumvent any kind of block is to host a VPN server on a VPS located in USA or Europe and to activate a VPN from Android device. With this method any kind of network communication can be sent through the VPN so there's no problem related to DNS etc. In this scenario there's no need to have root privileges (depending on the VPN technology choosen).
How can I capture mobile phone traffic on Wireshark?
Here are some suggestions:
For Android phones, any network: Root your phone, then install tcpdump on it. This app is a tcpdump wrapper that will install tcpdump and enable you to start captures using a GUI. Tip: You will need to make sure you supply the right interface name for the capture and this varies from one device to another, eg -i eth0 or -i tiwlan0 - or use -i any to log all interfaces
For Android 4.0+ phones: Android PCAP from Kismet uses the USB OTG interface to support packet capture without requiring root. I haven't tried this app, and there are some restrictions on the type of devices supported (see their page)
For Android phones: tPacketCapture uses the Android VPN service to intercept packets and capture them. I have used this app successfully, but it also seems to affect the performance with large traffic volumes (eg video streaming)
For IOS 5+ devices, any network: iOS 5 added a remote virtual interface (RVI) facility that lets you use Mac OS X packet trace programs to capture traces from an iOS device. See here for more details
For all phones, wi-fi only: Set up your Mac or PC as a wireless access point, then run wireshark on the computer.
For all phones, wi-fi only: Get a capture device that can sniff wi-fi. This has the advantage of giving you 802.11x headers as well, but you may miss some of the packets
Capture using a VPN server: Its fairly easy to set-up your own VPN server using OpenVPN. You can then route your traffic through your server by setting up the mobile device as a VPN client and capture the traffic on the server end.
In addition to rupello's excellent answer, a "dirty" but very effective trick:
For all phones, any (local) network: Set up your PC to Man-In-The-Middle your mobile device.
Use Ettercap to do ARP spoofing between your mobile device and your router, and all your mobile's traffic will appear in Wireshark. See this tutorial for set-up details
Another option which has not been suggested here is to run the app you want to monitor in the Android emulator from the Android SDK. You can then easily capture the traffic with wireshark on the same machine.
This was the easiest option for me.
Wireshark + OSX + iOS:
Great overview so far, but if you want specifics for Wireshark + OSX + iOS:
install Wireshark on your computer
connect iOS device to computer via USB cable
connect iOS device and computer to the same WiFi network
run this command in a OSX terminal window: rvictl -s x where x is the UDID of your iOS device. You can find the UDID of your iOS device via iTunes (make sure you are using the UDID and not the serial number).
goto Wireshark Capture->Options, a dialog box appears, click on the line rvi0 then press the Start button.
Now you will see all network traffic on the iOS device. It can be pretty overwhelming. A couple of pointers:
don't use iOS with a VPN, you don't be able to make sense of the encrypted traffic
use simple filters to focus on interesting traffic
ip.addr==204.144.14.134 views traffic with a source or destination address of 204.144.14.134
http views only http traffic
Here's a sample window depicting TCP traffic for for pdf download from 204.144.14.134:
For Android phone I used tPacketCapture:
https://play.google.com/store/apps/details?id=jp.co.taosoftware.android.packetcapture&hl=en
This app was a lifesaver I was debugging a problem with failure of SSL/TLS handshake on my Android app. Tried to setup ad hoc networking so I could use wireshark on my laptop. It did not work for me. This app quickly allowed me to capture network traffic, share it on my Google Drive so I could download on my laptop where I could examine it with Wireshark! Awesome and no root required!
Packet Capture Android app implements a VPN that logs all network traffic on the Android device. You don't need to setup any VPN/proxy server on your PC. Does not needs root. Supports SSL decryption which tPacketCapture does not. It also includes a good log viewer.
Preconditions: adb and wireshark is installed on your computer and you have a rooted android device.
Download tcpdump to ~/Downloads
adb push ~/Downloads/tcpdump /sdcard/
adb shell
su root
mv /sdcard/tcpdump /data/local/
cd /data/local/
chmod +x tcpdump
./tcpdump -vv -i any -s 0 -w /sdcard/dump.pcap
CTRL+C after you've captured enough packets.
exit
exit
adb pull /sdcard/dump.pcap ~/Downloads/
Now you can open the pcap file using Wireshark.
Install Fiddler on your PC and use it as a proxy on your Android device.
Source: http://www.cantoni.org/2013/11/06/capture-android-web-traffic-fiddler
Similarly to making your PC a wireless access point, but can be much easier, is using reverse tethering. If you happen to have an HTC phone they have a nice reverse-tethering option called "Internet pass-through", under the network/mobile network sharing settings. It routes all your traffic through your PC and you can just run Wireshark there.
Make your laptop a wifi hotspot for your phone (any) and connect it to internet. Sniff Traffic on your wifi interface using wireshark.
you will get to know a lot of anti privacy stuff!
As a Wireshark alternative/companion for Android, you can try my open source app PCAPdroid. On non-rooted devices, it uses the VPNService to capture the traffic with some limitations. On rooted devices, it works like a user-friendly tcpdump.
You can analyze connections and packets payload directly into the app, or export the traffic in PCAP format to analyze it on a PC with Wireshark. It has many other cool features, give it a try!
For Android, I previously used tPacketCapture but it didn't work well for an app streaming some video. I'm now using Shark. You need to be root to use it though.
It uses TCPDump (check the arguments you can pass) and creates a pcap file that can be read by Wireshark. The default arguments are usually good enough for me.
I had a similar problem that inspired me to develop an app that could help to capture traffic from an Android device. The app features SSH server that allows you to have traffic in Wireshark on the fly (sshdump wireshark component). As the app uses an OS feature called VPNService to capture traffic, it does not require the root access.
The app is in early Beta. If you have any issues/suggestions, do not hesitate to let me know.
Download From Play
Tutorial in which you could read additional details
For iOS Devices:
⦿ Open Terminal and simply write:
rvictl -s udid
it'll open an interface on Wireshark with a name, In my case its rvi0.
udid is iPhone's unique device id.
(How to find my iOS Device UDID)