blob: 8fe502ee42e2549090fd2cf269b77c74d0017474 [file] [log] [blame]
San Mehat3aff2d12009-06-15 14:10:44 -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
17#include <stdlib.h>
18
19#define LOG_TAG "SupplicantAssociatingEvent"
20#include <cutils/log.h>
21
22#include "SupplicantAssociatingEvent.h"
23
24SupplicantAssociatingEvent::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;
San Mehatbbe92c32009-06-16 10:51:14 -070032 mFreq = -1;
San Mehat3aff2d12009-06-15 14:10:44 -070033
34 // SSID 'default'
35 // OR
36 // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)"
37
38 if (strncmp(event, "SSID", 4)) {
39 mBssid = (char *) malloc(18);
40 strncpy(mBssid, p, 17);
41 mBssid[17] = '\0';
42 p += 25;
43
44 // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)"
45 // ^
46 // p
47 char *q = index(p, '\'');
48 if (!q) {
Steve Block01dda202012-01-06 14:13:42 +000049 ALOGE("Unable to decode SSID (p = {%s})\n", p);
San Mehat3aff2d12009-06-15 14:10:44 -070050 return;
51 }
52 mSsid = (char *) malloc((q - p) +1);
53 strncpy(mSsid, p, q-p);
54 mSsid[q-p] = '\0';
55
56 p = q + 7;
57
58 // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)"
59 // ^
60 // p
61 if (!(q = index(p, ' '))) {
Steve Block01dda202012-01-06 14:13:42 +000062 ALOGE("Unable to decode frequency\n");
San Mehat3aff2d12009-06-15 14:10:44 -070063 return;
64 }
65 *q = '\0';
66 mFreq = atoi(p);
67 } else {
68 p+= 6;
69
70 // SSID 'default'
71 // ^
72 // p
73
74 char *q = index(p, '\'');
75 if (!q) {
Steve Block01dda202012-01-06 14:13:42 +000076 ALOGE("Unable to decode SSID (p = {%s})\n", p);
San Mehat3aff2d12009-06-15 14:10:44 -070077 return;
78 }
79 mSsid = (char *) malloc((q - p) +1);
80 strncpy(mSsid, p, q-p);
81 mSsid[q-p] = '\0';
82 }
83}
84
85SupplicantAssociatingEvent::SupplicantAssociatingEvent(const char *bssid,
86 const char *ssid,
87 int freq) :
88 SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING, -1) {
89 mBssid = strdup(bssid);
90 mSsid= strdup(ssid);
91 mFreq = freq;
92}
93
94SupplicantAssociatingEvent::~SupplicantAssociatingEvent() {
95 if (mBssid)
96 free(mBssid);
97 if (mSsid)
98 free(mSsid);
99}
100