xref: /freebsd/contrib/wpa/src/fst/fst_ctrl_aux.c (revision 780fb4a2fa9a9aee5ac48a60b790f567c0dc13e9)
1 /*
2  * FST module implementation
3  * Copyright (c) 2014, Qualcomm Atheros, Inc.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "utils/includes.h"
10 #include "utils/common.h"
11 #include "common/defs.h"
12 #include "fst_ctrl_defs.h"
13 #include "fst_ctrl_aux.h"
14 
15 
16 static const char *session_event_names[] = {
17 	[EVENT_FST_ESTABLISHED] = FST_PVAL_EVT_TYPE_ESTABLISHED,
18 	[EVENT_FST_SETUP] = FST_PVAL_EVT_TYPE_SETUP,
19 	[EVENT_FST_SESSION_STATE_CHANGED] = FST_PVAL_EVT_TYPE_SESSION_STATE,
20 };
21 
22 static const char *reason_names[] = {
23 	[REASON_TEARDOWN] = FST_CS_PVAL_REASON_TEARDOWN,
24 	[REASON_SETUP] = FST_CS_PVAL_REASON_SETUP,
25 	[REASON_SWITCH] = FST_CS_PVAL_REASON_SWITCH,
26 	[REASON_STT] = FST_CS_PVAL_REASON_STT,
27 	[REASON_REJECT] = FST_CS_PVAL_REASON_REJECT,
28 	[REASON_ERROR_PARAMS] = FST_CS_PVAL_REASON_ERROR_PARAMS,
29 	[REASON_RESET] = FST_CS_PVAL_REASON_RESET,
30 	[REASON_DETACH_IFACE] = FST_CS_PVAL_REASON_DETACH_IFACE,
31 };
32 
33 static const char *session_state_names[] = {
34 	[FST_SESSION_STATE_INITIAL] = FST_CS_PVAL_STATE_INITIAL,
35 	[FST_SESSION_STATE_SETUP_COMPLETION] =
36 	FST_CS_PVAL_STATE_SETUP_COMPLETION,
37 	[FST_SESSION_STATE_TRANSITION_DONE] = FST_CS_PVAL_STATE_TRANSITION_DONE,
38 	[FST_SESSION_STATE_TRANSITION_CONFIRMED] =
39 	FST_CS_PVAL_STATE_TRANSITION_CONFIRMED,
40 };
41 
42 
43 /* helpers */
fst_get_str_name(unsigned index,const char * names[],size_t names_size)44 const char * fst_get_str_name(unsigned index, const char *names[],
45 			      size_t names_size)
46 {
47 	if (index >= names_size || !names[index])
48 		return FST_NAME_UNKNOWN;
49 	return names[index];
50 }
51 
52 
fst_session_event_type_name(enum fst_event_type event)53 const char * fst_session_event_type_name(enum fst_event_type event)
54 {
55 	return fst_get_str_name(event, session_event_names,
56 				ARRAY_SIZE(session_event_names));
57 }
58 
59 
fst_reason_name(enum fst_reason reason)60 const char * fst_reason_name(enum fst_reason reason)
61 {
62 	return fst_get_str_name(reason, reason_names, ARRAY_SIZE(reason_names));
63 }
64 
65 
fst_session_state_name(enum fst_session_state state)66 const char * fst_session_state_name(enum fst_session_state state)
67 {
68 	return fst_get_str_name(state, session_state_names,
69 				ARRAY_SIZE(session_state_names));
70 }
71