cm-kernel /drivers/net/wireless/tiwlan1251/common/src/core/sme/smeSm/smeSm.c

Language C Lines 1224
MD5 Hash 0d3eb5d68f3c340de47236ef6794f312 Estimated Cost $18,439 (why?)
Repository git://github.com/CyanogenMod/cm-kernel.git View Raw File View Project SPDX
   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
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
/****************************************************************************
**+-----------------------------------------------------------------------+**
**|                                                                       |**
**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
**| All rights reserved.                                                  |**
**|                                                                       |**
**| Redistribution and use in source and binary forms, with or without    |**
**| modification, are permitted provided that the following conditions    |**
**| are met:                                                              |**
**|                                                                       |**
**|  * Redistributions of source code must retain the above copyright     |**
**|    notice, this list of conditions and the following disclaimer.      |**
**|  * Redistributions in binary form must reproduce the above copyright  |**
**|    notice, this list of conditions and the following disclaimer in    |**
**|    the documentation and/or other materials provided with the         |**
**|    distribution.                                                      |**
**|  * Neither the name Texas Instruments nor the names of its            |**
**|    contributors may be used to endorse or promote products derived    |**
**|    from this software without specific prior written permission.      |**
**|                                                                       |**
**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
**|                                                                       |**
**+-----------------------------------------------------------------------+**
****************************************************************************/


/** \file smeSm.c
 *  \brief SME SM implementation
 *
 *  \see smeSm.h
 */

#include "osTIType.h"
#include "osApi.h"
#include "paramOut.h"
#include "paramIn.h"
#include "srcApi.h"
#include "report.h"
#include "connApi.h"
#include "siteMgrApi.h"
#include "smeSmApi.h"
#include "utils.h"  
#include "fsm.h"  
#include "smeSm.h" 
#include "smeApi.h" 
#include "DataCtrl_Api.h"
#include "regulatoryDomainApi.h"
#include "TrafficMonitorAPI.h"
#include "PowerMgr_API.h"
#include "EvHandler.h"
#include "TI_IPC_Api.h"
#include "ScanCncnApi.h"
#ifdef EXC_MODULE_INCLUDED
#include "DataCtrl_Api.h"
#endif
#include "apConn.h"


/* State Machine Functions */
static TI_STATUS idle_to_interScan(void *pData);

static TI_STATUS interScan_to_scanning(void *pData);

static TI_STATUS interScan_to_idle(void *pData);

static TI_STATUS scan_to_idle(void *pData);

static TI_STATUS scan_to_scan(void *pData);

static TI_STATUS scan_to_select(void *pData);

static TI_STATUS scan_to_interScan(void *pData);

static TI_STATUS select_to_InterScan(void *pData);

static TI_STATUS select_to_connect(void *pData);

static TI_STATUS connecting_To_Disconnecting(void *pData);

static TI_STATUS connecting_to_connected(void *pData);

static TI_STATUS connecting_to_selecting(void *pData);

static TI_STATUS connected_to_interScan(void *pData);

static TI_STATUS connected_To_disconnecting(void *pData);

static TI_STATUS disconnecting_to_interScan(void *pData);


/* Local functions prototypes */
static TI_STATUS actionUnexpected(void *pData);

static TI_STATUS actionNop(void *pData);

static TI_STATUS smeCallScan(void *pData);

static TI_STATUS chooseScanBand(smeSm_t* pSmeSm, radioBand_e *band);

static TI_STATUS smeSm_changeBandParams(TI_HANDLE	hSmeSm, radioBand_e radioBand);

static TI_STATUS smeSm_startInterScanTimeout(TI_HANDLE hSmeSm);

static TI_STATUS smeSm_stopInterScanTimeout(TI_HANDLE hSmeSm);

static void		 smeSm_sendDisassociateEvent(smeSm_t* pSmeSm);

/****************************************************/
/*		Interface Functions Implementations			*/
/****************************************************/


/***********************************************************************
 *                        smeSm_smCreate									
 ***********************************************************************
DESCRIPTION: State machine creation function, called by the SME SM API. Allocates the state machine 
                                                                                                   
INPUT:      hOs	-	OS handle.

OUTPUT:		

RETURN:     State machine pointer on success, NULL otherwise

************************************************************************/
fsm_stateMachine_t *smeSm_smCreate(TI_HANDLE hOs)
{
	TI_STATUS status;
	fsm_stateMachine_t *pFsm;

	status = fsm_Create(hOs, &pFsm, SME_SM_NUM_STATES, SME_SM_NUM_EVENTS);
	
	if (status != OK)
		return NULL;

	return pFsm;
}

