Browse Source

wpa_gui: Add peer dialog option for WPS PBC

Use advertised configuration methods to determine whether WPS PBC
and/or PIN methods should be allowed.
Jouni Malinen 15 years ago
parent
commit
d6211fbb2e
2 changed files with 50 additions and 6 deletions
  1. 49 6
      wpa_supplicant/wpa_gui-qt4/peers.cpp
  2. 1 0
      wpa_supplicant/wpa_gui-qt4/peers.h

+ 49 - 6
wpa_supplicant/wpa_gui-qt4/peers.cpp

@@ -140,16 +140,32 @@ void Peers::context_menu(const QPoint &pos)
 		menu->addAction(Peers::ItemType(type))->setEnabled(false);
 		menu->addSeparator();
 
-		if (type == PEER_TYPE_ASSOCIATED_STATION ||
-		    type == PEER_TYPE_AP_WPS ||
-		    type == PEER_TYPE_WPS_PIN_NEEDED ||
-		    type == PEER_TYPE_WPS_ER_ENROLLEE) {
-			/* TODO: only for peers that are requesting WPS PIN
-			 * method */
+		int config_methods = -1;
+		QVariant var = ctx_item->data(peer_role_config_methods);
+		if (var.isValid())
+			config_methods = var.toInt();
+
+		if ((type == PEER_TYPE_ASSOCIATED_STATION ||
+		     type == PEER_TYPE_AP_WPS ||
+		     type == PEER_TYPE_WPS_PIN_NEEDED ||
+		     type == PEER_TYPE_WPS_ER_ENROLLEE) &&
+		    (config_methods == -1 || (config_methods & 0x010c))) {
 			menu->addAction(tr("Enter WPS PIN"), this,
 					SLOT(enter_pin()));
 		}
 
+		if (type == PEER_TYPE_AP_WPS) {
+			menu->addAction(tr("Connect (PBC)"), this,
+					SLOT(connect_pbc()));
+		}
+
+		if ((type == PEER_TYPE_ASSOCIATED_STATION ||
+		     type == PEER_TYPE_WPS_ER_ENROLLEE) &&
+		    config_methods >= 0 && (config_methods & 0x0080)) {
+			menu->addAction(tr("Enroll (PBC)"), this,
+					SLOT(connect_pbc()));
+		}
+
 		menu->addAction(tr("Properties"), this, SLOT(properties()));
 	} else {
 		ctx_item = NULL;
@@ -754,3 +770,30 @@ void Peers::properties()
 
 	msg.exec();
 }
+
+
+void Peers::connect_pbc()
+{
+	if (ctx_item == NULL)
+		return;
+
+	char cmd[100];
+	char reply[100];
+	size_t reply_len;
+
+	int peer_type = ctx_item->data(peer_role_type).toInt();
+	if (peer_type == PEER_TYPE_WPS_ER_ENROLLEE) {
+		snprintf(cmd, sizeof(cmd), "WPS_ER_PBC %s",
+			 ctx_item->data(peer_role_uuid).toString().toAscii().
+			 constData());
+	} else {
+		snprintf(cmd, sizeof(cmd), "WPS_PBC");
+	}
+	reply_len = sizeof(reply) - 1;
+	if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) {
+		QMessageBox msg;
+		msg.setIcon(QMessageBox::Warning);
+		msg.setText("Failed to start WPS PBC.");
+		msg.exec();
+	}
+}

+ 1 - 0
wpa_supplicant/wpa_gui-qt4/peers.h

@@ -36,6 +36,7 @@ public:
 public slots:
 	virtual void context_menu(const QPoint &pos);
 	virtual void enter_pin();
+	virtual void connect_pbc();
 	virtual void ctx_refresh();
 	virtual void properties();