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
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;
32    mFreq = -1;
33
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) {
49            LOGE("Unable to decode SSID (p = {%s})\n", p);
50            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, ' '))) {
62            LOGE("Unable to decode frequency\n");
63            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) {
76            LOGE("Unable to decode SSID (p = {%s})\n", p);
77            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
101