/***********************************************************************
 *                        smeSm_smConfig									
 ***********************************************************************
DESCRIPTION: State machine configuration function, called by the SME SM API. Configures the state machine 
                                                                                                   
INPUT:      pSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     OK on success, NOK otherwise

************************************************************************/
TI_STATUS smeSm_smConfig(smeSm_t *pSmeSm)
{
    paramInfo_t param;

	fsm_actionCell_t    smMatrix[SME_SM_NUM_STATES][SME_SM_NUM_EVENTS] =
	{
		/* next state and actions for IDLE state */
		{
			{SME_SM_STATE_INTER_SCAN, idle_to_interScan},       /*  "EVENT_START",                   */
			{SME_SM_STATE_IDLE, actionUnexpected},         		/*  "EVENT_STOP",                    */
			{SME_SM_STATE_IDLE, actionUnexpected},         		/*  "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_IDLE, actionUnexpected},         		/*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_IDLE, actionUnexpected},         		/*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_IDLE, actionUnexpected},         		/*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_IDLE, actionUnexpected},         		/*  "EVENT_CONN_FAILURE",                  */
			{SME_SM_STATE_IDLE, actionNop},     		    	/*  "EVENT_RESELECT",                */
			{SME_SM_STATE_IDLE, actionNop},     		    	/*  "EVENT_DISCONNECT"*/
		},

		/* next state and actions for SCANNING state */
		{	
			{SME_SM_STATE_SCANNING, actionUnexpected},          /*  "EVENT_START",                   */
			{SME_SM_STATE_IDLE,      scan_to_idle},				/*  "EVENT_STOP",                    */
			{SME_SM_STATE_SELECTING, scan_to_select},           /*  "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_SCANNING, actionUnexpected},          /*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_SCANNING, actionUnexpected},          /*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_SCANNING, actionUnexpected},          /*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_SCANNING, actionUnexpected},          /*  "EVENT_CONN_FAILURE",                  */
			{SME_SM_STATE_SCANNING, scan_to_scan},              /*  "EVENT_RESELECT",*/
			{SME_SM_STATE_INTER_SCAN, scan_to_interScan},     	/*  "EVENT_DISCONNECT"*/
		},

		/* next state and actions for SELECTING state */
		{	
			{SME_SM_STATE_SELECTING, actionUnexpected},         /*  "EVENT_START",                   */
			{SME_SM_STATE_SELECTING, actionUnexpected},			/*  "EVENT_STOP",                    */
			{SME_SM_STATE_SELECTING, actionUnexpected},         /*  "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_CONNECTING, select_to_connect},       /*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_INTER_SCAN, select_to_InterScan},	   	/*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_SELECTING, actionUnexpected},         /*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_SELECTING, actionUnexpected},         /*  "EVENT_CONN_FAILURE",                   */
    		{SME_SM_STATE_SELECTING, actionUnexpected},         /*  "EVENT_RESELECT",                */
			{SME_SM_STATE_SELECTING, actionUnexpected},         /*  "EVENT_DISCONNECT",*/
		},

		/* next state and actions for CONNECTING state */
		{	
			{SME_SM_STATE_SCANNING,      actionUnexpected},               /*  "EVENT_START",                   */
			{SME_SM_STATE_DISCONNECTING, connecting_To_Disconnecting},    /*  "EVENT_STOP",                    */
			{SME_SM_STATE_CONNECTING,    actionUnexpected},               /*  "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_CONNECTING,    actionUnexpected},               /*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_CONNECTING,    actionUnexpected},               /*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_CONNECTED,     connecting_to_connected},        /*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_SELECTING,     connecting_to_selecting},        /*  "EVENT_CONN_FAILURE",                  */
			{SME_SM_STATE_DISCONNECTING, connecting_To_Disconnecting},    /*  "EVENT_RESELECT",               */
			{SME_SM_STATE_DISCONNECTING, connecting_To_Disconnecting},    /*  "EVENT_DISCONNECT", */
		},

		/* next state and actions for CONNECTED state */
		{	
			{SME_SM_STATE_SCANNING, actionUnexpected},			           	/*  "EVENT_START",                   */
			{SME_SM_STATE_DISCONNECTING, connected_To_disconnecting},	   	/*  "EVENT_STOP",                    */
			{SME_SM_STATE_CONNECTED, actionUnexpected},				 		/* "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_CONNECTED, actionUnexpected},						/*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_CONNECTED, actionUnexpected},						/*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_CONNECTED, actionUnexpected},		        		/*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_INTER_SCAN, connected_to_interScan},		        /*  "EVENT_CONN_FAILURE",                   */
			{SME_SM_STATE_DISCONNECTING, connected_To_disconnecting},      	/*  "EVENT_RESELECT",                */
			{SME_SM_STATE_DISCONNECTING	,connected_To_disconnecting},      	/*  "EVENT_DISCONNECT",*/
		},

	    /* next state and actions for DISCONNECTING state */
		{	
			{SME_SM_STATE_DISCONNECTING,      actionNop},   				/*  "EVENT_START",                   */
			{SME_SM_STATE_DISCONNECTING,      actionNop},  					/*  "EVENT_STOP",                    */
			{SME_SM_STATE_DISCONNECTING, actionUnexpected}, 				/*  "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_DISCONNECTING, actionUnexpected}, 				/*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_DISCONNECTING, actionUnexpected}, 				/*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_DISCONNECTING, actionUnexpected},  				/*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_INTER_SCAN, disconnecting_to_interScan}, 			/*  "EVENT_CONN_FAILURE",                  */
			{SME_SM_STATE_DISCONNECTING,  	   actionNop}, 			  	    /*  "EVENT_RESELECT",               */
			{SME_SM_STATE_DISCONNECTING,  	   actionNop}, 			  	    /*  "EVENT_DISCONNECT",*/
		},


		/* next state and actions for STATE_INTER_SCAN_TIMEOUT state */
		{
			{SME_SM_STATE_INTER_SCAN, actionUnexpected},          /*  "EVENT_START",                   */
			{SME_SM_STATE_IDLE, interScan_to_idle},				  /*  "EVENT_STOP",                    */
			{SME_SM_STATE_INTER_SCAN, actionUnexpected},          /*  "EVENT_SCAN_COMPLETE",           */
			{SME_SM_STATE_INTER_SCAN, actionUnexpected},          /*  "EVENT_SELECT_SUCCESS",          */
			{SME_SM_STATE_INTER_SCAN, actionUnexpected},          /*  "EVENT_SELECT_FAILURE",          */
			{SME_SM_STATE_INTER_SCAN, actionUnexpected},          /*  "EVENT_CONN_SUCCESS",            */
			{SME_SM_STATE_INTER_SCAN, actionUnexpected},          /*  "EVENT_CONN_FAILURE",                  */
			{SME_SM_STATE_SCANNING, interScan_to_scanning},       /*  "EVENT_RESELECT",                */
			{SME_SM_STATE_INTER_SCAN, actionNop},     			  /*  "EVENT_DISCONNECT",*/
		},
	
	};

	pSmeSm->dualBandReScanFlag = FALSE;
	pSmeSm->reScanFlag = FALSE;
	pSmeSm->radioOn    = FALSE;
    pSmeSm->immediateShutdownRequired = FALSE;
	
    /* if desired SSID is junk SSID, don't connect (until new SSID is set) */
    param.paramType = SITE_MGR_DESIRED_SSID_PARAM;
    siteMgr_getParam( pSmeSm->hSiteMgr, &param );
    
    if ( utils_isJunkSSID( &(param.content.siteMgrDesiredSSID) ) )
    {
        pSmeSm->connectEnabled = FALSE;
    }
    else
    {
        pSmeSm->connectEnabled = TRUE;
    }

	/* First event should indicate to the upper layer that STA is disassociated. */
	pSmeSm->DisAssoc.mgmtStatus = STATUS_UNSPECIFIED;
	pSmeSm->DisAssoc.uStatusCode = 0;
	smeSm_sendDisassociateEvent(pSmeSm);

#ifdef TI_DBG
	/* clear statistics */
	smeSm_resetStats( (TI_HANDLE)pSmeSm );
#endif

	return fsm_Config(pSmeSm->pFsm, (fsm_Matrix_t)smMatrix, SME_SM_NUM_STATES, SME_SM_NUM_EVENTS, smeSm_SMEvent, pSmeSm->hOs);
}

