blob: e9a286c3d00297288af719e22c02dcb761303d22 [file] [log] [blame]
San Mehatdc266072009-05-06 11:16:52 -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 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehatdc266072009-05-06 11:16:52 -070017#include <stdlib.h>
San Mehat69772dc2009-05-10 09:27:07 -070018#include <ctype.h>
San Mehatdc266072009-05-06 11:16:52 -070019
20#define LOG_TAG "ScanResult"
21#include <cutils/log.h>
22
23#include "ScanResult.h"
24
25ScanResult::ScanResult() {
26}
27
28ScanResult::ScanResult(char *rawResult) {
San Mehat69772dc2009-05-10 09:27:07 -070029 char *p = rawResult, *q = rawResult;
30 char tmp[255];
San Mehatdc266072009-05-06 11:16:52 -070031
San Mehat69772dc2009-05-10 09:27:07 -070032 // BSSID
33 for (q = p; *q != '\t'; ++q);
34 strncpy(tmp, p, (q - p));
35 tmp[q-p] = '\0';
36 mBssid = strdup(tmp);
37 ++q;
San Mehatdc266072009-05-06 11:16:52 -070038
San Mehat69772dc2009-05-10 09:27:07 -070039 // FREQ
40 for (p = q; *q != '\t'; ++q);
41 strncpy(tmp, p, (q - p));
42 tmp[q-p] = '\0';
43 mFreq = atoi(tmp);
44 ++q;
San Mehatdc266072009-05-06 11:16:52 -070045
San Mehat3c5a6f02009-05-22 15:36:13 -070046 // LEVEL
San Mehat69772dc2009-05-10 09:27:07 -070047 for (p = q; *q != '\t'; ++q);
48 strncpy(tmp, p, (q - p));
49 tmp[q-p] = '\0';
50 mLevel = atoi(tmp);
51 ++q;
San Mehatdc266072009-05-06 11:16:52 -070052
San Mehat69772dc2009-05-10 09:27:07 -070053 // FLAGS
54 for (p = q; *q != '\t'; ++q);
55 strncpy(tmp, p, (q - p));
56 tmp[q-p] = '\0';
57 mFlags = strdup(tmp);
58 ++q;
San Mehatdc266072009-05-06 11:16:52 -070059
San Mehat69772dc2009-05-10 09:27:07 -070060 // XXX: For some reason Supplicant sometimes sends a double-tab here.
61 // haven't had time to dig into it ...
62 if (*q == '\t')
63 q++;
San Mehat3c5a6f02009-05-22 15:36:13 -070064
San Mehat69772dc2009-05-10 09:27:07 -070065 for (p = q; *q != '\t'; ++q) {
66 if (*q == '\0')
67 break;
68 }
69
70 strncpy(tmp, p, (q - p));
71 tmp[q-p] = '\0';
72 mSsid = strdup(tmp);
73 ++q;
San Mehatdc266072009-05-06 11:16:52 -070074
75 return;
San Mehatdc266072009-05-06 11:16:52 -070076 out_bad:
77 LOGW("Malformatted scan result (%s)", rawResult);
78}
79
80ScanResult::~ScanResult() {
81 if (mBssid)
82 free(mBssid);
83 if (mFlags)
84 free(mFlags);
85 if (mSsid)
86 free(mSsid);
87}
88
89ScanResult *ScanResult::clone() {
90 ScanResult *r = new ScanResult();
91
92 r->mBssid = strdup(mBssid);
93 r->mFreq = mFreq;
94 r->mLevel = mLevel;
95 r->mFlags = strdup(mFlags);
96 r->mSsid = strdup(mSsid);
97
98 return r;
99}