blob: dc7599afe63cf40c139da351e552d0ab173276b1 [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 */
16#include <stdlib.h>
San Mehat69772dc2009-05-10 09:27:07 -070017#include <ctype.h>
San Mehatdc266072009-05-06 11:16:52 -070018
19#define LOG_TAG "ScanResult"
20#include <cutils/log.h>
21
22#include "ScanResult.h"
23
24ScanResult::ScanResult() {
25}
26
27ScanResult::ScanResult(char *rawResult) {
San Mehat69772dc2009-05-10 09:27:07 -070028 char *p = rawResult, *q = rawResult;
29 char tmp[255];
San Mehatdc266072009-05-06 11:16:52 -070030
San Mehat69772dc2009-05-10 09:27:07 -070031 // BSSID
32 for (q = p; *q != '\t'; ++q);
33 strncpy(tmp, p, (q - p));
34 tmp[q-p] = '\0';
35 mBssid = strdup(tmp);
36 ++q;
San Mehatdc266072009-05-06 11:16:52 -070037
San Mehat69772dc2009-05-10 09:27:07 -070038 // FREQ
39 for (p = q; *q != '\t'; ++q);
40 strncpy(tmp, p, (q - p));
41 tmp[q-p] = '\0';
42 mFreq = atoi(tmp);
43 ++q;
San Mehatdc266072009-05-06 11:16:52 -070044
San Mehat69772dc2009-05-10 09:27:07 -070045 // LEVEL
46 for (p = q; *q != '\t'; ++q);
47 strncpy(tmp, p, (q - p));
48 tmp[q-p] = '\0';
49 mLevel = atoi(tmp);
50 ++q;
San Mehatdc266072009-05-06 11:16:52 -070051
San Mehat69772dc2009-05-10 09:27:07 -070052 // FLAGS
53 for (p = q; *q != '\t'; ++q);
54 strncpy(tmp, p, (q - p));
55 tmp[q-p] = '\0';
56 mFlags = strdup(tmp);
57 ++q;
San Mehatdc266072009-05-06 11:16:52 -070058
San Mehat69772dc2009-05-10 09:27:07 -070059 // XXX: For some reason Supplicant sometimes sends a double-tab here.
60 // haven't had time to dig into it ...
61 if (*q == '\t')
62 q++;
63
64 for (p = q; *q != '\t'; ++q) {
65 if (*q == '\0')
66 break;
67 }
68
69 strncpy(tmp, p, (q - p));
70 tmp[q-p] = '\0';
71 mSsid = strdup(tmp);
72 ++q;
San Mehatdc266072009-05-06 11:16:52 -070073
74 return;
San Mehatdc266072009-05-06 11:16:52 -070075 out_bad:
76 LOGW("Malformatted scan result (%s)", rawResult);
77}
78
79ScanResult::~ScanResult() {
80 if (mBssid)
81 free(mBssid);
82 if (mFlags)
83 free(mFlags);
84 if (mSsid)
85 free(mSsid);
86}
87
88ScanResult *ScanResult::clone() {
89 ScanResult *r = new ScanResult();
90
91 r->mBssid = strdup(mBssid);
92 r->mFreq = mFreq;
93 r->mLevel = mLevel;
94 r->mFlags = strdup(mFlags);
95 r->mSsid = strdup(mSsid);
96
97 return r;
98}