Patchwork [14/23] P2P: deduce if a device is indoor based on the device category

login
register
mail settings
Submitter Ilan Peer
Date July 7, 2014, 11:21 a.m.
Message ID <1404732076-32252-15-git-send-email-ilan.peer@intel.com>
Download mbox | patch
Permalink /patch/367517/
State New
Headers show

Comments

Ilan Peer - July 7, 2014, 11:21 a.m.
Use the WPS category ID in the P2P Device IE to determine if the
peer device is an indoor device, e.g., media center, server etc.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
---
 src/p2p/p2p.h       |    9 +++++++
 src/p2p/p2p_utils.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)

Patch

diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index 0651358..6f35e24 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -2008,4 +2008,13 @@  int p2p_group_get_common_freqs(struct p2p_group *group,
 			       int *common_freqs,
 			       unsigned int *num);
 
+/**
+ * p2p_is_indoor_device - Deduce if the peer device is an indoor device or not
+ * based on the WPS primary and secondary device types.
+ *
+ * @peer: pointer to the peer device
+ * Returns 1 if indoor device, 0 if not.
+ */
+unsigned int p2p_is_indoor_device(struct p2p_peer_info *peer);
+
 #endif /* P2P_H */
diff --git a/src/p2p/p2p_utils.c b/src/p2p/p2p_utils.c
index b441ca1..06fe385 100644
--- a/src/p2p/p2p_utils.c
+++ b/src/p2p/p2p_utils.c
@@ -10,6 +10,7 @@ 
 
 #include "common.h"
 #include "p2p_i.h"
+#include "wps/wps_defs.h"
 #include "common/defs.h"
 #include "common/ieee802_11_common.h"
 
@@ -456,3 +457,69 @@  int p2p_channels_to_freqs(const struct p2p_channels *channels,
 	}
 	return idx;
 }
+
+
+unsigned int p2p_is_indoor_device(struct p2p_peer_info *peer)
+{
+	int cat, sub;
+	if (!peer)
+		return 0;
+
+	cat = WPA_GET_BE16(peer->pri_dev_type);
+	sub = WPA_GET_BE16(&peer->pri_dev_type[6]);
+
+	switch (cat) {
+	case WPS_DEV_COMPUTER:
+		switch (sub) {
+		case WPS_DEV_COMPUTER_SERVER:
+		case WPS_DEV_COMPUTER_MEDIA_CENTER:
+		case WPS_DEV_COMPUTER_DESKTOP:
+			return 1;
+		case WPS_DEV_COMPUTER_PC:
+		case WPS_DEV_COMPUTER_ULTRA_MOBILE:
+		case WPS_DEV_COMPUTER_NOTEBOOK:
+		case WPS_DEV_COMPUTER_MID:
+		default:
+			return 0;
+		}
+		break;
+	case WPS_DEV_MULTIMEDIA:
+		switch (sub) {
+		case WPS_DEV_MULTIMEDIA_DAR:
+		case WPS_DEV_MULTIMEDIA_PVR:
+		case WPS_DEV_MULTIMEDIA_MCX:
+		case WPS_DEV_MULTIMEDIA_SET_TOP_BOX:
+		case WPS_DEV_MULTIMEDIA_MEDIA_SERVER:
+			return 1;
+		case WPS_DEV_MULTIMEDIA_PORTABLE_VIDEO_PLAYER:
+		default:
+			return 0;
+		}
+		break;
+	case WPS_DEV_GAMING:
+		switch (sub) {
+		case WPS_DEV_GAMING_XBOX:
+		case WPS_DEV_GAMING_XBOX360:
+		case WPS_DEV_GAMING_PLAYSTATION:
+		case WPS_DEV_GAMING_GAME_CONSOLE:
+			return 1;
+		case WPS_DEV_GAMING_PORTABLE_DEVICE:
+		default:
+			return 0;
+		}
+		break;
+	case WPS_DEV_PRINTER:
+	case WPS_DEV_DISPLAY:
+	case WPS_DEV_NETWORK_INFRA:
+	case WPS_DEV_STORAGE:
+		return 1;
+	case WPS_DEV_INPUT:
+	case WPS_DEV_CAMERA:
+	case WPS_DEV_PHONE:
+	case WPS_DEV_AUDIO:
+	default:
+		return 0;
+	}
+
+	return 0;
+}