San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 1 | /* |
| 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 Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 16 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 17 | #include <stdlib.h> |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 18 | #include <ctype.h> |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 19 | |
| 20 | #define LOG_TAG "ScanResult" |
| 21 | #include <cutils/log.h> |
| 22 | |
| 23 | #include "ScanResult.h" |
| 24 | |
| 25 | ScanResult::ScanResult() { |
| 26 | } |
| 27 | |
| 28 | ScanResult::ScanResult(char *rawResult) { |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 29 | char *p = rawResult, *q = rawResult; |
| 30 | char tmp[255]; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 31 | |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 32 | // 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 Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 38 | |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 39 | // 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 Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 45 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 46 | // LEVEL |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 47 | for (p = q; *q != '\t'; ++q); |
| 48 | strncpy(tmp, p, (q - p)); |
| 49 | tmp[q-p] = '\0'; |
| 50 | mLevel = atoi(tmp); |
| 51 | ++q; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 52 | |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 53 | // 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 Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 59 | |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 60 | // 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 Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 64 | |
San Mehat | 69772dc | 2009-05-10 09:27:07 -0700 | [diff] [blame] | 65 | 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 Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 74 | |
| 75 | return; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 76 | out_bad: |
| 77 | LOGW("Malformatted scan result (%s)", rawResult); |
| 78 | } |
| 79 | |
| 80 | ScanResult::~ScanResult() { |
| 81 | if (mBssid) |
| 82 | free(mBssid); |
| 83 | if (mFlags) |
| 84 | free(mFlags); |
| 85 | if (mSsid) |
| 86 | free(mSsid); |
| 87 | } |
| 88 | |
| 89 | ScanResult *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 | } |