blob: 5c0944a7fcd66e3369e3fc4fa826e84f0c104183 [file] [log] [blame]
San Mehatdc266072009-05-06 11:16:52 -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#include <stdlib.h>
17
18#define LOG_TAG "SupplicantEvent"
19#include <cutils/log.h>
20
21#include "SupplicantEvent.h"
22
23#include "libwpa_client/wpa_ctrl.h"
24
25SupplicantEvent::SupplicantEvent(char *event, size_t len) {
26
27 if (event[0] == '<') {
28 char *match = strchr(event, '>');
29 if (match) {
30 char tmp[16];
31
32 strncpy(tmp, &event[1], (match - event));
33 mLevel = atoi(tmp);
34 event += (match - event) + 1;
35 } else
36 LOGW("Unclosed level brace in event");
37 } else
38 LOGW("No level specified in event");
39
40 /*
41 * <N>CTRL-EVENT-XXX
42 * ^
43 * +---- event
44 */
45
46 if (!strncmp(event, WPA_EVENT_CONNECTED, strlen(WPA_EVENT_CONNECTED)))
47 mType = SupplicantEvent::EVENT_CONNECTED;
48 else if (!strncmp(event, WPA_EVENT_DISCONNECTED, strlen(WPA_EVENT_DISCONNECTED)))
49 mType = SupplicantEvent::EVENT_DISCONNECTED;
50 else if (!strncmp(event, WPA_EVENT_TERMINATING, strlen(WPA_EVENT_TERMINATING)))
51 mType = SupplicantEvent::EVENT_TERMINATING;
52 else if (!strncmp(event, WPA_EVENT_PASSWORD_CHANGED, strlen(WPA_EVENT_PASSWORD_CHANGED)))
53 mType = SupplicantEvent::EVENT_PASSWORD_CHANGED;
54 else if (!strncmp(event, WPA_EVENT_EAP_NOTIFICATION, strlen(WPA_EVENT_EAP_NOTIFICATION)))
55 mType = SupplicantEvent::EVENT_EAP_NOTIFICATION;
56 else if (!strncmp(event, WPA_EVENT_EAP_STARTED, strlen(WPA_EVENT_EAP_STARTED)))
57 mType = SupplicantEvent::EVENT_EAP_STARTED;
58 else if (!strncmp(event, WPA_EVENT_EAP_METHOD, strlen(WPA_EVENT_EAP_METHOD)))
59 mType = SupplicantEvent::EVENT_EAP_METHOD;
60 else if (!strncmp(event, WPA_EVENT_EAP_SUCCESS, strlen(WPA_EVENT_EAP_SUCCESS)))
61 mType = SupplicantEvent::EVENT_EAP_SUCCESS;
62 else if (!strncmp(event, WPA_EVENT_EAP_FAILURE, strlen(WPA_EVENT_EAP_FAILURE)))
63 mType = SupplicantEvent::EVENT_EAP_FAILURE;
64 else if (!strncmp(event, WPA_EVENT_SCAN_RESULTS, strlen(WPA_EVENT_SCAN_RESULTS)))
65 mType = SupplicantEvent::EVENT_SCAN_RESULTS;
66 else if (!strncmp(event, WPA_EVENT_STATE_CHANGE, strlen(WPA_EVENT_STATE_CHANGE)))
67 mType = SupplicantEvent::EVENT_STATE_CHANGE;
68 else if (!strncmp(event, WPA_EVENT_LINK_SPEED, strlen(WPA_EVENT_LINK_SPEED)))
69 mType = SupplicantEvent::EVENT_LINK_SPEED;
70 else if (!strncmp(event, WPA_EVENT_DRIVER_STATE, strlen(WPA_EVENT_DRIVER_STATE)))
71 mType = SupplicantEvent::EVENT_DRIVER_STATE;
72 else {
73 LOGW("Unknown supplicant event '%s'", event);
74 mType = SupplicantEvent::EVENT_UNKNOWN;
75 }
76
77 for (event; *event != ' '; event++);
78 event++;
79
80 /*
81 * <N>CTRL-EVENT-XXX YYYY
82 * ^
83 * +---- event
84 */
85
86 for (event; *event == ' '; event++);
87
88 mEvent = strdup(event);
89 mLen = len;
90}
91
92SupplicantEvent::~SupplicantEvent() {
93 if (mEvent)
94 free(mEvent);
95}