/***********************************************************************
 *                        smeSm_smUnLoad									
 ***********************************************************************
DESCRIPTION: State machine unload function, called by the SME SM API. Unloads the state machine 
                                                                                                   
INPUT:      hOs		-	OS handle.
			pFsm	-	Pointer to the state machine

OUTPUT:		

RETURN:     State machine pointer on success, NULL otherwise

************************************************************************/
TI_STATUS smeSm_smUnLoad(TI_HANDLE hOs, fsm_stateMachine_t *pFsm)
{
	fsm_Unload(hOs, pFsm);
	
	return OK;
}

/***********************************************************************
 *                        smeSm_SMEvent									
 ***********************************************************************
DESCRIPTION: SME SM event processing function, called by the SME SM API
				Perform the following:
				-	Print the state movement as a result from the event
				-	Calls the generic state machine event processing function which preform the following:
					-	Calls the corresponding callback function
					-	Move to next state
				
INPUT:		currentState	-	Pointer to the connection current state.
			event	-	Received event
			pSmeSm	-	SME SM handle

OUTPUT:		

RETURN:     OK on success, NOK otherwise

************************************************************************/

#ifdef REPORT_LOG

static char *stateDesc[SME_SM_NUM_STATES] = 
	{
		"STATE_IDLE",
		"STATE_SCANNING",
		"STATE_SELECTING",
		"STATE_CONNECTING",
		"STATE_CONNECTED",
		"STATE_DISCONNECTING",
		"STATE_INTER_SCAN",
	};

static char *eventDesc[SME_SM_NUM_EVENTS] = 
	{
		"EVENT_START",
		"EVENT_STOP",
		"EVENT_SCAN_COMPLETE",
		"EVENT_SELECT_SUCCESS",
		"EVENT_SELECT_FAILURE",
		"EVENT_CONN_SUCCESS",
		"EVENT_CONN_FAILURE",
		"EVENT_RESELECT",
		"EVENT_DISCONNECT",
	};

#endif


TI_STATUS smeSm_SMEvent(UINT8 *currentState, UINT8 event, TI_HANDLE hSmeSm)
{
   smeSm_t *pSmeSm = (smeSm_t *)hSmeSm;
	TI_STATUS 		status;
	UINT8		nextState;

	status = fsm_GetNextState(pSmeSm->pFsm, *currentState, event, &nextState);
	if (status != OK)
	{
		WLAN_REPORT_SM(pSmeSm->hReport, SME_SM_MODULE_LOG, ("State machine error, failed getting next state\n"));
		return(NOK);
	}

	WLAN_REPORT_SM(pSmeSm->hReport, SME_SM_MODULE_LOG, 
							  ("<%s, %s> --> %s\n\n",
							   stateDesc[*currentState],
							   eventDesc[event],
							   stateDesc[nextState]));

	status = fsm_Event(pSmeSm->pFsm, currentState, event, (void *)pSmeSm);

	return status;
}


/************************************************************************************************************/
/*		In the following section are listed the callback function used by the SME state machine				*/
/************************************************************************************************************/

/* START_SCAN */ 
TI_STATUS sme_startScan(void *pData)
{
	paramInfo_t	param;
	smeSm_t *pSmeSm = (smeSm_t *)pData;
   
   /*
	* Support Dual Mode Operation
	*/ 

    radioBand_e	band; 

	/*
	 * If scan is disabled then send self scan complete event, skipping the scan procedure.
	 */ 
	if (pSmeSm->scanEnabled != SCAN_ENABLED)
	{
		if (pSmeSm->scanEnabled == SKIP_NEXT_SCAN) 
		{
			pSmeSm->scanEnabled = SCAN_ENABLED;
		}
		return smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_SCAN_COMPLETE , pSmeSm);
	}
	

    /* if performing a dual band rescan now */
    if ( TRUE == pSmeSm->dualBandReScanFlag )
    {
        /* mark that no more scans are needed */
        pSmeSm->dualBandReScanFlag = FALSE;
		chooseScanBand(pSmeSm, &band);
		smeSm_changeBandParams(pSmeSm, band);
    }
    else
    {
        param.paramType = SITE_MGR_DESIRED_DOT11_MODE_PARAM;
        siteMgr_getParam(pSmeSm->hSiteMgr, &param);

        if(param.content.siteMgrDot11Mode == DOT11_DUAL_MODE) 
        {
	        pSmeSm->dualBandReScanFlag = TRUE;
	        chooseScanBand(pSmeSm, &band);
	        smeSm_changeBandParams(pSmeSm, band);
        }
    }

    return smeCallScan(pData);
}


