bool NetlinkManager::SendMessageAndGetSingleResponse(
const NL80211Packet& packet,
unique_ptr<const NL80211Packet>* response) {
+ unique_ptr<const NL80211Packet> response_or_error;
+ if (!SendMessageAndGetSingleResponseOrError(packet, &response_or_error)) {
+ return false;
+ }
+ if (response_or_error->GetMessageType() == NLMSG_ERROR) {
+ // We use ERROR because we are not expecting to receive a ACK here.
+ // In that case the caller should use |SendMessageAndGetAckOrError|.
+ LOG(ERROR) << "Received error message: "
+ << strerror(response_or_error->GetErrorCode());
+ return false;
+ }
+ *response = std::move(response_or_error);
+ return true;
+}
+
+bool NetlinkManager::SendMessageAndGetSingleResponseOrError(
+ const NL80211Packet& packet,
+ unique_ptr<const NL80211Packet>* response) {
vector<unique_ptr<const NL80211Packet>> response_vec;
if (!SendMessageAndGetResponses(packet, &response_vec)) {
return false;
}
if (response_vec.size() != 1) {
- LOG(ERROR) << "Unexpected repsonse size: " << response_vec.size();
+ LOG(ERROR) << "Unexpected response size: " << response_vec.size();
return false;
}
bool NetlinkManager::SendMessageAndGetAckOrError(const NL80211Packet& packet,
int* error_code) {
unique_ptr<const NL80211Packet> response;
- if (!SendMessageAndGetSingleResponse(packet, &response)) {
+ if (!SendMessageAndGetSingleResponseOrError(packet, &response)) {
return false;
}
uint16_t type = response->GetMessageType();
LOG(ERROR) << "Failed to get NL80211 family info";
return false;
}
- if (response->GetMessageType() == NLMSG_ERROR) {
- LOG(ERROR) << "Receive ERROR message: "
- << strerror(response->GetErrorCode());
- return false;
- }
OnNewFamily(std::move(response));
if (message_types_.find(NL80211_GENL_NAME) == message_types_.end()) {
LOG(ERROR) << "Failed to get NL80211 family id";
// Wrapper of |SendMessageAndGetResponses| for messages with a single
// response.
// Returns true on successfully receiving an valid reply.
+ // This will returns false if a NLMSG_ERROR is received.
// Reply packet will be stored in |*response|.
virtual bool SendMessageAndGetSingleResponse(
const NL80211Packet& packet,
std::unique_ptr<const NL80211Packet>* response);
+
+ // Wrapper of |SendMessageAndGetResponses| for messages with a single
+ // response.
+ // Returns true on successfully receiving an valid reply.
+ // This will returns true if a NLMSG_ERROR is received.
+ // This is useful when the caller needs the error code from kernel.
+ // Reply packet will be stored in |*response|.
+ virtual bool SendMessageAndGetSingleResponseOrError(
+ const NL80211Packet& packet,
+ std::unique_ptr<const NL80211Packet>* response);
+
// Wrapper of |SendMessageAndGetResponses| for messages that trigger
// only a NLMSG_ERROR response
// Returns true if the message is successfully sent and a NLMSG_ERROR response
LOG(ERROR) << "Failed to get scan capabilities";
return false;
}
- if (response->GetMessageType() == NLMSG_ERROR) {
- LOG(ERROR) << "Receive ERROR message: "
- << strerror(response->GetErrorCode())
- << "in response to a GetWiphy request";
- return false;
- }
if (response->GetCommand() != NL80211_CMD_NEW_WIPHY) {
LOG(ERROR) << "Wrong command in response to a get wiphy request: "
<< static_cast<int>(response->GetCommand());
LOG(ERROR) << "Failed to get packet counters";
return false;
}
- if (response->GetMessageType() == NLMSG_ERROR) {
- LOG(ERROR) << "Receive ERROR message: "
- << strerror(response->GetErrorCode())
- << "in response to a get station request";
- return false;
- }
-
if (response->GetCommand() != NL80211_CMD_NEW_STATION) {
LOG(ERROR) << "Wrong command in response to a get station request: "
<< static_cast<int>(response->GetCommand());