1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 #ifndef _IDM_CONN_SM_H_ 27 #define _IDM_CONN_SM_H_ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 34 /* 35 * IDM connection state machine events. Most events get generated internally 36 * either by the state machine or by the IDM TX/RX code. For example when IDM 37 * receives a login request for a target connectionit will generate a 38 * CE_LOGIN_RCV event. Similarly when the target sends a successful login 39 * response IDM generate a "CE_LOGIN_SUCCESS_SND" event. The following 40 * events are not detected on the TX/RX path and must be generated explicitly 41 * by the client when appropriate: 42 * 43 * CE_LOGOUT_OTHER_CONN_RCV 44 * CE_ASYNC_DROP_CONN_RCV (Only because the message may be received on 45 * a different connection from the connection being dropped) 46 * CE_ASYNC_DROP_ALL_CONN_RCV 47 * CE_LOGOUT_OTHER_CONN_SND 48 * CE_ASYNC_DROP_ALL_CONN_SND 49 * 50 * The following events might occur in any state since they are driven 51 * by the PDU's that IDM receives: 52 * 53 * CE_LOGIN_RCV 54 * CE_LOGIN_SUCCESS_RCV 55 * CE_LOGIN_FAIL_RCV 56 * CE_LOGOUT_SUCCESS_RCV 57 * CE_LOGOUT_FAIL_RCV 58 * CE_ASYNC_LOGOUT_RCV 59 * CE_MISC_RCV 60 * CE_RX_PROTOCOL_ERROR 61 */ 62 63 #define IDM_LOGIN_SECONDS 20 64 #define IDM_LOGOUT_SECONDS 20 65 #define IDM_CLEANUP_SECONDS 0 66 67 /* Update idm_ce_name table whenever connection events are modified */ 68 typedef enum { 69 CE_UNDEFINED = 0, 70 71 /* Initiator events */ 72 CE_CONNECT_REQ, 73 CE_CONNECT_FAIL, 74 CE_CONNECT_SUCCESS, 75 CE_LOGIN_SND, 76 CE_LOGIN_SUCCESS_RCV, 77 CE_LOGIN_FAIL_RCV, 78 CE_LOGOUT_THIS_CONN_SND, 79 CE_LOGOUT_OTHER_CONN_SND, 80 CE_LOGOUT_SESSION_SND, 81 CE_LOGOUT_SUCCESS_RCV, 82 CE_LOGOUT_FAIL_RCV, 83 CE_ASYNC_LOGOUT_RCV, 84 CE_ASYNC_DROP_CONN_RCV, 85 CE_ASYNC_DROP_ALL_CONN_RCV, 86 87 /* Target events */ 88 CE_CONNECT_ACCEPT, 89 CE_CONNECT_REJECT, 90 CE_LOGIN_RCV, 91 CE_LOGIN_TIMEOUT, 92 CE_LOGIN_SUCCESS_SND, 93 CE_LOGIN_FAIL_SND, 94 CE_LOGIN_FAIL_SND_DONE, 95 CE_LOGOUT_THIS_CONN_RCV, 96 CE_LOGOUT_OTHER_CONN_RCV, 97 CE_LOGOUT_SESSION_RCV, 98 CE_LOGOUT_SUCCESS_SND, 99 CE_LOGOUT_SUCCESS_SND_DONE, 100 CE_LOGOUT_FAIL_SND, 101 CE_LOGOUT_FAIL_SND_DONE, 102 CE_CLEANUP_TIMEOUT, 103 CE_ASYNC_LOGOUT_SND, 104 CE_ASYNC_DROP_CONN_SND, 105 CE_ASYNC_DROP_ALL_CONN_SND, 106 CE_LOGOUT_TIMEOUT, 107 108 /* Common events */ 109 CE_TRANSPORT_FAIL, 110 CE_MISC_TX, 111 CE_TX_PROTOCOL_ERROR, 112 CE_MISC_RX, 113 CE_RX_PROTOCOL_ERROR, 114 CE_LOGOUT_SESSION_SUCCESS, 115 CE_CONN_REINSTATE, 116 CE_CONN_REINSTATE_SUCCESS, 117 CE_CONN_REINSTATE_FAIL, 118 CE_ENABLE_DM_SUCCESS, 119 CE_ENABLE_DM_FAIL, 120 121 /* Add new events above CE_MAX_EVENT */ 122 CE_MAX_EVENT 123 } idm_conn_event_t; 124 125 #ifdef IDM_CONN_SM_STRINGS 126 /* An array of event text values, for use in logging events */ 127 static const char *idm_ce_name[CE_MAX_EVENT+1] = { 128 "CE_UNDEFINED", 129 "CE_CONNECT_REQ", 130 "CE_CONNECT_FAIL", 131 "CE_CONNECT_SUCCESS", 132 "CE_LOGIN_SND", 133 "CE_LOGIN_SUCCESS_RCV", 134 "CE_LOGIN_FAIL_RCV", 135 "CE_LOGOUT_THIS_CONN_SND", 136 "CE_LOGOUT_OTHER_CONN_SND", 137 "CE_LOGOUT_SESSION_SND", 138 "CE_LOGOUT_SUCCESS_RCV", 139 "CE_LOGOUT_FAIL_RCV", 140 "CE_ASYNC_LOGOUT_RCV", 141 "CE_ASYNC_DROP_CONN_RCV", 142 "CE_ASYNC_DROP_ALL_CONN_RCV", 143 "CE_CONNECT_ACCEPT", 144 "CE_CONNECT_REJECT", 145 "CE_LOGIN_RCV", 146 "CE_LOGIN_TIMEOUT", 147 "CE_LOGIN_SUCCESS_SND", 148 "CE_LOGIN_FAIL_SND", 149 "CE_LOGIN_FAIL_SND_DONE", 150 "CE_LOGOUT_THIS_CONN_RCV", 151 "CE_LOGOUT_OTHER_CONN_RCV", 152 "CE_LOGOUT_SESSION_RCV", 153 "CE_LOGOUT_SUCCESS_SND", 154 "CE_LOGOUT_SUCCESS_SND_DONE", 155 "CE_LOGOUT_FAIL_SND", 156 "CE_LOGOUT_FAIL_SND_DONE", 157 "CE_CLEANUP_TIMEOUT", 158 "CE_ASYNC_LOGOUT_SND", 159 "CE_ASYNC_DROP_CONN_SND", 160 "CE_ASYNC_DROP_ALL_CONN_SND", 161 "CE_LOGOUT_TIMEOUT", 162 "CE_TRANSPORT_FAIL", 163 "CE_MISC_TX", 164 "CE_TX_PROTOCOL_ERROR", 165 "CE_MISC_RX", 166 "CE_RX_PROTOCOL_ERROR", 167 "CE_LOGOUT_SESSION_SUCCESS", 168 "CE_CONN_REINSTATE", 169 "CE_CONN_REINSTATE_SUCCESS", 170 "CE_CONN_REINSTATE_FAIL", 171 "CE_ENABLE_DM_SUCCESS", 172 "CE_ENABLE_DM_FAIL", 173 "CE_MAX_EVENT" 174 }; 175 #endif 176 177 /* Update idm_cs_name table whenever connection states are modified */ 178 typedef enum { 179 CS_S0_UNDEFINED = 0, 180 181 CS_S1_FREE, 182 CS_S2_XPT_WAIT, 183 CS_S3_XPT_UP, 184 CS_S4_IN_LOGIN, 185 CS_S5_LOGGED_IN, 186 CS_S6_IN_LOGOUT, 187 CS_S7_LOGOUT_REQ, 188 CS_S8_CLEANUP, 189 CS_S9_INIT_ERROR, 190 CS_S10_IN_CLEANUP, 191 CS_S11_COMPLETE, 192 CS_S12_ENABLE_DM, 193 194 /* Add new connection states above CS_MAX_STATE */ 195 CS_MAX_STATE 196 } idm_conn_state_t; 197 198 #ifdef IDM_CONN_SM_STRINGS 199 /* An array of state text values, for use in logging state transitions */ 200 static const char *idm_cs_name[CS_MAX_STATE+1] = { 201 "CS_S0_UNDEFINED", 202 "CS_S1_FREE", 203 "CS_S2_XPT_WAIT", 204 "CS_S3_XPT_UP", 205 "CS_S4_IN_LOGIN", 206 "CS_S5_LOGGED_IN", 207 "CS_S6_IN_LOGOUT", 208 "CS_S7_LOGOUT_REQ", 209 "CS_S8_CLEANUP", 210 "CS_S9_INIT_ERROR", 211 "CS_S10_IN_CLEANUP", 212 "CS_S11_COMPLETE", 213 "CS_S12_ENABLE_DM", 214 "CS_MAX_STATE" 215 }; 216 #endif 217 218 typedef enum { 219 CT_NONE = 0, 220 CT_RX_PDU, 221 CT_TX_PDU 222 } idm_pdu_event_type_t; 223 224 typedef enum { 225 CA_TX_PROTOCOL_ERROR, /* Send "protocol error" to state machine */ 226 CA_RX_PROTOCOL_ERROR, /* Send "protocol error" to state machine */ 227 CA_FORWARD, /* State machine event and foward to client */ 228 CA_DROP /* Drop PDU */ 229 } idm_pdu_event_action_t; 230 231 typedef struct { 232 struct idm_conn_s *iec_ic; 233 idm_conn_event_t iec_event; 234 uintptr_t iec_info; 235 idm_pdu_event_type_t iec_pdu_event_type; 236 } idm_conn_event_ctx_t; 237 238 idm_status_t 239 idm_conn_sm_init(struct idm_conn_s *ic); 240 241 void 242 idm_conn_sm_fini(struct idm_conn_s *ic); 243 244 idm_status_t 245 idm_notify_client(struct idm_conn_s *ic, idm_client_notify_t cn, 246 uintptr_t data); 247 248 void 249 idm_conn_event(struct idm_conn_s *ic, idm_conn_event_t event, uintptr_t data); 250 251 idm_status_t 252 idm_conn_reinstate_event(struct idm_conn_s *old_ic, struct idm_conn_s *new_ic); 253 254 void 255 idm_conn_tx_pdu_event(struct idm_conn_s *ic, idm_conn_event_t event, 256 uintptr_t data); 257 258 void 259 idm_conn_rx_pdu_event(struct idm_conn_s *ic, idm_conn_event_t event, 260 uintptr_t data); 261 262 char * 263 idm_conn_state_str(struct idm_conn_s *ic); 264 265 #ifdef __cplusplus 266 } 267 #endif 268 269 #endif /* _IDM_CONN_SM_H_ */ 270