How to p2p_connect to device with WiFi Direct without MAC Address? (Raspberry Pi and Android) - linux

I have an Android tablet and A Raspberry Pi and I want to established a connection between them automatically when the tablet sends a request to the Pi.
I followed an Android application example here and start discovering any nearby devices. (https://www.youtube.com/watch?v=qnY97iBxp30)
At the same time i run sudo wpa_cli and p2p_find 20. The Android application detects the Pi, and I try to establish connection with the Pi which will display
<3>P2P-GO-NEG-REQUEST TABLET_MAC_ADDRESS dev_passwd_id=4
Normally I would just p2p_connect TABLET_MAC_ADDRESS pbc to successfully connect them together but I find it inefficient if I were to swap to another mobile device.
Are there any other ways to connect the tablet without writing the tablet mac address? For example connecting to that specific device ssid when they send a P2P-GO-NEG-REQUEST to the pi?

TL;DR Nope.
If we look at the OSI ISO 7 layer model for network communication we can see that the Media Access Control (MAC) address is vital for identifying which device is which within a wifi network.
You could try setting up a bluetooth connection or a token-ring, but I suspect that would be more effort than you are looking for.
With IPv6 your devices could use neighbour discovery to automate past the MAC entry to the Internet Protocol, and its possible to connect between devices using their link-local address (fe80::some:thing)
Wifi carries packets of data, that have addresses. By analogy, if I tell you which town I live in, but don't write my building address on the packet, you are going to have a hard time delivering it.

Related

Can a USB 3 Host machine be programmed as a USB 3 Peripheral (or a HID keyboard)?

What I want to do:
An AI program on a host machine, reading inputs from a camera sensing the screen of the target machine and outputting controls to the target machine via USB connection--programming the host machine's USB host as a USB peripheral connected to the target machine.
What I want to do step by step: (is it possible to implement the steps below?)
Have a host machine A and a target machine B.
Connect A and B with a USB 3.0 Type-A male-male cable.
The USB connection shows up as an HID keyboard device on B.
Write code to simulate key presses on A that sends to B.
(Eg. calling press('F') on a program running on A would type F to B's input)
It shouldn't require any program installed on B.
What I already searched:
USB 3.0 Host to host connection is possible:
https://superuser.com/questions/795053/how-do-i-connect-two-computers-using-usb-3-0
USB 2.0 Host to host connection is impossible:
https://superuser.com/questions/99274/how-to-connect-two-computers-with-usb
Similar questions asked without the assumption that USB 3.0 Host to Host connection is possible:
https://superuser.com/questions/1128365/simulate-usb-keyboard-from-machine
Setting up a computer to act as an HID device connected to another computer via ps/2,usb or another wired connection
https://superuser.com/questions/507921/computer-to-act-as-keyboard?rq=1
Suggestions in ascending order of feasibility:
USB Gadgets
You are using linux, so the default way would be to create/configure/load a gadget driver. Have a look at this tutorial, though for a raspberry, should work on your PC too. However, I could not find any information regarding the use of USB3 - the tutorial assumes your host is using one of it's OTG ports, which your PC most likely does not have. So whether this works with your USB3.1 Type-A-to-Type-A connection you'll need to test.
USBIP
The idea of sharing USB devices (not just keyboards) is not really new. With USBIP you can "export" any local USB device to the network, and your client will need the client-side USBIP driver to access the keyboard.
Dont bother with USB at all, just use Ethernet
I'd simply write two userland scripts/programs that send/receive+execute the keystrokes. Very easy to implement, you're probably familiar with python anyway.
If you absolutely cant have software installed on the client-PC and your Type-C-to-Type-C connection doesnt support USB Gadgets, there's another way. It basically involves the use of two USB-to-serial adapters (~15$) and a serial cable. While this wont be enumerated as a keyboard, but rather as serial port, it's the lowest-effort solution to transfer data without additional software on the client. Both computers will just do file I/O. If your computers still have COM-ports, you can even omit the serial converters!

How to allow only 1 connection to BlueZ GATT server at any given moment?

I'm working on Bluetooth on the embedded Linux. I'm using BlueZ and D-Bus. I have a server taken from the example https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-gatt-server.
I have the app such as nRF installed in 2 iPhones. I'm able to connect to my Linux Bluetooth server at the same time. I'm able to modify the characteristic from either of the iPhone app. But this is a problem because we don't want it. We'd like to have only 1 phone connected to the Linux device. That way, the same characteristic won't be modified by more than 1 phone app at the same time.
Is there a way to allow only 1 connection to the Linux Bluetooth GATT server at any given time?
Thanks.
Yes, the way to do this is to disable/stop advertisements on your Linux device as soon as a connection is established. This way, upon a connection, your Linux device will no longer be advertising and remote devices will no longer be able to connect to it.

Use a Linux Computer as a USB Coupler

I am on debian and:
I have a USB controller hooked up to a USB port on my PC (Device 1).
I have a male to male USB cord hooked up to another port on the PC that connects to Device 2. (it is a "bridging" usb cord, and has the chip for it)
I want to make them connect to each other as if they were one cord, so neither device knows that there is a computer in the middle.
This would be called a 'Coupler', except that I am using a PC as a coupler.
Here is a (really bad) diagram I made:
What I have done:
I have been able to connect the two devices independently of each other and sniff the results for when they fail to connect. The devices don't send a large volume of data back and forth.
Maybe there is some kind of command tool that I could use, for example (psudocode):
$ couple-usb-ports PORT1 PORT2
You're trying to reinvent the wheel here.
You might consider looking at this link instead.
http://dan3lmi.blogspot.com/2012/10/sniffing-usb-traffic-different.html
Specifically this.
Windows: You cannot directly capture raw USB traffic on Windows with Wireshark/WinPcap, but it is possible to capture and debug USB traffic on a virtual Windows machine under Oracle Virtual Box.
You cannot use a simple PC as transparent USB sniffer without extra (expensive) hardware. An USB bus has always one host (and one or more devices), and the PC can only be the host. This is a hardware limitation.
But you can capture USB data in a Windows machine using Wireshark and USBPcap, eliminating the need for the middle box in most cases.
As this post is tagged Linux, I suppose the controller PC is a Linux machine. Instead of connecting USB ports with a male-male connector, which is all kinds of bad (you are connecting the 5V lines of both machine with each other!), just run Wireshark in the controller PC.
There might be a little work to be done previously, as you have to enable Wireshark for USB monitoring (Particularly in Debian, this is disabled by default), and you might have to install a small driver to enable the monitoring. Have a look at this page for more information.
Once you get it working, Wireshark is an excellent tool for this!

Passing on IP camera through raspberry pi

I've been having problems with a project of mine. I had a raspberry pi connected to webcams but I found that this was too much load for the RPI. This is why I decided to purchase and use an IP camera. The only problem though, is that the IP camera does not get wifi reception where the it should be placed but I have a powerful Directional antenna which I can attach to the RPI. I want the RPI to route internet traffic from the camera plugged into ethernet, over the wifi. I'm not one hundred percent sure how to do this but so far I have giving the wifi priority over the Ethernet and set up a dhcp server so that the camera gets an ip address.
In my current setup, when I am hard-wired into the Raspberry pi, I can connect to the camera (on 192.168.2.10) but outside, I can only connect to the web server which is also running on on the RPI. I'm not sure if the port forwarding of the camera works but I want to be able to access the webserver on 192.168.1.117 (this works) and I want to see the camera on 192.168.1.117:10 (this does not work). To try to do this, I followed this tutorial but I cant seem to get any results after finishing it.
Any help is greatly appreciated! thanks.
You may want to try UV4L with the mjpegstream driver. It turns your IP camera into a (virtual) Video device available on your RPi. An example is here (in step 3 pass the URL of your IP camera stream).

Is it right to send data in J2ME through cable by mean of DatagramConnection?

I want to send data by using J2ME between a mobile phone and a computer. The two machines are connected by the phone's cable : there is no Wi-Fi , no http connection , no Internet. So is it wrong or correct to use the J2ME DatagramConnection to send data to the computer when the mobile's cable is inserted to the USB port of the computer ?
When you talk about interaction between two systems, first you will need to address the connectivity. In the situation described, the connectivity between the phones is via USB, which is a serial port. So the communication can be done over serial port only.
Datagram can be used over IP networks and other specialized networks.
If for some reason you are unable to communicate via USB, check if you could connect both of them using Bluetooth. If your phone has Bluetooth and the computer doesn't, then you could purchase an USB Bluetooth Dongle for very cheap.
If you are trying to get logs of your application, you can check out Bluetooth loggers for J2ME. There are quite a lot of them. One such library is microlog
Hope this helps.
It depends, if you require high speed of data transfer while can bear some data loss then DatagramConnection is ok, and if you can't bear loss of data packets, then you should use TCPConnection.

Resources