blob: b3c560a81686fa9313736ebf6eac4b438885d76d [file] [log] [blame]
San Mehat3aff2d12009-06-15 14:10:44 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdlib.h>
18#include <string.h>
19
San Mehatd0290ea2009-06-16 12:01:50 -070020#define LOG_TAG "SupplicantStatus"
San Mehat3aff2d12009-06-15 14:10:44 -070021#include <cutils/log.h>
22
23#include "SupplicantStatus.h"
24#include "SupplicantState.h"
25
26SupplicantStatus::SupplicantStatus() {
27 mWpaState = SupplicantState::UNKNOWN;
28 mId = -1;
29 mBssid = NULL;
30 mSsid = NULL;
31}
32
33SupplicantStatus::SupplicantStatus(int state, int id, char *bssid, char *ssid) :
34 mWpaState(state), mId(id), mBssid(bssid), mSsid(ssid) {
35
36LOGD("state %d, id %d, bssid %p, ssid %p\n", mWpaState, mId, mBssid, mSsid);
37}
38
39SupplicantStatus::~SupplicantStatus() {
40 if (mBssid)
41 free(mBssid);
42 if (mSsid)
43 free(mSsid);
44}
45
46SupplicantStatus *SupplicantStatus::createStatus(char *data, int len) {
47 char *bssid = NULL;
48 char *ssid = NULL;
49 int id = -1;
50 int state = SupplicantState::UNKNOWN;
51
52 char *next = data;
53 char *line;
54 while((line = strsep(&next, "\n"))) {
San Mehatd0290ea2009-06-16 12:01:50 -070055 char *line_next = line;
56 char *token = strsep(&line_next, "=");
57 char *value = strsep(&line_next, "=");
San Mehat3aff2d12009-06-15 14:10:44 -070058 if (!strcmp(token, "bssid"))
59 bssid = strdup(value);
60 else if (!strcmp(token, "ssid"))
61 ssid = strdup(value);
62 else if (!strcmp(token, "id"))
63 id = atoi(value);
San Mehatd0290ea2009-06-16 12:01:50 -070064 else if (!strcmp(token, "wpa_state")) {
65 if (!strcmp(value, "DISCONNECTED"))
66 state = SupplicantState::DISCONNECTED;
67 else if (!strcmp(value, "INACTIVE"))
68 state = SupplicantState::INACTIVE;
69 else if (!strcmp(value, "SCANNING"))
70 state = SupplicantState::SCANNING;
71 else if (!strcmp(value, "ASSOCIATING"))
72 state = SupplicantState::ASSOCIATING;
73 else if (!strcmp(value, "ASSOCIATED"))
74 state = SupplicantState::ASSOCIATED;
75 else if (!strcmp(value, "FOURWAY_HANDSHAKE"))
76 state = SupplicantState::FOURWAY_HANDSHAKE;
77 else if (!strcmp(value, "GROUP_HANDSHAKE"))
78 state = SupplicantState::GROUP_HANDSHAKE;
79 else if (!strcmp(value, "COMPLETED"))
80 state = SupplicantState::COMPLETED;
81 else if (!strcmp(value, "IDLE"))
82 state = SupplicantState::IDLE;
83 else
84 LOGE("Unknown supplicant state '%s'", value);
85 } else
San Mehat3aff2d12009-06-15 14:10:44 -070086 LOGD("Ignoring unsupported status token '%s'", token);
87 }
88
89 return new SupplicantStatus(state, id, bssid, ssid);
90
91}