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 */ 16 17 #include <stdlib.h> 18 #include <ctype.h> 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) { 29 char *p = rawResult, *q = rawResult; 30 char tmp[255]; 31 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; 38 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; 45 46 // LEVEL 47 for (p = q; *q != '\t'; ++q); 48 strncpy(tmp, p, (q - p)); 49 tmp[q-p] = '\0'; 50 mLevel = atoi(tmp); 51 ++q; 52 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; 59 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++; 64 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; 74 75 return; 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 } 100