/* RESTART_SCAN when exiting from IDLE state*/ 
static TI_STATUS idle_to_interScan(void *pData)
{
	smeSm_t         *pSmeSm = (smeSm_t *)pData;

	pSmeSm->interScanTimeout = pSmeSm->interScanTimeoutMin;

    /* Set the SCR group to inter SCAN */
    scr_setGroup( pSmeSm->hScr, SCR_GID_INTER_SCAN );

    /*
	 * If the connection is enabled then initiate "reselect" event that moves the
	 * SM into scan state. 
	 */
	if( pSmeSm->connectEnabled ){
		return smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_RESELECT , pSmeSm);
	}
	/* connectEnabled is FALSE, need to stay at this state until it will be changed. */

	return OK;
}



TI_STATUS interScan_to_scanning(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;
	
	pSmeSm->bSendDisAssocEvent = FALSE; 
	
	smeSm_stopInterScanTimeout(pSmeSm);
		
    /* Set SCR to "first connection" */
	scr_setGroup( pSmeSm->hScr, SCR_GID_CONNECT );

#ifdef TI_DBG
	/* update statistics - count scan attempts for connection */
	pSmeSm->smeStats.currentNumberOfScanAttempts++;
#endif
	return (sme_startScan(pData));
}



static TI_STATUS disconnecting_to_interScan(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	pSmeSm->interScanTimeout = pSmeSm->interScanTimeoutMin;

    scr_setGroup( pSmeSm->hScr, SCR_GID_INTER_SCAN );
    
    siteMgr_disSelectSite(pSmeSm->hSiteMgr);

	/*
	 *  Notify that the driver is disassociated to the supplicant\IP stack. 
	 */
	smeSm_sendDisassociateEvent(pSmeSm);

	if (!pSmeSm->scanEnabled) 
	{
		pSmeSm->connectEnabled = FALSE;
	}

	/* Radio ON and connection is enabled go to scanning */
	if( pSmeSm->radioOn )
	{
		if(	pSmeSm->connectEnabled )
			return smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_RESELECT , pSmeSm);

		else {
			/* Radio is on but connection is disabled, stay at interScan state 
				without starting the interscan timer. */
	
			/* SCR is set to enable only APP scan */
			return OK;
		}
	}	

	else{ 
			return smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_STOP , pSmeSm);
	}
}


static TI_STATUS connected_to_interScan(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	pSmeSm->interScanTimeout = pSmeSm->interScanTimeoutMin;
	
	siteMgr_disSelectSite(pSmeSm->hSiteMgr);

	scr_setGroup( pSmeSm->hScr, SCR_GID_INTER_SCAN );

	/*
	 *  Notify that the driver is associated to the supplicant\IP stack. 
	 */
	smeSm_sendDisassociateEvent(pSmeSm);

	if (!pSmeSm->scanEnabled) 
	{
		pSmeSm->connectEnabled = FALSE;
	}

	return smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_RESELECT , pSmeSm);
}


static TI_STATUS select_to_InterScan(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;
		
	siteMgr_disSelectSite(pSmeSm->hSiteMgr);

	/* SCR is set to enable only APP scan */
    scr_setGroup( pSmeSm->hScr, SCR_GID_INTER_SCAN );
    
    if (pSmeSm->connectEnabled)
	{
		smeSm_startInterScanTimeout(pSmeSm);
	}

	if ((pSmeSm->bSendDisAssocEvent == TRUE) || (pSmeSm->scanEnabled == FALSE))
    {
		/*
		 *  Notify that the driver is disassociated to the supplicant\IP stack. 
		 */
		smeSm_sendDisassociateEvent(pSmeSm);
	}

	return OK;
}



static TI_STATUS scan_to_interScan(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;
   	
	/* SCR is set to enable only APP scan */
	scr_setGroup( pSmeSm->hScr, SCR_GID_INTER_SCAN );

	pSmeSm->interScanTimeout = pSmeSm->interScanTimeoutMin;

	if (pSmeSm->connectEnabled)
	{
		smeSm_startInterScanTimeout(pSmeSm);
	}

	return OK;

}


/* STOP_SCAN, START_SCAN */ 
static TI_STATUS scan_to_scan(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;
	
	WLAN_REPORT_INFORMATION(pSmeSm->hReport, SME_SM_MODULE_LOG, ("Setting reScanFlag to ON\n"));
	
	pSmeSm->reScanFlag = TRUE;
	
	scanConcentrator_stopScan( pSmeSm->hScanCncn, SCAN_SCC_DRIVER );
	
	return OK;
}



/* CANCEL INTER_SCAN TIMEOUT*/ 
static TI_STATUS interScan_to_idle(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	smeSm_stopInterScanTimeout(pSmeSm);
	
    /* Change shutdown status flag to indicate SME is in IDLE state */
    pSmeSm->shutDownStatus |= DRIVER_SHUTDOWN_SME_STOPPED;

	/* Set SCR state to "Idle" */
    scr_setGroup( pSmeSm->hScr, SCR_GID_IDLE );
    
	return OK;
	
}


/* Stop current scanning and  go to idle */ 
static TI_STATUS scan_to_idle(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	/* stopping the current active scan process */
	scanConcentrator_stopScan( pSmeSm->hScanCncn, SCAN_SCC_DRIVER );

    /* Change shutdown status flag to indicate SME is in IDLE state */
    pSmeSm->shutDownStatus |= DRIVER_SHUTDOWN_SME_STOPPED;

	/* Set the SCR group to "idle" */
    scr_setGroup( pSmeSm->hScr, SCR_GID_IDLE );

	return OK;
}

