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