San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -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 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | #define LOG_TAG "SupplicantAssociatingEvent" |
| 20 | #include <cutils/log.h> |
| 21 | |
| 22 | #include "SupplicantAssociatingEvent.h" |
| 23 | |
| 24 | SupplicantAssociatingEvent::SupplicantAssociatingEvent(int level, char *event, |
| 25 | size_t len) : |
| 26 | SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING, |
| 27 | level) { |
| 28 | char *p = event; |
| 29 | |
| 30 | mBssid = NULL; |
| 31 | mSsid = NULL; |
| 32 | |
| 33 | // SSID 'default' |
| 34 | // OR |
| 35 | // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)" |
| 36 | |
| 37 | if (strncmp(event, "SSID", 4)) { |
| 38 | mBssid = (char *) malloc(18); |
| 39 | strncpy(mBssid, p, 17); |
| 40 | mBssid[17] = '\0'; |
| 41 | p += 25; |
| 42 | |
| 43 | // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)" |
| 44 | // ^ |
| 45 | // p |
| 46 | char *q = index(p, '\''); |
| 47 | if (!q) { |
| 48 | LOGE("Unable to decode SSID (p = {%s})\n", p); |
| 49 | return; |
| 50 | } |
| 51 | mSsid = (char *) malloc((q - p) +1); |
| 52 | strncpy(mSsid, p, q-p); |
| 53 | mSsid[q-p] = '\0'; |
| 54 | |
| 55 | p = q + 7; |
| 56 | |
| 57 | // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)" |
| 58 | // ^ |
| 59 | // p |
| 60 | if (!(q = index(p, ' '))) { |
| 61 | LOGE("Unable to decode frequency\n"); |
| 62 | return; |
| 63 | } |
| 64 | *q = '\0'; |
| 65 | mFreq = atoi(p); |
| 66 | } else { |
| 67 | p+= 6; |
| 68 | |
| 69 | // SSID 'default' |
| 70 | // ^ |
| 71 | // p |
| 72 | |
| 73 | char *q = index(p, '\''); |
| 74 | if (!q) { |
| 75 | LOGE("Unable to decode SSID (p = {%s})\n", p); |
| 76 | return; |
| 77 | } |
| 78 | mSsid = (char *) malloc((q - p) +1); |
| 79 | strncpy(mSsid, p, q-p); |
| 80 | mSsid[q-p] = '\0'; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | SupplicantAssociatingEvent::SupplicantAssociatingEvent(const char *bssid, |
| 85 | const char *ssid, |
| 86 | int freq) : |
| 87 | SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING, -1) { |
| 88 | mBssid = strdup(bssid); |
| 89 | mSsid= strdup(ssid); |
| 90 | mFreq = freq; |
| 91 | } |
| 92 | |
| 93 | SupplicantAssociatingEvent::~SupplicantAssociatingEvent() { |
| 94 | if (mBssid) |
| 95 | free(mBssid); |
| 96 | if (mSsid) |
| 97 | free(mSsid); |
| 98 | } |
| 99 | |