/* SELECT */ 
static TI_STATUS scan_to_select(void *pData)
{
	smeSm_t 		*pSmeSm = (smeSm_t *)pData;

	if (!pSmeSm->connectEnabled)
	{
		return smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_SELECT_FAILURE, pSmeSm);
	}

	siteMgr_resetAttemptsNumberParameter(pSmeSm->hSiteMgr);

	return siteMgr_selectSite(pSmeSm->hSiteMgr);
}



/* START_TX, CONNECT */ 
static TI_STATUS select_to_connect(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;
    paramInfo_t param;

	/* From this moment forward we will send DisAssociation event even if the connection failed */
	pSmeSm->bSendDisAssocEvent = TRUE;

    /* if we are about o start an IBSS, the conn SM will wait for few seconds before sending connection
       failure indication, so that the SME will rescan for IBSSes with the same SSID. To enable application
       scan during this period, in this case ONLY we change here the SCR group ID to inter scan */
   	param.paramType = CONN_TYPE_PARAM;
	conn_getParam(pSmeSm->hConn, &param);
	if (CONNECTION_SELF == param.content.connType)
	{
        /* Set SCR group to inter-scan */
        scr_setGroup( pSmeSm->hScr, SCR_GID_INTER_SCAN );
	}

	/* Configure QoS manager not to renegotiate TSPECs as this is first time connection */
	return conn_start(pSmeSm->hConn, CONN_TYPE_FIRST_CONN, smeSm_reportConnStatus, pSmeSm, FALSE, FALSE);
}  




/* Stop the connecting and go to disconnecting */ 
static TI_STATUS connecting_To_Disconnecting(void *pData)
{
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	conn_stop(pSmeSm->hConn, DISCONN_TYPE_DEAUTH, STATUS_UNSPECIFIED,
					   TRUE, smeSm_reportConnStatus, pSmeSm);

	return OK;
}


/* Stop the connection and go to disconnecting */ 
static TI_STATUS connected_To_disconnecting(void *pData)
{
	TI_STATUS status;
	paramInfo_t		param;
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	scr_setGroup( pSmeSm->hScr, SCR_GID_CONNECT );

	param.paramType = SITE_MGR_CURRENT_BSS_TYPE_PARAM;
	siteMgr_getParam(pSmeSm->hSiteMgr, &param);
	
	if(param.content.siteMgrDesiredBSSType == BSS_INFRASTRUCTURE)
	{
		/* Call the AP connection to perform disconnect - If immidiateShutdownRequired is TRUE, no need to send DISASSOC frame */
		 status = apConn_stop(pSmeSm->hApConn, TRUE, pSmeSm->immediateShutdownRequired);
	}
	else 
	{
	    /* In IBSS disconnect is done directly with the connection SM */ 
		status = conn_stop(pSmeSm->hConn, DISCONN_TYPE_DEAUTH, STATUS_UNSPECIFIED,
						   TRUE, smeSm_reportConnStatus,pSmeSm);
		if (status != OK)
		{
			WLAN_REPORT_ERROR(pSmeSm->hReport, SME_SM_MODULE_LOG, ("SME status=%d, have to return (%d)\n",status,__LINE__));
			return status; 
		}
	}


	return OK;
}

/* RESET_ATTEMPTS_NUMBER, START_SITE_AGING, START_DATA_ALGO */ 
/* CONNECTING -> CONNECTED due to event CONN_SUCC */
static TI_STATUS connecting_to_connected(void *pData)
{
	TI_STATUS status;
	paramInfo_t	param;
	
	smeSm_t *pSmeSm = (smeSm_t *)pData;

	/* Reset the DisAssociation reason since the SME saves that last reason, and if a new connection was made and than aborted by
	   unspecified reason - no one will clear this value */
	pSmeSm->DisAssoc.mgmtStatus = STATUS_UNSPECIFIED;
	pSmeSm->DisAssoc.uStatusCode = 0;

	status = siteMgr_resetPrevPrimarySiteRssi(pSmeSm->hSiteMgr);
	if (status != OK)
      {
         WLAN_REPORT_ERROR(pSmeSm->hReport, SME_SM_MODULE_LOG, ("SME status=%d, have to return (%d)\n",status,__LINE__));
         return status; 
      }

	status = siteMgr_resetPrimarySiteAttemptsNumber(pSmeSm->hSiteMgr);
	if (status != OK)
      {
         WLAN_REPORT_ERROR(pSmeSm->hReport, SME_SM_MODULE_LOG, ("SME status=%d, have to return (%d)\n",status,__LINE__));
         return status; 
      }

	status = siteMgr_resetEventStatisticsHistory(pSmeSm->hSiteMgr);
	if (status != OK)
      {
         WLAN_REPORT_ERROR(pSmeSm->hReport, SME_SM_MODULE_LOG, ("SME status=%d, have to return (%d)\n",status,__LINE__));
         return status; 
      }
    

	param.paramType = SITE_MGR_CURRENT_BSS_TYPE_PARAM;
	siteMgr_getParam(pSmeSm->hSiteMgr, &param);
	if (param.content.siteMgrDesiredBSSType == BSS_INFRASTRUCTURE)
	{
		/* Start the AP connection */
		apConn_start(pSmeSm->hApConn, siteMgr_isThereValidSSID(pSmeSm->hSiteMgr));
	}

    /* Set SCR group to connected */
    scr_setGroup( pSmeSm->hScr, SCR_GID_CONNECTED );

#ifdef TI_DBG
	/* update statistics - scan attempts for connection histogran */
	if ( SCAN_ATTAMEPTS_HISTOGRAM_SIZE < pSmeSm->smeStats.currentNumberOfScanAttempts )
	{
		pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ SCAN_ATTAMEPTS_HISTOGRAM_SIZE - 1 ]++;
	}
	else
	{
		pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ pSmeSm->smeStats.currentNumberOfScanAttempts - 1 ]++;
	}
	pSmeSm->smeStats.currentNumberOfScanAttempts = 0;
