Use a BMessenger to check for wpa_supplicant availabiltiy.
* Only launch it on join requests if it isn't yet valid anyway. * Don't do any work on leave requests if it isn't running at all.
This commit is contained in:
@@ -1129,14 +1129,21 @@ NetServer::_JoinNetwork(const BMessage& message, const char* name)
|
|||||||
|
|
||||||
// Join via wpa_supplicant
|
// Join via wpa_supplicant
|
||||||
|
|
||||||
status_t status = be_roster->Launch(kWPASupplicantSignature);
|
BMessenger wpaSupplicant(kWPASupplicantSignature);
|
||||||
if (status != B_OK && status != B_ALREADY_RUNNING)
|
if (!wpaSupplicant.IsValid()) {
|
||||||
return status;
|
status_t status = be_roster->Launch(kWPASupplicantSignature);
|
||||||
|
if (status != B_OK && status != B_ALREADY_RUNNING)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
wpaSupplicant.SetTo(kWPASupplicantSignature);
|
||||||
|
if (!wpaSupplicant.IsValid())
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: listen to notifications from the supplicant!
|
// TODO: listen to notifications from the supplicant!
|
||||||
|
|
||||||
BMessage join(kMsgWPAJoinNetwork);
|
BMessage join(kMsgWPAJoinNetwork);
|
||||||
status = join.AddString("device", deviceName);
|
status_t status = join.AddString("device", deviceName);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = join.AddString("name", network.name);
|
status = join.AddString("name", network.name);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
@@ -1148,7 +1155,6 @@ NetServer::_JoinNetwork(const BMessage& message, const char* name)
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
BMessenger wpaSupplicant(kWPASupplicantSignature);
|
|
||||||
status = wpaSupplicant.SendMessage(&join);
|
status = wpaSupplicant.SendMessage(&join);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
@@ -1170,17 +1176,19 @@ NetServer::_LeaveNetwork(const BMessage& message)
|
|||||||
|
|
||||||
// We always try to send the leave request to the wpa_supplicant.
|
// We always try to send the leave request to the wpa_supplicant.
|
||||||
|
|
||||||
BMessage leave(kMsgWPALeaveNetwork);
|
|
||||||
status_t status = leave.AddString("device", deviceName);
|
|
||||||
if (status == B_OK)
|
|
||||||
status = leave.AddInt32("reason", reason);
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
BMessenger wpaSupplicant(kWPASupplicantSignature);
|
BMessenger wpaSupplicant(kWPASupplicantSignature);
|
||||||
status = wpaSupplicant.SendMessage(&leave);
|
if (wpaSupplicant.IsValid()) {
|
||||||
if (status == B_OK)
|
BMessage leave(kMsgWPALeaveNetwork);
|
||||||
return B_OK;
|
status_t status = leave.AddString("device", deviceName);
|
||||||
|
if (status == B_OK)
|
||||||
|
status = leave.AddInt32("reason", reason);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
status = wpaSupplicant.SendMessage(&leave);
|
||||||
|
if (status == B_OK)
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// The wpa_supplicant doesn't seem to be running, check if this was an open
|
// The wpa_supplicant doesn't seem to be running, check if this was an open
|
||||||
// network we connected ourselves.
|
// network we connected ourselves.
|
||||||
@@ -1191,7 +1199,7 @@ NetServer::_LeaveNetwork(const BMessage& message)
|
|||||||
if (device.GetNextAssociatedNetwork(cookie, network) != B_OK
|
if (device.GetNextAssociatedNetwork(cookie, network) != B_OK
|
||||||
|| network.authentication_mode != B_NETWORK_AUTHENTICATION_NONE) {
|
|| network.authentication_mode != B_NETWORK_AUTHENTICATION_NONE) {
|
||||||
// We didn't join ourselves, we can't do much.
|
// We didn't join ourselves, we can't do much.
|
||||||
return status;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We joined ourselves, so we can just disassociate again.
|
// We joined ourselves, so we can just disassociate again.
|
||||||
|
|||||||
Reference in New Issue
Block a user