Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wi-Fi Direct and "normal" Wi-Fi - Different MAC?

I'm currently trying to connect two phones which know each other's MAC address via Wi-Fi Direct, and stumbled upon the following problem: The MAC address, which I receive from

    WifiManager wifiMan = (WifiManager) this
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInf = wifiMan.getConnectionInfo();
    MAC_ADDRESS = wifiInf.getMacAddress();

is slightly different than the one I receive from the WifiP2pManager when discovering and requesting peers. Example: a0:xx:xx:... turns into a2:xx:xx.... Does anyone know why? I did not find any way to get the "Wi-Fi Direct MAC address", and as I thought the MAC address should be unique, and it's the same Wi-Fi module that handles both (normal Wi-Fi and P2P/Direct). This is very weird.. What should I do? For the two devices (Galaxy Nexus) I've got, it's always only the first two characters that differ in the MAC addresses - should I simply discard them? Is the probability to encounter problems (two devices which only differ in the first part of MAC address) too high?

Thanks.

like image 437
damian Avatar asked Jun 10 '12 13:06

damian


People also ask

What is the difference between Wi-Fi and Wi-Fi Direct?

Wi-Fi Direct is single-hop communication, rather than multihop communication like wireless ad hoc networks. Wi-Fi becomes a way of communicating wirelessly, much like Bluetooth.

Can I use Wi-Fi Direct on MAC?

Wi-Fi Direct not only supports Android devices running 4.0 or higher operating system but also supports your Mac devices as well.

Is Wi-Fi Direct faster than Wi-Fi?

Wi-Fi Direct devices will operate at the same speeds or data rates and range as current Wi-Fi gear.

How do I connect my MAC to a Wi-Fi Direct printer?

Choose Apple menu > System Preferences, then click Printers & Scanners. Select your printer in the list. If the printer isn't listed, click the Add button , select your printer, then click Add.


2 Answers

Reading about the MAC address on wikipedia.

Addresses can either be universally administered addresses or locally administered addresses.

Universally administered and locally administered addresses are distinguished by setting the second-least-significant bit of the most significant byte of the address. This bit is also referred to as the U/L bit, short for Universal/Local, which identifies how the address is administered. If the bit is 0, the address is universally administered. If it is 1, the address is locally administered.

MAC 48 Address

Since Wi-Fi Direct is just another stack on top of MAC, you should also check what that bit can mean for it. I've found some mail discussion shedding some light on this. Apparently quote below is from a WFA spec.

The P2P Device shall assign a P2P Interface Address, corresponding to the format as described in §7.1.3.3.1 of IEEE Std 802.11‑2007 1, which is used to communicate with the P2P Group Owner or Clients within a P2P Group. A P2P Interface Address is not required to be globally unique and may be locally administered. A P2P Interface Address may be the same as the P2P Device Address provided the requirements for P2P Interface Address in this clause are satisfied.

So I believe answer to this question is, you shouldn't take MAC address from WifiManager and use it with Wi-Fi P2P connections.

like image 55
auselen Avatar answered Sep 21 '22 06:09

auselen


I had been searching for this during my project. My requirements were to uniquely identify devices in an adhoc P2p network formed with WiFi Direct. Each device should identify its friend device the next time when it comes into proximity. I needed my own WiFi (Direct) MAC and my friends' to create a Key for this friend zone creation.

My Research: The design is in such a way that there is an Unique Universal ID and a Local ID. Reason: Universal ID can only be used to connect to Infrastructure mode Networks. Local ID could be used for "ad-hoc" mode networks(device to device). In this ad-hoc mode, there are possibilities that a single device might simultaneosly belong to several ad-hoc groups.

  1. Hence to support this concurrent operations, P2p devices support Multiple MAC entities, possibly on different channels.
  2. For each session, a persistent group MAY use a different channel and device MAC for each session.
  3. P2P devices use their global MAC address as Device ID during discovery and negotiation, and a temporary local MAC address for all frames within a group. Understood from here

However, there is NO straight forward way to obtain one's own WiFi P2p MAC address. Issue 53437: Android.

In this issue discussion, the project member from google has suggested this is possible and just that it hasn't been documented

Solution: Using intent filter WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION and the extra from the intent WifiP2pManager.EXTRA_WIFI_P2P_DEVICE

This is how I have used it in my project:

@Override
public void onReceive(Context context, Intent intent) {
....
....
String action = intent.getAction();

if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
            .equals(action)) {

        WifiP2pDevice device = (WifiP2pDevice) intent
                .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);

        String myMac = device.deviceAddress;

        Log.d(TAG, "Device WiFi P2p MAC Address: " + myMac);

/* Saving WiFi P2p MAC in SharedPref */

        sharedPref = context.getSharedPreferences(context.getString(R.string.sp_file_name), Context.MODE_PRIVATE);
        String MY_MAC_ADDRESS = sharedPref.getString(context.getString(R.string.sp_field_my_mac), null);

        if (MY_MAC_ADDRESS == null || MY_MAC_ADDRESS != myMac) {
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString(context.getString(R.string.sp_field_my_mac), myMac);
            editor.commit();
        }

Hope this helps someone!

like image 33
Hariharan Gandhi Avatar answered Sep 23 '22 06:09

Hariharan Gandhi