#endif
    return OK; 
}



/* STOP_RX, STOP_TX, UPDATE_PRIMARY_SITE_FAIL_STATUS,  */ 
static TI_STATUS connecting_to_selecting(void *pData)
{
	TI_STATUS status;
	paramInfo_t	param;
    smeSm_t *pSmeSm = (smeSm_t *)pData;

	conn_stop(pSmeSm->hConn, DISCONN_TYPE_IMMEDIATE, STATUS_UNSPECIFIED,
			  TRUE, smeSm_reportConnStatus,pSmeSm); 

	/* Remove primary site */
	status = siteMgr_updatePrimarySiteFailStatus(pSmeSm->hSiteMgr, TRUE);
	if (status != OK)
      {
         WLAN_REPORT_ERROR(pSmeSm->hReport, SME_SM_MODULE_LOG, ("SME status=%d, have to return (%d)\n",status,__LINE__));
         return status; 
      }
	
	status = siteMgr_disSelectSite(pSmeSm->hSiteMgr);
	if (status != OK)
      {
         WLAN_REPORT_ERROR(pSmeSm->hReport, SME_SM_MODULE_LOG, ("SME status=%d, have to return (%d)\n",status,__LINE__));
         return status; 
      }

	/* If we are in IBSS mode we don't try to select another site */
	param.paramType = SITE_MGR_DESIRED_BSS_TYPE_PARAM;
	siteMgr_getParam(pSmeSm->hSiteMgr, &param);

	if(param.content.siteMgrDesiredBSSType == BSS_INDEPENDENT)
		return smeSm_reportSelectStatus(pSmeSm, (mgmtStatus_e)SELECT_STATUS_FAILURE);
	else
		return siteMgr_selectSite(pSmeSm->hSiteMgr);
}




static TI_STATUS chooseScanBand(smeSm_t* pSmeSm, radioBand_e *band)
{		
	paramInfo_t	param;

    param.paramType = SITE_MGR_DESIRED_DOT11_MODE_PARAM;
    siteMgr_getParam( pSmeSm->hSiteMgr, &param );

	/* if working in dual band, select band according to dualBandReScanFlag */
    if ( param.content.siteMgrDot11Mode == DOT11_DUAL_MODE )
    {
        *band = ( TRUE == pSmeSm->dualBandReScanFlag ? RADIO_BAND_5_0_GHZ : RADIO_BAND_2_4_GHZ);
    }	
    /* if not working in dual band, return site manager current band */
    else
    {
    	param.paramType = SITE_MGR_RADIO_BAND_PARAM;
	    siteMgr_getParam(pSmeSm->hSiteMgr, &param);
	    *band = pSmeSm->currBand = param.content.siteMgrRadioBand;
    }
	return OK;				
}



static TI_STATUS smeCallScan(void *pData)
{
    smeSm_t	*pSmeSm = (smeSm_t *)pData;
    paramInfo_t param;
	scan_Params_t* pScanParams = &(pSmeSm->scanParams);
	sme_scan_Params_t 	*pSmeScanParams;
	scan_normalChannelEntry_t *pChanEntry;
	int	chan, k;

	/* 
	 * Check in which band we are in and prepare the scan command.
	 */
    pScanParams->scanType = SCAN_TYPE_NORMAL_ACTIVE;
    pScanParams->Tid = 0;


    param.paramType = SITE_MGR_OPERATIONAL_MODE_PARAM;
    siteMgr_getParam( pSmeSm->hSiteMgr, &param );

    if ( DOT11_A_MODE == param.content.siteMgrDot11OperationalMode )
	{	
        pScanParams->band = RADIO_BAND_5_0_GHZ;
		pSmeScanParams  = &(pSmeSm->scanParamsA);
	}
    else
	{
         pScanParams->band = RADIO_BAND_2_4_GHZ;
		 pSmeScanParams  = &(pSmeSm->scanParamsBG);
	}

	 pScanParams->probeRequestRate 	= pSmeScanParams->probeRequestRate;
	 pScanParams->numOfChannels 		= pSmeScanParams->numOfChannels;
	 pScanParams->probeReqNumber 		= pSmeScanParams->probeReqNumber;

	 WLAN_REPORT_INFORMATION(pSmeSm->hReport, SME_SM_MODULE_LOG,  
					("Global Scan Params: Rate=0x%x, Prob#=%d, Channels#=%d\n",
					 pScanParams->probeRequestRate, pScanParams->probeReqNumber, 
					 pScanParams->numOfChannels));  

	 for( chan=0; chan < pScanParams->numOfChannels; chan++ )
	 {
		pChanEntry = &(pScanParams->channelEntry[chan].normalChannelEntry);
		
		/* Fill channel ID */
		pChanEntry->channel = pSmeScanParams->channelsList[chan];
		
		/* Set broadcast BSSID */
		for ( k = 0; k < 6; k++ ) pChanEntry->bssId.addr[ k ] = 0xff;

		/* Set min & max dwell time */
		pChanEntry->minChannelDwellTime = pSmeScanParams->minDwellTime;
		pChanEntry->maxChannelDwellTime = pSmeScanParams->maxDwellTime;

		/* Set up early termination params. */	
		pChanEntry->earlyTerminationEvent =  SCAN_DEFAULT_EARLY_TERMINATION_EVENT;
		pChanEntry->ETMaxNumOfAPframes = SCAN_DEFAULT_EARLY_TERMINATION_NUM_OF_FRAMES;
		
		/* Set desired tx power */ 
		pChanEntry->txPowerDbm = pSmeScanParams->txPowerDbm;

		WLAN_REPORT_INFORMATION(pSmeSm->hReport, SME_SM_MODULE_LOG,  
					("Chan %d: CH=%d , DwellTime Min=%d Max=%d, ET=%d, TxPowr=%d, \n",
					 chan,
					 pScanParams->channelEntry[chan].normalChannelEntry.channel,
					 pScanParams->channelEntry[chan].normalChannelEntry.minChannelDwellTime,
					 pScanParams->channelEntry[chan].normalChannelEntry.maxChannelDwellTime,
					 pScanParams->channelEntry[chan].normalChannelEntry.earlyTerminationEvent,
					 pScanParams->channelEntry[chan].normalChannelEntry.txPowerDbm));
	 } /* Channel list setting */


    /*
     * Set the desired SSID (if any)
     */
    param.paramType = SITE_MGR_DESIRED_SSID_PARAM;
    siteMgr_getParam( pSmeSm->hSiteMgr, &param );

    if ( utils_isAnySSID( &(param.content.siteMgrDesiredSSID) ) ) 
    {
        pScanParams->desiredSsid.len = 0;
    }
    else
    {
        pScanParams->desiredSsid.len = param.content.siteMgrDesiredSSID.len;
        os_memoryCopy( pSmeSm->hOs, (void *)pScanParams->desiredSsid.ssidString,
                       (void *)param.content.siteMgrDesiredSSID.ssidString,
                       param.content.siteMgrDesiredSSID.len );
    }



	/*
	 * Prepare scan complete's aging, by increasing the scanned sites 
	 * scan attemps counter. The counter will be checked upon scan complete,  
	 * and the sites with no update scan results will be dropped.   
	 */
	siteMgr_setNotReceivedParameter(pSmeSm->hSiteMgr, &(pScanParams->desiredSsid), pScanParams->band );

#ifdef TI_DBG
	/* scan results count statistics - nullify the count before starting scan */
	pSmeSm->smeStats.currentNumberOfScanResults = 0;
#endif

	/* 
	 * Set and send the scan command. 
	 */
    if (scanConcentrator_scan( pSmeSm->hScanCncn, SCAN_SCC_DRIVER, pScanParams ) != 
            SCAN_CRS_SCAN_RUNNING)
	{
    	/* imitate scan complete event if scan could not be performed.*/
		smeSm_SMEvent(&pSmeSm->state, SME_SM_EVENT_SCAN_COMPLETE, pSmeSm);
	}

	return OK;
}


