blob: 87f6c98dcedaa8b11223bd28150ea0f5bf0d035c [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
20#define LOG_TAG "SupplicantState"
21#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"))) {
55 char *token = strsep(&next, "=");
56 char *value = strsep(&next, "=");
57
58 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);
64 else if (!strcmp(token, "wpa_state"))
65 state = atoi(value);
66 else
67 LOGD("Ignoring unsupported status token '%s'", token);
68 }
69
70 return new SupplicantStatus(state, id, bssid, ssid);
71
72}