xref: /freebsd/contrib/wpa/src/fst/fst_ctrl_aux.c (revision 243e928310d073338c5ec089f0dce238a80b9866)
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] FST_CS_PVAL_STATE_SETUP_COMPLETION,
36 	[FST_SESSION_STATE_TRANSITION_DONE] FST_CS_PVAL_STATE_TRANSITION_DONE,
37 	[FST_SESSION_STATE_TRANSITION_CONFIRMED]
38 	FST_CS_PVAL_STATE_TRANSITION_CONFIRMED,
39 };
40 
41 
42 /* helpers */
43 const char * fst_get_str_name(unsigned index, const char *names[],
44 			      size_t names_size)
45 {
46 	if (index >= names_size || !names[index])
47 		return FST_NAME_UNKNOWN;
48 	return names[index];
49 }
50 
51 
52 const char * fst_session_event_type_name(enum fst_event_type event)
53 {
54 	return fst_get_str_name(event, session_event_names,
55 				ARRAY_SIZE(session_event_names));
56 }
57 
58 
59 const char * fst_reason_name(enum fst_reason reason)
60 {
61 	return fst_get_str_name(reason, reason_names, ARRAY_SIZE(reason_names));
62 }
63 
64 
65 const char * fst_session_state_name(enum fst_session_state state)
66 {
67 	return fst_get_str_name(state, session_state_names,
68 				ARRAY_SIZE(session_state_names));
69 }
70