static TI_STATUS actionUnexpected(void *pData) 
{
	smeSm_t	*pSmeSm = (smeSm_t *)pData; 
	
	WLAN_REPORT_SM(pSmeSm->hReport, SME_SM_MODULE_LOG,  ("State machine error, unexpected Event\n\n"));
	return OK;
}



static TI_STATUS actionNop(void *pData)
{
	return OK;
}



static TI_STATUS smeSm_changeBandParams(TI_HANDLE	hSmeSm, radioBand_e radioBand)
{
	paramInfo_t	param;
	smeSm_t *pSmeSm = (smeSm_t *)hSmeSm;

	/* change dot11 mode */
	param.paramType = SITE_MGR_OPERATIONAL_MODE_PARAM;
	if(radioBand == RADIO_BAND_2_4_GHZ)
		param.content.siteMgrDot11OperationalMode = DOT11_G_MODE;
	else
		param.content.siteMgrDot11OperationalMode = DOT11_A_MODE;

	siteMgr_setParam(pSmeSm->hSiteMgr, &param);
	
	param.paramType = SITE_MGR_RADIO_BAND_PARAM;
	param.content.siteMgrRadioBand = radioBand;
	siteMgr_setParam(pSmeSm->hSiteMgr, &param);
	
	siteMgr_setCurrentTable(pSmeSm->hSiteMgr, radioBand);
	
	/* configure hal with common core-hal parameters */
	whalCtrl_SetRadioBand(pSmeSm->hHalCtrl, radioBand);
	
	return OK;
}

/***********************************************************************
 *                        smeSm_startInterScanTimeout									
 ***********************************************************************
DESCRIPTION: Starts interscan timeout
                                                                                                   
INPUT:      hSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     OK on success, NOK otherwise

************************************************************************/
static TI_STATUS smeSm_startInterScanTimeout(TI_HANDLE hSmeSm)
{
	smeSm_t 		*pSmeSm = (smeSm_t *)hSmeSm;
	paramInfo_t		param;

	/* If the SME scan is disabled, (scan is performed by the application)
	 * don't start the inter scan timeout
	 */
	if (pSmeSm->scanEnabled == SCAN_DISABLED)
	{
		return OK;
	}

	if (pSmeSm->scanEnabled == SKIP_NEXT_SCAN) 
	{
		pSmeSm->scanEnabled = SCAN_ENABLED;
	}

	param.paramType = SITE_MGR_DESIRED_BSS_TYPE_PARAM;
	siteMgr_getParam(pSmeSm->hSiteMgr, &param);

	if (param.content.siteMgrDesiredBSSType == BSS_INDEPENDENT)
	{
		os_timerStart(pSmeSm->hOs, pSmeSm->interScanTimeoutTimer, IBSS_INTER_SCAN_PERIOD, FALSE);
	}
	else 
	{	
		os_timerStart(pSmeSm->hOs, pSmeSm->interScanTimeoutTimer, pSmeSm->interScanTimeout, FALSE);   
	}

	return OK;
}

/***********************************************************************
 *                        smeSm_stopInterScanTimeout									
 ***********************************************************************
DESCRIPTION: Stops scan timeout
                                                                                                   
INPUT:      hSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     OK on success, NOK otherwise

************************************************************************/
static TI_STATUS smeSm_stopInterScanTimeout(TI_HANDLE hSmeSm)
{
	smeSm_t *pSmeSm = (smeSm_t *)hSmeSm;

	os_timerStop(pSmeSm->hOs, pSmeSm->interScanTimeoutTimer);
	return OK;
}

