Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | /********************************************************************* * * Filename: iriap_event.c * Version: 0.1 * Description: IAP Finite State Machine * Status: Experimental. * Author: Dag Brattli <dagb@cs.uit.no> * Created at: Thu Aug 21 00:02:07 1997 * Modified at: Sun May 9 11:01:47 1999 * Modified by: Dag Brattli <dagb@cs.uit.no> * * Copyright (c) 1997, 1999 Dag Brattli <dagb@cs.uit.no>, All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Neither Dag Brattli nor University of Tromsø admit liability nor * provide warranty for any of this software. This material is * provided "AS-IS" and at no charge. * ********************************************************************/ #include <net/irda/irda.h> #include <net/irda/irlmp.h> #include <net/irda/iriap.h> #include <net/irda/iriap_event.h> static void state_s_disconnect ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_connecting ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_call ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_make_call ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_calling ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_outstanding ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_replying ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_wait_for_call( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_s_wait_active ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_disconnect ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_call ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_waiting ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_wait_active ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_receiving ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_execute ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void state_r_returning ( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb); static void (*iriap_state[])( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) = { /* Client FSM */ state_s_disconnect, state_s_connecting, state_s_call, /* S-Call FSM */ state_s_make_call, state_s_calling, state_s_outstanding, state_s_replying, state_s_wait_for_call, state_s_wait_active, /* Server FSM */ state_r_disconnect, state_r_call, /* R-Connect FSM */ state_r_waiting, state_r_wait_active, state_r_receiving, state_r_execute, state_r_returning, }; void iriap_next_client_state( struct iriap_cb *self, IRIAP_STATE state) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); switch ( state) { /* case S_DISCONNECT: DEBUG( 0, "IAP Client = S_DISCONNECT\n"); break; */ /* case S_CONNECTING: DEBUG( 0, "IAP Client = S_CONNECTING\n"); break; */ /* case S_CALL: DEBUG( 0, "IAP Client = S_CALL\n"); break; */ default: break; } self->client_state = state; } void iriap_next_call_state( struct iriap_cb *self, IRIAP_STATE state) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); /* switch ( state) { */ /* case S_MAKE_CALL: DEBUG( 0, "IAP Call = S_MAKE_CALL\n"); break; */ /* case S_CALLING: DEBUG( 0, "IAP Call = S_CALLING\n"); break; */ /* case S_OUTSTANDING: DEBUG( 0, "IAP Call = S_OUTSTANDING\n");break; */ /* case S_REPLYING: DEBUG( 0, "IAP Call = S_REPLYING\n"); break; */ /* case S_WAIT_FOR_CALL: DEBUG( 0, "IAP Call = S_WAIT_FOR_CALL\n"); break; */ /* case S_WAIT_ACTIVE: DEBUG( 0, "IAP Call = S_WAIT_ACTIVE\n"); break; */ /* default: */ /* break; */ /* } */ self->call_state = state; } void iriap_next_server_state( struct iriap_cb *self, IRIAP_STATE state) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); self->server_state = state; } void iriap_next_r_connect_state( struct iriap_cb *self, IRIAP_STATE state) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); self->r_connect_state = state; } void iriap_do_client_event( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); (*iriap_state[ self->client_state]) ( self, event, skb); } void iriap_do_call_event( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); (*iriap_state[ self->call_state]) ( self, event, skb); } void iriap_do_server_event( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); (*iriap_state[ self->server_state]) ( self, event, skb); } void iriap_do_r_connect_event( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); (*iriap_state[ self->r_connect_state]) ( self, event, skb); } /* * Function state_s_disconnect (event, skb) * * S-Disconnect, The device has no LSAP connection to a particular * remote device. */ static void state_s_disconnect( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { int ret; ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); switch( event) { case IAP_CALL_REQUEST_GVBC: iriap_next_client_state( self, S_CONNECTING); self->skb = skb; ret = irlmp_connect_request( self->lsap, LSAP_IAS, self->saddr, self->daddr, NULL, NULL); break; case IAP_LM_DISCONNECT_INDICATION: break; default: DEBUG( 0, __FUNCTION__"(), Unknown event %d\n", event); break; } } /* * Function state_s_connecting (self, event, skb) * * S-Connecting * */ static void state_s_connecting( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); ASSERT( self->magic == IAS_MAGIC, return;); switch( event) { case IAP_LM_CONNECT_CONFIRM: /* * Jump to S-Call FSM */ iriap_do_call_event( self, IAP_CALL_REQUEST, skb); /* iriap_call_request( self, 0,0,0); */ iriap_next_client_state( self, S_CALL); break; case IAP_LM_DISCONNECT_INDICATION: /* Abort calls */ iriap_next_call_state( self, S_MAKE_CALL); iriap_next_client_state( self, S_DISCONNECT); break; default: DEBUG( 0, __FUNCTION__ "(), Unknown event %d\n", event); break; } } /* * Function state_s_call (self, event, skb) * * S-Call, The device can process calls to a specific remote * device. Whenever the LSAP connection is disconnected, this state * catches that event and clears up */ static void state_s_call( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); switch( event) { case IAP_LM_DISCONNECT_INDICATION: /* Abort calls */ iriap_next_call_state( self, S_MAKE_CALL); iriap_next_client_state( self, S_DISCONNECT); break; default: DEBUG( 0, "state_s_call: Unknown event %d\n", event); break; } } /* * Function state_s_make_call (event, skb) * * S-Make-Call * */ static void state_s_make_call( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); switch( event) { case IAP_CALL_REQUEST: irlmp_data_request( self->lsap, self->skb); iriap_next_call_state( self, S_OUTSTANDING); break; default: DEBUG( 0, "state_s_make_call: Unknown event %d\n", event); break; } if ( skb) { dev_kfree_skb( skb); } } /* * Function state_s_calling (event, skb) * * S-Calling * */ static void state_s_calling( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), Not implemented\n"); } /* * Function state_s_outstanding (event, skb) * * S-Outstanding, The device is waiting for a response to a command * */ static void state_s_outstanding( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { ASSERT( self != NULL, return;); switch( event) { case IAP_RECV_F_LST: iriap_send_ack( self); /*LM_Idle_request(idle); */ dev_kfree_skb( skb); iriap_next_call_state( self, S_WAIT_FOR_CALL); break; default: DEBUG( 0, __FUNCTION__ "(), Unknown event %d\n", event); break; } } /* * Function state_s_replying (event, skb) * * S-Replying, The device is collecting a multiple part response */ static void state_s_replying( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), Not implemented\n"); } /* * Function state_s_wait_for_call (event, skb) * * S-Wait-for-Call * */ static void state_s_wait_for_call( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), Not implemented\n"); } /* * Function state_s_wait_active (event, skb) * * S-Wait-Active * */ static void state_s_wait_active( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), Not implemented\n"); } /************************************************************************** * * Server FSM * **************************************************************************/ /* * Function state_r_disconnect (self, event, skb) * * LM-IAS server is disconnected (not processing any requests!) * */ static void state_r_disconnect( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { struct sk_buff *tx_skb; switch( event) { case IAP_LM_CONNECT_INDICATION: tx_skb = dev_alloc_skb( 64); if ( tx_skb == NULL) { DEBUG( 0,"state_r_disconnect: " "Could not allocate an sk_buff of length %d\n", 64); return; } /* Reserve space for MUX_CONTROL and LAP header */ skb_reserve(tx_skb, LMP_MAX_HEADER); irlmp_connect_response(self->lsap, tx_skb); /*LM_Idle_request(idle); */ iriap_next_server_state( self, R_CALL); /* * Jump to R-Connect FSM, we skip R-Waiting since we do not * care about LM_Idle_request()! */ iriap_next_r_connect_state( self, R_RECEIVING); if (skb) dev_kfree_skb( skb); break; default: DEBUG( 0, "state_r_disconnect: Unknown event %d\n", event); break; } } /* * Function state_r_call (self, event, skb) * * * */ static void state_r_call( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 4, "state_r_call()\n"); switch( event) { case IAP_LM_DISCONNECT_INDICATION: /* Abort call */ iriap_next_server_state( self, R_DISCONNECT); iriap_next_r_connect_state( self, R_WAITING); break; default: DEBUG( 0, "state_r_call, unknown event!\n"); break; } } /* * R-Connect FSM */ /* * Function state_r_waiting (self, event, skb) * * * */ static void state_r_waiting( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), Not implemented\n"); } static void state_r_wait_active( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), Not implemented\n"); } /* * Function state_r_receiving (self, event, skb) * * We are receiving a command * */ static void state_r_receiving( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 4, __FUNCTION__ "()\n"); switch( event) { case IAP_RECV_F_LST: iriap_next_r_connect_state( self, R_EXECUTE); iriap_call_indication( self, skb); break; default: DEBUG( 0, __FUNCTION__ "(), unknown event!\n"); break; } } /* * Function state_r_execute (self, event, skb) * * The server is processing the request * */ static void state_r_execute( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 4, __FUNCTION__ "()\n"); ASSERT( skb != NULL, return;); if ( !self || self->magic != IAS_MAGIC) { DEBUG( 0, "state_r_execute: bad pointer self\n"); return; } switch( event) { case IAP_CALL_RESPONSE: /* * Since we don't implement the Waiting state, we return * to state Receiving instead, DB. */ iriap_next_r_connect_state( self, R_RECEIVING); irlmp_data_request( self->lsap, skb); break; default: DEBUG( 0, __FUNCTION__ "(), unknown event!\n"); break; } } static void state_r_returning( struct iriap_cb *self, IRIAP_EVENT event, struct sk_buff *skb) { DEBUG( 0, __FUNCTION__ "(), event=%d\n", event); switch( event) { case IAP_RECV_F_LST: break; default: break; } } |