/***********************************************************************
*                        smeSm_sendDisassociateEvent									
***********************************************************************
DESCRIPTION: Send disassociate event with the reason

INPUT:      pSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     

************************************************************************/
static void smeSm_sendDisassociateEvent(smeSm_t* pSmeSm)
{
	OS_802_11_DISASSOCIATE_REASON_T	eventReason;

	WLAN_REPORT_INFORMATION(pSmeSm->hReport, SME_SM_MODULE_LOG, 
		("%s uDissconnectType = %d, uStatusCode = %d\n",__FUNCTION__, pSmeSm->DisAssoc.mgmtStatus, pSmeSm->DisAssoc.uStatusCode));

	/* Convert reason to OS layer */
	switch(pSmeSm->DisAssoc.mgmtStatus)
	{
	case STATUS_UNSPECIFIED:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_UNSPECIFIED;
		break;
	case STATUS_AUTH_REJECT:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_AUTH_REJECT;
	    break;
	case STATUS_ASSOC_REJECT:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_ASSOC_REJECT;
	    break;
	case STATUS_SECURITY_FAILURE:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_SECURITY_FAILURE;
		break;
	case STATUS_AP_DEAUTHENTICATE:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_AP_DEAUTHENTICATE;
		break;
	case STATUS_AP_DISASSOCIATE:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_AP_DISASSOCIATE;
		break;
	case STATUS_ROAMING_TRIGGER:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_ROAMING_TRIGGER;
		break;
	default:
		eventReason.eDisAssocType = OS_DISASSOC_STATUS_UNSPECIFIED; 
	    break;
	}
	/* Use the same status code for OS */
	eventReason.uStatusCode		 = pSmeSm->DisAssoc.uStatusCode;

	EvHandlerSendEvent(pSmeSm->hEvHandler, IPC_EVENT_DISASSOCIATED, (UINT8*)&eventReason, sizeof(OS_802_11_DISASSOCIATE_REASON_T));

	/* Reset status after sending the event */
	pSmeSm->DisAssoc.mgmtStatus = STATUS_UNSPECIFIED;
	pSmeSm->DisAssoc.uStatusCode = 0;
}

#ifdef TI_DBG
/***********************************************************************
 *                        smeSm_resetStats									
 ***********************************************************************
DESCRIPTION: Reset SME statistics
                                                                                                   
INPUT:      hSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     

************************************************************************/
void smeSm_resetStats( TI_HANDLE hSmeSm )
{
	smeSm_t* pSmeSm = (smeSm_t*)hSmeSm;

	os_memoryZero( pSmeSm->hOs, &(pSmeSm->smeStats), sizeof(smeSmStats_t) );
}

/***********************************************************************
 *                        smeSm_printStats									
 ***********************************************************************
DESCRIPTION: Print SME statistics
                                                                                                   
INPUT:      hSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     

************************************************************************/
void smeSm_printStats( TI_HANDLE hSmeSm )
{
	smeSm_t* pSmeSm = (smeSm_t*)hSmeSm;

	WLAN_OS_REPORT(("----------------------- SME statistics -----------------------\n\n"));
	WLAN_OS_REPORT(("Scan attempts histogram:\n"));
	WLAN_OS_REPORT(("------------------------\n\n"));
	WLAN_OS_REPORT(("Attempts: %6d %6d %6d %6d %6d %6d %6d %6d\n", 1, 2, 3, 4, 5, 6, 7, 8));
	WLAN_OS_REPORT(("Count:    %6d %6d %6d %6d %6d %6d %6d %6d\n\n", pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 0 ],
					pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 1 ], pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 2 ],
					pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 3 ], pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 4 ],
					pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 5 ], pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 6 ],
					pSmeSm->smeStats.scanAttemptsForConnectionHistogram[ 7 ]));
	WLAN_OS_REPORT(("Scan result count histogram:\n"));
	WLAN_OS_REPORT(("----------------------------\n\n"));
	WLAN_OS_REPORT(("Results: %6d %6d %6d %6d %6d %6d %6d %6d\n", 0, 1, 2, 3, 4, 5, 6, 7));
	WLAN_OS_REPORT(("Scans:   %6d %6d %6d %6d %6d %6d %6d %6d\n\n", pSmeSm->smeStats.scanResulCountHistogram[ 0 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 1 ], pSmeSm->smeStats.scanResulCountHistogram[ 2 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 3 ], pSmeSm->smeStats.scanResulCountHistogram[ 4 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 5 ], pSmeSm->smeStats.scanResulCountHistogram[ 6 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 7 ]));
	WLAN_OS_REPORT(("Results: %6d %6d %6d %6d %6d %6d %6d %6d\n", 8, 9, 10, 11, 12, 13, 14, 15));
	WLAN_OS_REPORT(("Scans:   %6d %6d %6d %6d %6d %6d %6d %6d\n", pSmeSm->smeStats.scanResulCountHistogram[ 8 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 9 ], pSmeSm->smeStats.scanResulCountHistogram[ 10 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 11 ], pSmeSm->smeStats.scanResulCountHistogram[ 12 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 13 ], pSmeSm->smeStats.scanResulCountHistogram[ 14 ],
					pSmeSm->smeStats.scanResulCountHistogram[ 15 ]));
}

/***********************************************************************
 *                        smeSm_dbgPrintObject									
 ***********************************************************************
DESCRIPTION: Print the SME object
                                                                                                   
INPUT:      hSmeSm	-	SME SM handle.

OUTPUT:		

RETURN:     

************************************************************************/
void smeSm_dbgPrintObject( TI_HANDLE hSmeSm )
{
	smeSm_t *pSmeSm = (smeSm_t *)hSmeSm;

	WLAN_OS_REPORT(("Current SME State is <%s>\n",stateDesc[pSmeSm->state]));
}

#endif
Back to Top