summaryrefslogtreecommitdiff
path: root/util/iserial.c
blob: e183e5cc2ab9d96716557e9902356a32df6d2a92 (plain)
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
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
/*
 * tmconfig.c
 *
 * This tool sets up the serial EMP port for the Terminal Mode settings.
 *
 * Author:  Andy Cress  arcress at users.sourceforge.net
 * Copyright (c) 2002-2006 Intel Corporation. 
 * 
 * Options: 
 *  -b   Set serial port up for Basic Mode (fBMode)
 *  -B   Set baud rate for serial port
 *  -d   Disable serial port for IPMI use
 *  -f   Flow Control setting, default=1 (RTS/CTS)
 *  -r   Read-only, view serial port parameters
 *  -s   configure serial port for Shared Basic Mode & Remote Console
 *  -t   Configure serial port for shared Terminal Mode (TMode) & Console
 *  -u username  Set username for EMP TMode login (default is null user 1)
 *  -p password  Set password for EMP TMode login 
 *  -l   show LAN parameters also
 *  -m0  switch MUX to Normal baseboard operation
 *  -m1  switch MUX to BMC operation (BMode or TMode)
 *  -x   eXtra debug messages
 *  -f   special boot Flags
 *
 * Change Log:
 * 02/12/02 Andy Cress - created from pefconfig.c
 * 03/08/02 Andy Cress - added GET_USER_ACCESS to serial parameters shown
 * 03/11/02 Andy Cress - changed MUX param 8 value for -b
 * 03/13/02 Andy Cress - changed default behavior to be like -r,
 *                       added -c option to configure TMode
 * 03/15/02 Andy Cress v1.3 added bootflags
 * 04/12/02 Andy Cress v1.4 use always avail instead of shared mode
 *                          also, don't do boot flags if not specified
 * 07/02/02 Andy Cress v1.5 add more Usage, add -d option.
 * 07/25/02 Andy Cress v1.6 fixed passwd offset for fSetTMode (-c)
 * 08/02/02 Andy Cress v1.7 moved common ipmi_cmd() code to ipmicmd.c
 * 12/09/02 Andy Cress v1.8 make sure -d sets user1 to admin again,
 *                          combine -n/-t into -m for MUX,
 *                          fix -c to drop thru to SetTMode logic,
 *                          param 8 values changed,
 * 		            Dont SetUser for TMode unless -u,
 *                          use DCD & RTS/CTS for TMode. 
 * 12/12/02 Andy Cress v1.9  change access from 0x23 to 0x2b
 * 01/23/03 Andy Cress v1.10 decode UserAccess meanings
 * 01/29/03 Andy Cress v1.11 added MV OpenIPMI support
 * 07/31/03 Andy Cress v1.12 added -F to try force it
 * 09/10/03 Andy Cress v1.13 isolate ser_ch, add -n option to specify chan#,
 *                           abort if no serial channels
 * 05/05/04 Andy Cress v1.14 call ipmi_close before exit, added WIN32
 * 06/29/04 Andy Cress v1.15 added fSetPsw even if not fSetUser3
 * 11/01/04 Andy Cress v1.16 add -N / -R for remote nodes   
 * 11/23/04 Andy Cress v1.17 recompile with ipmignu.c changes
 * 01/31/05 Andy Cress v1.18 allow IPMI 2.0 versions
 * 03/18/05 Andy Cress v1.19 fix for -n, show the ser_ch it is using.
 * 05/19/05 Andy Cress v1.20 show 4 users if IPMI20
 * 06/13/05 Andy Cress v1.21 show multiple alert destinations
 * 08/10/05 Andy Cress v1.22 truncate extra string chars
 * 05/02/06 Andy Cress v1.23 add -B option for baud rate
 * 09/12/06 Andy Cress v1.26 use authmask to set Serial Param(2)
 * 09/29/06 Andy Cress v1.27 add -q for user number, add -f for Flow Control,
 *                           adjust Mode if known, clear SerialParam(3) if -d,
 *                           added ShowAccess if -r.
 */
/*M*
Copyright (c) 2002-2006, Intel Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

  a.. Redistributions of source code must retain the above copyright notice, 
      this list of conditions and the following disclaimer. 
  b.. 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. 
  c.. Neither the name of Intel Corporation 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.
 *M*/
#ifdef WIN32
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
#elif defined(DOS)
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#if defined(HPUX)
/* getopt is defined in stdio.h */
#elif defined(MACOS)
/* getopt is defined in unistd.h */
#include <unistd.h>
#else
#include <getopt.h>
#endif
#include <string.h>
#endif
#include "ipmicmd.h"
 
#define SELprintf          printf
#define SER_CH    4
#define LAN_CH    1
#define MAXCHAN   16
#define PSW_LEN  16   /*see also PSW_MAX=20 in ipmicmd.h*/
/* Note: The optional IPMI 2.0 20-byte passwords are not supported here,
 * due to back-compatibility issues. */

/* serial channel access values */
#define ALWAYS_AUTH   0x22
#define ALWAYS_NOAUTH 0x2A
#define SHARED_AUTH   0x23
#define SHARED_NOAUTH 0x2B

typedef struct
{
        unsigned short     record_id;
        uchar              record_type;
        int                timestamp;
        unsigned short     generator_id;
        uchar              evm_rev;         //event message revision
        uchar              sensor_type;
        uchar              sensor_number;
        uchar              event_trigger;
        uchar              event_data1;
        uchar              event_data2;
        uchar              event_data3;
}       SEL_RECORD;

typedef struct
{            /* See IPMI Table 19-3 */
        uchar              data[30];
}       SER_RECORD;

/*
 * Global variables 
 */
static char * progver   = "3.05";
static char * progname  = "iserial";
static int    vend_id = 0;
static int    prod_id = 0;
static char   fdebug    = 0;
static char   fpicmg    = 0;
static char   freadonly = 0;
static char   fdoanyway = 0;
static char   fSetUser3 = 0;     /* =1 set User3->admin and User1->user access*/
static char   fSetPsw   = 0;     /* =1 set Password to user parameter */
static char   fSetTMode = 0;     /* =1 configure for TMode */
static char   fBasebdOn = 0;     /* =1 only do MUX switch BMC -> Baseboard */
static char   fTModeOn  = 0;     /* =1 only do MUX switch Baseboard -> BMC */
static char   fBMode    = 0;     /* =1 do Basic mode config stuff */
static char   fShared   = 0;     /* =1 shared Basic mode & Remote console */
static char   fDisable  = 0;     /* =1 to disable serial port IPMI */
static char   fKnownMode = 0;    /* =0 if unknown, =1 if TMode, =2 if BMode */
static char   fgetlan    = 0;
static char   fnotshared = 0;    /* =1 if IPMI serial shared with OS/BIOS*/
static char   fconsoleonly = 0;  /* =1 BIOS console only, no serial mux */
static char   fIPMI20   = 0;	 /* =1 IPMI v2.0 or greater */
static char   fcanonical = 0;	 /* =1 IPMI v2.0 or greater */
static char   fuser1admin = 0;	 /* =1 if default user 1 should be admin */
static char   bdelim    = ':';
static char   bFlow     = 1;     /* Flow Control: 1=RTS/CTS, 0=none */
static char   inactivity = 0;    /* Inactivity Timeout (30 sec increments) */
static char   newbaud    = 0x07;  /* default = 19.2K */
static uchar  bootflags  = 16;    /* if < 16 use these bootflags */
static uchar  ser_ch     = SER_CH;
static uchar  lan_ch     = LAN_CH;  /* usu LAN 1 = 7 */
static uchar  ser_user   = 0x03;    /* if -u specified, configure user 3 */
static uchar  ser_access = 0x04;    /* user priv 4=Admin, 3=Operator, 2=User */
static uchar  usernum    = 0;       /* set non-zero to specify user number */
static uchar  useridx    = 0;       /* user number index for get/show*/
static uchar  max_users     = 5;    /* set in GetUserAccess() if unum==1 */
static uchar  enabled_users = 0;    /* set in GetUserAccess() if unum==1 */
static uchar  show_users    = 5;    /* set in GetUserAccess() if unum==1 */
static char rguser[16]   = "root";     /* default, settable via user param */
static char rgpasswd[PSW_LEN+1] = "password"; /* default, set via user param */

#define NLAN  27
static struct {
  int cmd;
  int sz;
  char desc[28];
} lanparams[NLAN] = {   /* see IPMI Table 19-4 */
 /*  0 */ { 0, 1, "Set in progress"},
 /*  1 */ { 1, 1, "Auth type support"},
 /*  2 */ { 2, 5, "Auth type enables"},
 /*  3 */ { 3, 4, "IP address"},
 /*  4 */ { 4, 1, "IP addr src"},  /* (DHCP/Static) */
 /*  5 */ { 5, 6, "MAC addr"},
 /*  6 */ { 6, 4, "Subnet mask"},
 /*  7 */ { 7, 3, "IPv4 header"},
 /*  8 */ { 8, 2, "Prim RMCP port "},
 /*  9 */ { 9, 2, "Sec RMCP port "},
 /* 10 */ {10, 1, "BMC grat ARP "},
 /* 11 */ {11, 1, "grat ARP interval"},
 /* 12 */ {12, 4, "Def gateway IP"},
 /* 13 */ {13, 6, "Def gateway MAC"},
 /* 14 */ {14, 4, "Sec gateway IP"},
 /* 15 */ {15, 6, "Sec gateway MAC"},
 /* 16 */ {16,18, "Community string"},
 /* 17 */ {17, 1, "Num dest"},
 /* 18 */ {18, 5, "Dest type"},
 /* 19 */ {19, 13, "Dest address"},
 /* 20 */ {96, 28, "OEM Alert String"},
 /* 21 */ {97,  1, "Alert Retry Algorithm"},
 /* 22 */ {98,  3, "UTC Offset"},
 /* 23 */ {192, 4, "DHCP Server IP"},
 /* 24 */ {193, 6, "DHCP MAC Address"},
 /* 25 */ {194, 1, "DHCP Enable"},
 /* 26 */ {201, 2, "Channel Access Mode (Lan)"}
};

/* Special temp ids for other serial commands that aren't serial params */
#define CMDID_CA1   201  /*this is the first temp id*/
#define CMDID_UA1   202
#define CMDID_UA2   203
#define CMDID_UA3   204
#define CMDID_UA4   205
#define CMDID_MUX   210
#define CMDID_BOOT  211
#define NSER  28   /* was 32 */
static struct {
  int cmd;
  int sz;
  char desc[28];
} serparams[NSER] = {   /* see IPMI Table 20-4 */
 /*  0 */ { 0, 1, "Set in progress"},
 /*  1 */ { 1, 1, "Auth type support"},
 /*  2 */ { 2, 5, "Auth type enables"},
 /*  3 */ { 3, 1, "Connection Mode"},
 /*  4 */ { 4, 1, "Sess Inactiv Timeout"},
 /*  5 */ { 5, 5, "Channel Callback"},
 /*  6 */ { 6, 1, "Session Termination"},
 /*  7 */ { 7, 2, "IPMI Msg Comm"},
 /*  8 */ { 8, 2, "Mux Switch"},
 /*  9 */ { 9, 2, "Modem Ring Time"},
 /* 10 */ {10,17, "Modem Init String"},
 /* 11 */ {11, 5, "Modem Escape Seq"},
 /* 12 */ {12, 8, "Modem Hangup Seq"},
 /* 13 */ {13, 8, "Modem Dial Command"},
 /* 14 */ {14, 1, "Page Blackout Interval"},
 /* 15 */ {15,18, "Community String"},
 /* 16 */ {16, 1, "Num of Alert Dest"},
 /* 17 */ {17, 5, "Destination Info"},
 /* 18 */ {18, 1, "Call Retry Interval"},
 /* 19 */ {19, 3, "Destination Comm Settings"},
 /* 20 */ {20, 1, "Number Dial Strings"},
 /* 21 */ {21,33, "Dest Dial String"},
 /* 22 */ {22, 1, "Number Dest IP Addrs"},
 /* 23 */ {23, 5, "Dest IP Address"},
 /* 24 */ {29, 2, "Terminal Mode Config"},
 /* 25 */ {CMDID_MUX, 1,"Get Serial MUX Status"},
 /* 26 */ {CMDID_BOOT, 3,"Get Boot Options(3)"},
 /* 27 */ {CMDID_CA1, 2,"Channel Access Mode (Ser)"}
 /* 28 *% {CMDID_UA1, 4,""},  //"Get User Access (1)", */
 /* 29 *% {CMDID_UA2, 4,""},  //"Get User Access (2)", */
 /* 30 *% {CMDID_UA3, 4,""},  //"Get User Access (3)", */
 /* 31 *% {CMDID_UA4, 4,""}   //"Get User Access (4)"  */
};

static int GetDeviceID(SER_RECORD *pSerRecord)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	int status;
	uchar inputData[24];
	uchar completionCode;

	if (pSerRecord == NULL) return(-1);

        status = ipmi_cmd(GET_DEVICE_ID, inputData, 0, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
			SELprintf("GetDeviceID: completion code=%x\n", 
				completionCode); 
		} else {
			// dont copy first byte (Parameter revision, usu 0x11)
			memcpy(pSerRecord,&responseData[0],responseLength);
			set_mfgid(&responseData[0],responseLength);
			return(0);  // successful, done
		}
	}  /* endif */
	/* if get here, error */
 	return(-1);
}  /*end GetDeviceID() */

static int GetChanAcc(uchar chan, uchar parm, SER_RECORD *pSerRecord)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	int status;
	uchar inputData[24];
	uchar completionCode;

	if (pSerRecord == NULL) return(-1);
	responseLength = 3;
	inputData[0] = chan;
	inputData[1] = parm;  /* 0x80 = active, 0x40 = non-volatile */

        status = ipmi_cmd(GET_CHANNEL_ACC, inputData, 2, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
			SELprintf("GetChanAcc: completion code=%x\n", 
				completionCode); 
		} else {
			memcpy(pSerRecord,&responseData[0],responseLength);
			return(0);  // successful, done
		}
	}  /* endif */
	/* if get here, error */
 	return(-1);
}  /*GetChanAcc()*/

static int SetChanAcc(uchar chan, uchar parm, uchar val)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	int status;
	uchar inputData[24];
	uchar completionCode;

        /* parm: 0x80 = active, 0x40 = set non-vol*/
	responseLength = 1;
	inputData[0] = chan;  /* channel */
	inputData[1] = (parm & 0xc0) | (val & 0x3F); 
	if (chan == lan_ch) inputData[2] = 0x04;  /* LAN, don't set priv level*/
	else inputData[2] = (parm & 0xc0) | 0x04;  /* set Admin priv level */
                     /* serial defaults to 0x02 = User priv level */

        status = ipmi_cmd(SET_CHANNEL_ACC, inputData, 3, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
			SELprintf("SetChanAcc: completion code=%x\n", 
				completionCode); 
		} else {
			return(0);  // successful, done
		}
	}  /* endif */
	/* if get here, error */
 	return(-1);
}  /*SetChanAcc()*/

static int GetSerEntry(uchar subfunc, uchar bset, SER_RECORD *pSerRecord)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar inputData[24];
	int status;
	uchar completionCode;
	uchar chan; 

	if (pSerRecord == NULL)
	{
	   if (fdebug)
	       printf("GetSerEntry: error, output buffer is NULL\n");
 	   return (-1);
	}

        chan = ser_ch;  /* sample: 0=IPMB, 1=EMP/serial, 6=LAN2, 7=LAN1 */

	inputData[0]            = chan;  // flags, channel 3:0 (1=EMP)
	inputData[1]            = subfunc;  // Param selector 
	inputData[2]            = bset;  // Set selector 
	inputData[3]            = 0;  // Block selector
	if (subfunc == 10)  {  /*modem init string*/
	   inputData[3] = 1;  /*blocks start with 1*/
 	} else if (subfunc == 21) {
	   inputData[3] = 1;  /*blocks start with 1*/
	}

        status = ipmi_cmd(GET_SER_CONFIG, inputData, 4, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
		   if (completionCode == 0x80) 
			SELprintf("GetSerEntry(%d): Parameter not supported\n", 
				  subfunc); 
		   else
			SELprintf("GetSerEntry(%d): completion code=%x\n", 
				subfunc,completionCode); // responseData[0]);
		} else {
			// dont copy first byte (Parameter revision, usu 0x11)
			memcpy(pSerRecord,&responseData[1],responseLength-1);
			pSerRecord->data[responseLength-1] = 0;
			//successful, done
			return(0);
		}
	}

	// we are here because completionCode is not COMPLETION_CODE_OK
	if (fdebug) 
	     printf("GetSerEntry: ipmi_cmd status=%d, completion code=%d\n",
                          status,completionCode);
 	return -1;
}

static int SetSerEntry(uchar subfunc, SER_RECORD *pSerRecord, int reqlen)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar inputData[24];
	int status;
	uchar completionCode;

	if (pSerRecord == NULL)
	{
	   if (fdebug)
	       printf("SetSerEntry(%d): error, input buffer is NULL\n",
		      subfunc);
 	   return (-1);
	}

	inputData[0]            = ser_ch;  // flags, channel 3:0 (EMP)
	inputData[1]            = subfunc;  // Param selector 
	memcpy(&inputData[2],pSerRecord,reqlen);

        status = ipmi_cmd(SET_SER_CONFIG, inputData, (uchar)(reqlen+2), 
		        responseData, &responseLength, &completionCode, fdebug);

	if (status == ACCESS_OK) {
		if( completionCode ) {
		   if (completionCode == 0x80) 
			SELprintf("SetSerEntry(%d): Parameter not supported\n", 
				  subfunc); 
		   else
			SELprintf("SetSerEntry(%d): completion code=%x\n", 
				subfunc, completionCode);
		} else {
			//successful, done
			return(0);
		}
	}

	// we are here because completionCode is not COMPLETION_CODE_OK
	if (fdebug) 
	     printf("SetSerEntry: ipmi_cmd status=%d, completion code=%d\n",
                          status,completionCode);
 	return -1;
}  /* end SetSerEntry() */

#ifdef NEEDED
int SerialIsOptional(uchar bparam)
{
   /* These Serial Parameters are for optional Modem/Callback functions. */
   uchar optvals[9] = { 5, 9, 10, 11, 12, 13, 14, 20, 21 };
   int rv = 0;
   int i;
   for (i = 0; i < sizeof(optvals); i++) {
      if (optvals[i] == bparam) { rv = 1; break; }
   }
   return(rv);
}
#endif

int SetMiscEntry(ushort icmd, SER_RECORD *pSerRecord, int reqlen)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar inputData[24];
	int status;
	uchar completionCode;

	if (pSerRecord == NULL) {
	   if (fdebug) printf("SetMiscEntry: error, input buffer is NULL\n");
 	   return (-1);
	}
	memcpy(&inputData[0],pSerRecord,reqlen);

        status = ipmi_cmd(icmd, inputData, (uchar)reqlen, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
			printf("SetMiscEntry(%04x): completion code=%x\n", 
				icmd,completionCode); 
		} else {  //successful
			if (responseLength > 1) {
			  // skip first byte (Parameter revision, usu 0x11)
			  memcpy(pSerRecord,&responseData[1],responseLength-1);
			  }
			return(0);
		}
	}

	// we are here because completionCode is not COMPLETION_CODE_OK
	if (fdebug) 
	     printf("SetMiscEntry: ipmi_cmd status=%d, completion code=%d\n",
                          status,completionCode);
 	return -1;
}  /* end SetMiscEntry() */

int GetMiscEntry(ushort icmd, SER_RECORD *pSerRecord, int reqlen)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar inputData[24];
	int status;
	uchar completionCode;

	if (pSerRecord == NULL) {
	   if (fdebug) printf("GetMiscEntry: error, output buffer is NULL\n");
 	   return (-1);
	}

	memcpy(&inputData[0],pSerRecord,reqlen);
        status = ipmi_cmd(icmd, inputData, (uchar)reqlen, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
		   if (completionCode == 0x80) 
			printf("GetMiscEntry(%d): Parameter not supported\n", 
				 icmd); 
		   else
			printf("GetMiscEntry(%d): completion code=%x\n", 
				icmd,completionCode); 
		} else {     //successful
			if (responseLength > 1) 
			  memcpy(pSerRecord,&responseData[0],responseLength);
			return(0);
		}
	}

	if (fdebug) 
	    printf("GetMiscEntry(%d): ipmi_cmd status=%d, completion code=%x\n",
                        icmd,status,completionCode);
 	return -1;
}  /* end GetMiscEntry() */

void ShowUserAccess(uchar unum, uchar c0, uchar c1, uchar c2, uchar c, 
			char *name)
{ 
	/* channel is always ser_ch */
	if (unum == 1 && !fcanonical) {
	   printf("Users: showing %d of max %d users (%d enabled)\n",
		show_users,max_users,enabled_users);
	}
	printf("Get User Access(%d)%c %02x %02x %02x %02x%c ",
			unum,bdelim,c0,c1,c2,c,bdelim);
	if (c & 0x10) printf("IPMI, ");
	c = (c & 0x0f);
	switch(c) {
			case 1:    printf("Callback"); break;
			case 2:    printf("User "); break;
			case 3:    printf("Operator"); break;
			case 4:    printf("Admin"); break;
			case 5:    printf("OEM "); break;
			case 0x0f: printf("No access"); break;
			default:   printf("Reserved"); 
	}
        printf(" (%s)\n",name);  
}

int GetUserAccess(uchar unum, uchar *rdata, char *name)
{
    int rv;
    /* rdata must be at least 2 bytes, and name must be at least 16 bytes */
    rdata[0] = ser_ch;  /* channel# */
    rdata[1] = unum;  /* user# */
    rv = GetMiscEntry(GET_USER_ACCESS, (SER_RECORD *)rdata, 2);
    if (rv == 0 && name != NULL) {
       name[0] = unum;  /* user# */
       rv = GetMiscEntry(GET_USER_NAME, (SER_RECORD *)name, 1);
       if (rv != 0) name[0] = 0;
       rv = 0;
    }
    if (unum == 1) { /*get max_users and enabled_users*/
        max_users = rdata[0] & 0x3f;
        enabled_users = rdata[1] & 0x3f;
        // if (enabled_users > show_users) show_users = enabled_users;
	if (show_users > max_users) show_users = max_users;
    }
    if (rv == 0) 
         ShowUserAccess(unum,rdata[0],rdata[1],rdata[2],rdata[3],name);
    else printf("Get User Access(%d): error %d\n",unum,rv);
    return(rv);
}

static int GetLanEntry(uchar subfunc, SER_RECORD *pSerRecord)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar inputData[24];
	int status;
	uchar completionCode;
	uchar chan; uchar bset;

	if (pSerRecord == NULL)
	{
	   if (fdebug)
	       printf("GetLanEntry: error, output buffer is NULL\n");
 	   return (-1);
	}

        chan = lan_ch;
	if (subfunc == 18 || subfunc == 19) bset = 1;  /* dest id = 1 */
	else bset = 0;

	inputData[0]            = chan;  // flags, channel 3:0 (LAN 1)
	inputData[1]            = subfunc;  // Param selector (3 = ip addr)
	inputData[2]            = bset;  // Set selector 
	inputData[3]            = 0;  // Block selector

        status = ipmi_cmd(GET_LAN_CONFIG, inputData, 4, responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
			SELprintf("GetLanEntry: completion code=%x\n", 
				completionCode); // responseData[0]);
		} else {
			// dont copy first byte (Parameter revision, usu 0x11)
			memcpy(pSerRecord,&responseData[1],responseLength-1);
			pSerRecord->data[responseLength-1] = 0;
			//successful, done
			return(0);
		}
	}

	// we are here because completionCode is not COMPLETION_CODE_OK
	if (fdebug) 
	     printf("GetLanEntry: ipmi_cmd status=%d, completion code=%d\n",
                          status,completionCode);
 	return -1;
}  /* end GetLanEntry() */

#ifdef NOT
static int SetLanEntry(uchar subfunc, SER_RECORD *pSerRecord, int reqlen)
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar inputData[24];
	int status;
	uchar completionCode;

	if (pSerRecord == NULL)
	{
	   if (fdebug)
	       printf("SetLanEntry: error, input buffer is NULL\n");
 	   return (-1);
	}

	inputData[0]            = lan_ch;  // flags, channel 3:0 (LAN 1)
	inputData[1]            = subfunc;  // Param selector (3 = ip addr)
	memcpy(&inputData[2],pSerRecord,reqlen);

        status = ipmi_cmd(SET_LAN_CONFIG,inputData,(uchar)(reqlen+2),responseData,
                        &responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK) {
		if( completionCode ) {
			SELprintf("SetLanEntry: completion code=%x\n", 
				completionCode); // responseData[0]);
		} else {
			//successful, done
			return(0);
		}
	}

	// we are here because completionCode is not COMPLETION_CODE_OK
	if (fdebug) 
	     printf("SetLanEntry: ipmi_cmd status=%d, completion code=%d\n",
                          status,completionCode);
 	return -1;
}  /* end SetLanEntry() */
#endif

static int ReadSELinfo()
{
	uchar responseData[MAX_BUFFER_SIZE];
	int responseLength = MAX_BUFFER_SIZE;
	uchar completionCode;
	uchar inputData[6];
	int status;

        status = ipmi_cmd(GET_SEL_INFO, inputData, 0, responseData, 
			&responseLength, &completionCode, fdebug); 

	if (status == ACCESS_OK)
	{
		if (fdebug)
                  SELprintf("Code %d SEL Ver %d Support %d\n",
                          completionCode,
                          responseData[0],
                          responseData[13]
                          );
		//successful, done
		return(0);
	}
        else    return(1);

}  /*end ReadSELinfo()*/

#define NBAUDS  10
static struct {
       unsigned char val;
       char str[8];
    } mapbaud[NBAUDS] = {
       { 6,  "9600" },
       { 6,  "9.6K" },
       { 7,  "19.2K" },
       { 7,  "19200" },
       { 8,  "38.4K" },
       { 8,  "38400" },
       { 9,  "57.6K" },
       { 9,  "57600" },
       { 10, "115.2K" },
       { 10, "115200" }
    };

static unsigned char Str2Baud(char * str)
{
   unsigned char baud = 0;
   int i, n, len;
   len = (int)strlen(str);
   for (i = 0; i < len; i++)  /*toupper*/
      if (str[i] >= 'a' && str[i] <= 'z') str[i] &= 0x5F;
   for (i = 0; i < NBAUDS; i++) {
       n = (int)strlen(mapbaud[i].str);
       if (strncmp(str,mapbaud[i].str,n) == 0) {
           baud = mapbaud[i].val;
           break;
       }
   }
   if (i == NBAUDS || baud == 0) {
       printf("Invalid -B parameter value (%s), using 19.2K.\n",str);
       i = 1; /* default is 19.2K */
       baud = mapbaud[i].val; /* =7 */
   }
   if (fdebug) printf("new baud = %02x (%s)\n",baud,mapbaud[i].str);
   return(baud);
}

static char *Baud2Str(unsigned char bin)
{
    char *baudstr;
    unsigned char b;
    b = bin & 0x0f;
    switch(b) {
	case 6:  baudstr = "9600 "; break;
	case 7:  baudstr = "19.2k"; break;
	case 8:  baudstr = "38.4k"; break;
	case 9:  baudstr = "57.6k"; break;
	case 10: baudstr = "115.2k"; break;
	default: baudstr = "nobaud";
    }
    return(baudstr);
}

void ShowChanAccess(uchar chan, char *tag, uchar access, uchar access2)
{
    printf("Channel Access Mode(%d=%s)%c %02x %02x %c ",
		chan,tag,bdelim,access,access2,bdelim);
    switch (access & 0x03) {
        case 0: printf("Access = Disabled, ");     break;
        case 1: printf("Access = Pre-Boot, ");     break;
        case 2: printf("Access = Always Avail, "); break;
        case 3: printf("Access = Shared, ");       break;
        default:  break;
    }
    if (access & 0x20) printf("PEF Alerts Disabled\n"); /*0*/
    else printf("PEF Alerts Enabled\n");   /*1*/
}

static int valid_priv(int c)
{
	int rv;
	switch(c) {
		case 1:  
		case 2:  
		case 3:   
		case 4:   
		case 5:   
		case 0x0f:
			rv = 1; break;
		default:   
			rv = 0; break;
	}
	return(rv);
}

#ifdef METACOMMAND
int i_serial(int argc, char **argv)
#else
#ifdef WIN32
int __cdecl
#else
int
#endif
main(int  argc, char **argv)
#endif
{
   int ret;
   SER_RECORD SerRecord;
   char uname[16];
   int i, idx;
   int c;
   int rlen;
   uchar iData[2];
   uchar rData[10];
   uchar cc;
   int j;
   uchar bset;
   uchar nalert, ndial, ndest;
   uchar ialert, idial, idest;
   uchar authmask = 0;
   char mystr[80];

   // progname = argv[0];
   printf("%s ver %s \n",progname,progver);

   if (argc <= 1) freadonly = 1;  /* default to readonly if no options */

   while ( (c = getopt( argc, argv,"abcdef:gi:lm:n:p:#:q:rstu:v:xB:F:T:V:J:EYP:N:R:U:X:Z:?")) != EOF ) 
      switch(c) {
          case 'x': fdebug = 1;     break;
          case 'r': freadonly = 1;  break;
          case 'l': fgetlan = 1;    break;
          case 'd': fDisable = 1; freadonly = 0;  break;
          case 'a': fcanonical = 1;  /* canonical mode with delimeter */
		    bdelim = BDELIM; break;
          case 'c':                  /* configure Terminal Mode & Console */
          case 't': fSetTMode = 1;         /* set Terminal Mode & Console */
                    freadonly = 0; break; 
          case 'e': fSetTMode = 1;         /* set Terminal Mode not shared*/
		    fnotshared = 1;        /* no BIOS console, not shared */
                    freadonly = 0; break; 
          case 'g': fSetTMode = 1;         /* set Terminal Mode, but BCR only */
		    fconsoleonly = 1;      /* BIOS console only, disable mux */
                    freadonly = 0; break; 
          case 'b': fBMode = 1;            /* set Basic Mode only */
                    freadonly = 0; break; 
          case 's': fBMode = 1;            /* set Basic Mode & Console */
		    fShared = 1; freadonly = 0;
		    break;
          case 'f': i = atoi(optarg);  /*flow control*/
                    if (i >= 0 && i < 2) bFlow = (uchar)i;
                    break;
          case 'i': i = atoi(optarg);    /*inactivity timeout*/
                    if (i > 0 && i < 30) inactivity = 1;
                    else inactivity = i / 30;
                    break;
          case 'B': newbaud = Str2Baud(optarg);  break;
          case 'm': 		    /* set MUX to specific value */
		    i = atoi(optarg);
		    if (fdebug) printf("MUX Mode %d\n",i);
		    switch(i) {
			case 0: fBasebdOn = 1; break;
			case 1: fTModeOn = 1;  break;
			default: fBasebdOn = 1;
		    }
		    break;
          case 'u': 
		    strncpy(rguser,optarg,16);
		    rguser[15] = 0;
		    /* Use specified user #3, and set user 1 to not admin */
		    fSetUser3 = 1; 
		    break;
          case 'p': 
		    strncpy(rgpasswd,optarg,PSW_LEN);
		    rgpasswd[PSW_LEN] = 0;
		    fSetPsw = 1;
                    /* Hide password from 'ps' */
                    memset(optarg, ' ', strlen(optarg));
		    break;
          case 'q': 
          case '#': 
		    usernum = atob(optarg);
                    if (usernum > 15) usernum = 0;  /*MAX_IPMI_USERS = 4*/
		    break;
          case 'n': 
		    ser_ch = atob(optarg);
		    if (ser_ch > MAXCHAN) ser_ch = SER_CH; /*default=1*/
		    break;
          case 'v':    /*user privilege level access */
		    i = atoi(optarg);
		    if (valid_priv(i)) ser_access = i & 0x0f;
		    else printf("Invalid privilege -v %d, using Admin\n",i);
		    break;
          case 'X': 
		    bootflags = atob(optarg);
		    fdoanyway = 1;   /* undocumented, for test only */
		    break;
          case 'N':    /* nodename */
          case 'U':    /* remote username */
          case 'P':    /* remote password */
          case 'R':    /* remote password */
          case 'E':    /* get password from IPMI_PASSWORD environment var */
          case 'F':    /* force driver type */
          case 'T':    /* auth type */
          case 'J':    /* cipher suite */ 
          case 'V':    /* priv level */
          case 'Y':    /* prompt for remote password */
          case 'Z':    /* set local MC address */
                parse_lan_options(c,optarg,fdebug);
                break;
	  default:
                printf("Usage: %s [-bcdefglmnq#rstxB -u user -p passwd -NUPREFTVY]\n",progname);
		printf("   -b   configure serial port for Basic Mode\n");
		printf("   -c   Configure serial port for shared Terminal Mode & Console\n");
		printf("   -d   Disable serial port for IPMI use.\n");
		printf("   -e   configure serial port for Terminal Mode only\n");
		printf("   -f0  Flow control:  0=none, 1=RTS/CTS(default)\n");
		printf("   -g   configure serial port for console only, with BMode CTS\n");
		printf("   -s   configure serial port for Shared Basic Mode & Remote Console\n");
		printf("   -l   show some LAN parameters also\n");
		printf("   -m0  switch MUX to Normal baseboard operation\n");
		printf("   -m1  switch MUX to BMC operation (BMode or TMode)\n");
		printf("   -B bval      set Baud to bval for serial port\n");
		printf("   -n ser_chan  serial channel Number (default=1)\n");
		printf("   -p password  set Password for EMP TMode login\n");
		printf("   -u username  set Username for EMP TMode login\n");
                printf("   -q/-#        User number of Username for EMP\n"); 
		printf("   -r   Read-only, view serial port parameters (default)\n");
		printf("   -t   Configure serial port for shared Terminal Mode & Console (same as -c)\n");
		printf("   -v4  access priVilege: 4=Admin, 3=Operator, 2=User\n");
		printf("   -x   eXtra debug messages\n");
		print_lan_opt_usage(0);
                ret = ERR_USAGE;
		goto do_exit;
      }

   if (is_remote() && !freadonly) parse_lan_options('V',"4",0);

   ret = GetDeviceID( &SerRecord);
   if (ret != 0) {
      goto do_exit;
   } else {
      uchar ipmi_maj, ipmi_min;
      uchar *devrec;
 
      devrec = &SerRecord.data[0];
      ipmi_maj = devrec[4] & 0x0f;
      ipmi_min = devrec[4] >> 4;
      vend_id = devrec[6] + (devrec[7] << 8) + (int)(devrec[8] << 16);
      prod_id = devrec[9] + (devrec[10] << 8);
      show_devid( devrec[2],  devrec[3], ipmi_maj, ipmi_min);
      if ((ipmi_maj == 0) || (ipmi_maj == 1 && ipmi_min < 5)) {
	 /* IPMI 0.9 and 1.0 dont support this. */
         printf("This system does not support EMP Terminal Mode.\n");
         if (!fdoanyway) {
            ret = LAN_ERR_NOTSUPPORT;
            goto do_exit;
         }
      }
      if (ipmi_maj >= 2) fIPMI20 = 1;
      /* Determine if Basic or Terminal Mode is supported by product id */
      if (vend_id == VENDOR_INTEL) { /*Intel*/
         switch(prod_id) {
            case 0x4311: fKnownMode = 1; break;  /*NSI2U,   BMode*/
            case 0x000C: fKnownMode = 1; break;  /*TSRLT2,  BMode*/
            case 0x0100: fKnownMode = 1; break;  /*Tiger2,  BMode*/
            case 0x001B: fKnownMode = 2; break;  /*TIGPR2U, TMode*/
            case 0x0022: fKnownMode = 2; break;  /*TIGI2U,  TMode*/
            case 0x0026: fKnownMode = 2; break;  /*Alcolu,  TMode*/
            case 0x0028: fKnownMode = 2; break;  /*Alcolu,  TMode*/
            case 0x0811: fKnownMode = 2; break;  /*TIGW1U,  TMode*/
            case 0x003E: fKnownMode = 2;         /*NSN2U/CG2100, TMode*/
	        set_max_kcs_loops(URNLOOPS); /*longer KCS timeout*/
		break; 
            default:   break;
         }
      } else if (vend_id == VENDOR_NSC) { /*NSC*/
         if (prod_id == 0x4311) fKnownMode = 1;  /*TIGPT1U, No EMP*/
      } /* else   * other vend_id, leave defaults */
      if (fKnownMode > 0) {  
         /* Adjust if we know that the user set the wrong one. */
         if (fKnownMode == 1 && fSetTMode == 1) {
            printf("Adjusting from Terminal Mode to Basic Mode\n");
            fSetTMode = 0;  fBMode = 1; fShared = 1;
         } else if (fKnownMode == 2 && fBMode == 1) {
            printf("Adjusting from Basic Mode to Terminal Mode\n");
            fSetTMode = 1;  fBMode = 0;
         } 
      }
   }  /*end-else have device_id */

   ret = ipmi_getpicmg( &SerRecord.data[0], 16, fdebug);
   if (ret == 0) fpicmg = 1;

   ret = ReadSELinfo();
   if (ret == 0) {   /* talking to BMC ok */

      /* find the first Serial channel via Channel Info */
      for (j = 1; j < MAXCHAN; j++) {
        iData[0] = (uchar)j;  /*channel #*/
        rlen = sizeof(rData);
        ret = ipmi_cmd(GET_CHANNEL_INFO, iData, 1, rData, &rlen, &cc, 0); 
	if (ret != 0) break;
	if (rData[1] == 4) { 		/* 4 = LAN type*/
		if (fdebug) printf("chan[%d] = lan\n",j);
		lan_ch = (uchar)j;
	} else if (rData[1] == 5) {     /* 5 = Serial type*/
		if (fdebug) printf("chan[%d] = serial\n",j);
		if (ser_ch != SER_CH) { /* user set it */
		   if (j == ser_ch) break;
		} else {   /* find the first serial channel */
		   ser_ch = (uchar)j;
		   break;
		}
	} else  /* 7 = SMBus, 12 = System Interface */
		if (fdebug) printf("chan[%d] = %d\n",j,rData[1]);
      }
      if (fdebug) printf("ser_ch = %d\n",ser_ch);
      if (j >= MAXCHAN) {
	  printf("No serial channel support found (channel %d)\n",ser_ch);
          ret = LAN_ERR_NOTSUPPORT;
          goto do_exit;
      }

      if (fdebug && fSetUser3 == 1)  
         printf("user %d/%d: username=%s, password=%p\n",
			usernum,ser_user, rguser,rgpasswd);

      if (fgetlan && !fcanonical) {
       int ival;
       printf("%s, GetLanEntry for channel %d ...\n",progname,lan_ch);
       for (idx = 0; idx < NLAN; idx++)
       {
	 ival = lanparams[idx].cmd;
         if (ival == 8 || ival == 9) continue;	  /* not implemented */
         if (ival >= 96 && ival <= 98) continue;  /* not implemented */
         if (ival == CMDID_CA1) {
             ret = GetChanAcc(lan_ch, 0x40, &SerRecord);
	 } else {
             ret = GetLanEntry((uchar)ival, &SerRecord);
	 }
         if (ret == 0) {    // Show the LAN record
            uchar * pc; int sz;
            pc = (uchar *)&SerRecord;
            sz = lanparams[idx].sz; 
            printf("Lan Param(%d) %s%c ",ival,lanparams[idx].desc,bdelim);
	    if (ival == 16) { printf("%s \n",pc);      /* string */
	    } else {  /* print results for others */
              for (i = 0; i < sz; i++) {
	  	if (ival == 3 || ival == 6 || ival == 12 || ival == 14 ||
		    ival == 192)
		   printf("%d ",pc[i]);      /* IP addresses in dec */
		else printf("%02x ",pc[i]);  /* show in hex */
		}
	      /* if (ival == 4) { pc[0]: 01 = static, 02 = DHCP } */
              printf("\n");
	    }
         } else  /* ret != 0 */
            printf("GetLanEntry(%d), ret = %d\n",ival,ret);
        }  /*end for*/
       } 

       printf("%s, GetSerEntry for channel %d ...\n",progname,ser_ch);
       nalert = 1; ialert = 1;
       ndial = 1;  idial = 1;
       ndest = 1;  idest = 1;
       for (idx = 0; idx < NSER; idx++) {
   	 int ival;
	 ival = serparams[idx].cmd;
         /* 
          * ival is either the Serial Param# or a temp id.
          * Do the appropriate Get command, based on ival.
          */
         if (ival == CMDID_CA1) {
             ret = GetChanAcc(ser_ch, 0x40, &SerRecord);
         } else if (ival == CMDID_UA1) {
	     useridx = 1;
             ret = GetUserAccess(useridx,(uchar *)&SerRecord,uname);
         } else if (ival == CMDID_UA2) {
	     useridx = 2;
             ret = GetUserAccess(useridx,(uchar *)&SerRecord,uname);
         } else if (ival == CMDID_UA3) {
	     useridx = 3;
             ret = GetUserAccess(useridx,(uchar *)&SerRecord,uname);
         } else if (ival == CMDID_UA4) {
	     useridx = 4;
	     if (fIPMI20 == 0) continue;  /* IPMI 1.5 only has 3 users */
             ret = GetUserAccess(useridx,(uchar *)&SerRecord,uname);
         } else if (ival == CMDID_MUX) {
	     SerRecord.data[0] = ser_ch;   /* channel 1 = EMP */
	     SerRecord.data[1] = 0x00;   /* just get MUX status */
             ret = SetMiscEntry(SET_SER_MUX, &SerRecord, 2);
         } else if (ival == CMDID_BOOT) {
	     SerRecord.data[0] = 0x03;   /* Boot Param 3 */
	     SerRecord.data[1] = 0x00;   /* Set Selector */
	     SerRecord.data[2] = 0x00;   /* %%%% */
             ret = GetMiscEntry(GET_BOOT_OPTIONS, &SerRecord, 3);
	 } else {
	     if (fcanonical) {
		switch(ival) {  /*only show certain parameters*/
		    case 3:
		    case 4:
		    case 6:
		    case 7:
		    case 8:
		    case 29:
			break;
		    default:
			continue; break;
		}
	     }
             if (vend_id == VENDOR_SUPERMICROX && ival == 8) continue;
             if (vend_id == VENDOR_SUPERMICRO && ival == 8) continue;
	     if (ival == 17 || ival == 19) bset = ialert;
	     else if (ival == 21)          bset = idial;
	     else if (ival == 23)          bset = idest;
	     else bset = 0;  /*default*/
             ret = GetSerEntry((uchar)ival, bset, &SerRecord);
	 }
         /* 
          * Now the Get command is done, check the status, and
          * show the raw output.
          */
         if (ret == 0) {    // Show the SER record
           uchar * pc; int sz;
           pc = (uchar *)&SerRecord;
           sz = serparams[idx].sz; 
           /* save some input data for later reuse */
	   if (ival == 16) nalert = pc[0];
	   else if (ival == 20) ndial = pc[0];
	   else if (ival == 22) ndest = pc[0];
           if (ival == CMDID_CA1)  ;
           else if (ival > CMDID_CA1) 
		printf("%s%c ",serparams[idx].desc,bdelim);
           else
	       printf("Serial Param(%d) %s%c ",ival,serparams[idx].desc,bdelim);
	   if (ival == 1) {  /* Auth Type support*/
                authmask = pc[0]; /* auth type support mask */
                mystr[0] = 0;
                if (authmask & 0x01) strcat(mystr,"None ");
                if (authmask & 0x02) strcat(mystr,"MD2 ");
                if (authmask & 0x04) strcat(mystr,"MD5 ");
                if (authmask & 0x10) strcat(mystr,"Pswd ");
                if (authmask & 0x20) strcat(mystr,"OEM ");
                printf("%02x %c %s\n",authmask,bdelim,mystr);
	        } 
           else if (ival == 10) {  /* modem init string */
		pc[sz] = 0;
		printf("%02x %s\n",pc[0],&pc[1]); 
		}
	   else if (ival == 21) {  /* modem dial string */
		pc[sz] = 0;
		printf("%02x %02x %s\n",pc[0],pc[1],&pc[2]); 
		}
	   else if ((ival >= 11 && ival <= 13) || ival == 15) {  /* strings */
		pc[sz] = 0;
		printf("%s\n",pc); 
		}
	   else if (ival == 23) {  /* Dest IP Address */
		printf("%02x %d %d %d %d\n", pc[0], /*dest index*/
			pc[1],pc[2],pc[3],pc[4]);
		}
	   else if (ival == CMDID_CA1) {  /* Channel Access */
                ShowChanAccess(ser_ch,"Ser",pc[0],pc[1]);
	        } 
	   else if (ival == CMDID_UA1 || ival == CMDID_UA2 || 
                     ival == CMDID_UA3 || ival == CMDID_UA4) {
                // ShowUserAccess(useridx,pc[0],pc[1],pc[2],pc[3],uname);
	        } /*endif UA*/
	   else   /* hex data */
           {
            for (i = 0; i < sz; i++) {
		printf("%02x ",pc[i]);  /* show in hex */
		}
            /* 
             * Raw hex data display is complete, now do post-processing. 
             * Interpret some hex data.
             */
            if (ival == 4) {  /* Session Inactivity Timeout */
		c = pc[0];
		if (c == 0) strcpy(mystr,"infinite");
		else sprintf(mystr,"%d sec",(c * 30));
                printf(" %c %s",bdelim,mystr);
	        } 
	    else if (ival == 7) {  /*IPMI Msg Comm*/
	      uchar v;
	      char *flow; char *dtr; char *baud;
	      v = pc[0] & 0xc0;
	      switch(v) {
		case 0x40: flow = "RTS/CTS"; break;
		case 0x80: flow = "XON/XOFF"; break;
		case 0x00: 
		default:   flow = "no_flow";
	      }
	      if ((pc[0] & 0x20) == 0) dtr="no_DTR";
	      else dtr = "DTR";
              baud = Baud2Str(pc[1]);
	      printf("%c %s, %s, %s",bdelim,flow,dtr,baud);
	    } 
	    else if (ival == 19) {  /*Dest Comm Settings*/
	      uchar v;
	      char *flow; char *baud;
	      uchar chsz,parity,stopb;
	      v = pc[1] & 0xc0;
	      switch(v) {
		case 0x40: flow = "RTS/CTS"; break;
		case 0x80: flow = "XON/XOFF"; break;
		case 0x00: 
		default:   flow = "no_flow";
	      }
	      if ((pc[1] & 0x10) == 0) stopb = 1;
	      else stopb = 2;
	      if ((pc[1] & 0x08) == 0) chsz = 8;
	      else chsz = 7;
	      v = pc[1] & 0x07; 
	      switch(v) {
		case 1:  parity = 'O'; break;
		case 2:  parity = 'E'; break;
		case 0:  
		default: parity = 'N';
	      }
              baud = Baud2Str(pc[2]);
	      printf("%c %s, %d%c%d, %s",bdelim,flow,chsz,parity,stopb,baud);
	    } 
#ifdef TEST
	    /* This MUX reading is volatile and may not be accurate */
            else if (ival == CMDID_MUX) {
		    if ((pc[0] & 0x01) == 1) printf("%c BMC",bdelim);
		    else printf("%c System",bdelim); /*BIOS*/
	    }
#endif
            printf("\n");
	   } /*end else hex*/
	 }  /*endif show*/
	 if (ival ==  17 || ival == 19) {   /* alert params */
            if (ialert < nalert) {
               ialert++;
               idx--;  /* repeat this param*/
            } else ialert = 1;
	 }
	 if (ival ==  21) {        /* dial param */
            if (idial < ndial) {
               idial++;
               idx--;  /* repeat this param*/
            } else idial = 1;
	 }
	 if (ival ==  23) {     /* dest param */
            if (idest < ndest) {
               idest++;
               idx--;  /* repeat this param*/
            } else idest = 1;
	 }
       }  /*end for(idx) serial params*/

       for (i = 1; i <= show_users; i++)
           ret = GetUserAccess((uchar)i,(uchar *)&SerRecord,uname);

       if (!freadonly) {    /* set serial channel parameters */
	uchar access;
	if (fBasebdOn) {  /* -m0 */
	 SerRecord.data[0] = ser_ch;   /* channel 1 = EMP */
	 SerRecord.data[1] = 0x03;   /* force switch to Baseboard */
         ret = SetMiscEntry(SET_SER_MUX, &SerRecord, 2);
         printf("SetSerialMux(System), ret = %d, value = %02x\n",
		ret,SerRecord.data[0]);
	} else if (fTModeOn) {  /* -m1 */
	 SerRecord.data[0] = ser_ch;   /* channel 1 = EMP */
	 SerRecord.data[1] = 0x04;   /* force switch to BMC for TMode */
         ret = SetMiscEntry(SET_SER_MUX, &SerRecord, 2);
         printf("SetSerialMux(BMC), ret = %d, value = %02x\n",
		ret,SerRecord.data[0]);

	} else if (fDisable) {  /* -d */
	 /*
          * DISABLE SERIAL CHANNEL ACCESS 
          */
         if (vend_id == VENDOR_INTEL && fuser1admin) {
	    /* First, make sure null user (1) has admin privileges again */
	    SerRecord.data[0] = 0x90 | ser_ch;   /*0x91*/
	    SerRecord.data[1] = 0x01; /*user 1*/
	    SerRecord.data[2] = ser_access;  /* usu 0x04 admin access*/
	    SerRecord.data[3] = 0x00; 
            ret = SetMiscEntry(SET_USER_ACCESS, &SerRecord, 4);
            printf("SetUserAccess(1/%02x), ret = %d\n",ser_access,ret);
	 }
         if (usernum != 0) {   /*disable usernum if specified*/
	    SerRecord.data[0] = 0x80 | ser_ch;   /*0x81*/
	    SerRecord.data[1] = usernum;
	    SerRecord.data[2] = 0x0F; /*No access*/
	    SerRecord.data[3] = 0x00; 
            ret = SetMiscEntry(SET_USER_ACCESS, &SerRecord, 4);
            printf("SetUserAccess(%d/none), ret = %d\n",usernum,ret);
         }
         ret = SetChanAcc(ser_ch, 0x80, 0x20); /*vol  access=disabled*/
         if (fdebug) printf("SetChanAcc(ser/disable), ret = %d\n",ret);
         ret = SetChanAcc(ser_ch, 0x40, 0x20); /*nvol access=disabled*/
         printf("SetChanAcc(ser/disable), ret = %d\n",ret);
         ret = GetChanAcc(ser_ch, 0x40, &SerRecord);
	 access = SerRecord.data[0];
         printf("GetChanAcc(ser/disable), ret = %d, new value = %02x\n",
		ret,access);
	 if ((vend_id != VENDOR_SUPERMICROX) &&
	     (vend_id != VENDOR_SUPERMICRO)) {
            /* Also disable the Serial Parameter 3: Connection Mode */
	    SerRecord.data[0] = 0x00; /* Connection Mode = none */
            ret = SetSerEntry(3, &SerRecord,1);
            printf("SetSerEntry(3/disable), ret = %d\n",ret);
	 }

	} else if (fSetTMode || fBMode) {
	 /*
	  * ENABLE SERIAL CHANNEL ACCESS
	  * Enable: configure everything for TMode and/or BMode 
          *
	  * Set Serial/EMP Channel Access
	  * Use serial channel in shared mode 
	  * 0x20 means alerting=off, disabled (system only)
	  * 0x22 means alerting=off, always avail
	  *      which would only show BMC messages, not OS messages
	  * 0x23 means alerting=off, always avail + shared + user-auth on
	  * 0x2A means alerting=off, always avail + user-auth off
	  * 0x2B means alerting=off, always avail + shared + user-auth off
	  * 0x0B means alerting=on,  always avail + shared + user-auth off
	  * SSU won't set 0x2B, but we need shared access mode.
	  */
	 if (fconsoleonly) {
	   access = ALWAYS_NOAUTH;  /*0x2A*/
	 } else if (fnotshared) {  /* serial IPMI, but no console (-e only) */
	   if (fSetTMode) access = ALWAYS_NOAUTH;  /*0x2A*/
	   else access = ALWAYS_AUTH;  /*0x22*/
	 } else {     /* shared with BIOS console, normal */
	   if (fSetTMode) access = SHARED_NOAUTH;  /*0x2B*/
	   else access = SHARED_AUTH;  /*0x23*/
	 }
         ret = SetChanAcc(ser_ch, 0x80, access);  
         if (fdebug) printf("SetChanAcc(ser/active), ret = %d\n",ret);
         ret = SetChanAcc(ser_ch, 0x40, access);
         printf("SetChanAcc(ser), ret = %d\n",ret);
         ret = GetChanAcc(ser_ch, 0x80, &SerRecord);
	 if (fdebug) {
	    access = SerRecord.data[0];
            printf("GetChanAcc(ser/active), ret = %d, new value = %02x\n",
		   ret,access);
	    }
         ret = GetChanAcc(ser_ch, 0x40, &SerRecord);
	 access = SerRecord.data[0];
         printf("GetChanAcc(ser), ret = %d, new value = %02x\n",
		ret,access);
         ShowChanAccess(ser_ch,"ser",access,SerRecord.data[1]);

	 /* Needed if (fSetTMode), otherwise extra. */
	 {
            /* auth types: pswd, MD5, MD2, none */
            if (authmask == 0) authmask = 0x17;
            SerRecord.data[0] = (0x16 & authmask); /*Callback level*/
            SerRecord.data[1] = (0x16 & authmask); /*User level    */
            SerRecord.data[2] = (0x16 & authmask); /*Operator level*/
            SerRecord.data[3] = (0x16 & authmask); /*Admin level   */
            SerRecord.data[4] = 0x00;         /*OEM level*/
	    ret = SetSerEntry(2, &SerRecord,5);
            printf("SetSerEntry(2), ret = %d\n",ret);
	 }
	 if (fconsoleonly) SerRecord.data[0] = 0x81; /*direct, Basic only */
	 else if (fBMode)  SerRecord.data[0] = 0x83; /*direct; PPP & Basic */
	 else        SerRecord.data[0] = 0x87; /*direct; TMode, PPP, Basic*/
	 if ((vend_id != VENDOR_SUPERMICROX) &&
	     (vend_id != VENDOR_SUPERMICRO)) {
            ret = SetSerEntry(3, &SerRecord,1);
            printf("SetSerEntry(3), ret = %d\n",ret);
         }
	 /* 
	  * BMode inactivity timeout = 2 (* 30 sec = 60 sec)
	  * TMode inactivity timeout = 0 (infinite)
	  */
	 if (fBMode) SerRecord.data[0] = 0x02;  
	 else        SerRecord.data[0] = inactivity;  /*usu 0, infinite*/
         ret = SetSerEntry(4, &SerRecord,1);
         printf("SetSerEntry(4), ret = %d\n",ret);
	 if ((vend_id != VENDOR_SUPERMICROX) &&
	     (vend_id != VENDOR_SUPERMICRO)) {
	   // SerRecord.data[0] = 0x02;  /* enable inactivity, ignore DCD */
	   SerRecord.data[0] = 0x03;  /* enable inactivity, enable DCD */
           ret = SetSerEntry(6, &SerRecord,1);
           printf("SetSerEntry(6), ret = %d\n",ret);
           /* flow control: 60=RTS/CTS+DTR, 20=none+DTR */
	   SerRecord.data[0] = (bFlow << 6) | 0x20;
	   SerRecord.data[1] = newbaud; /* baud default = 19.2K bps */
           ret = SetSerEntry(7, &SerRecord,2);
           printf("SetSerEntry(7) baud %s, ret = %d\n",Baud2Str(newbaud),ret);
	   if (fBMode) {
	     SerRecord.data[0] = 0x1e; /* mux 2way control, GetChanAuth, PPP */
	   } else {  /*TMode*/
	     // SerRecord.data[0] = 0x1e; /* mux 2way control,GetChanAuth,PPP */
	     SerRecord.data[0] = 0x16; /* mux 2way control, GetChanAuth,no PPP*/
				       /* 2way: <ESC>( and <ESC>Q */
	   }
	   if (fconsoleonly)
	     SerRecord.data[1] = 0x09; /* enable serial port sharing, hb=not */
	   else if (fBMode && !fShared)  /* Basic Mode and NOT shared */
	     SerRecord.data[1] = 0x0a; /* enable serial port sharing,heartbeat*/
	   else 
	     SerRecord.data[1] = 0x08; /* enable serial port sharing, hb=off */
           ret = SetSerEntry(8, &SerRecord,2);
           printf("SetSerEntry(8), ret = %d\n",ret);
         }

	 if (fSetUser3) {
           if (usernum == 0) usernum = ser_user;  /* user 3 */
	   /* 
	    * Set up admin user for Serial User (usu User# 3)
	    * Username: root
	    * Password: password
            *
	    * cmdtool 20 18 45 3 72 6F 6F 74 0 0 0 0 0 0 0 0 0 0 0 0
	    * cmdtool 20 18 47 3 2 70 61 73 73 77 6F 72 64 0 0 0 0 0 0 0 0
	    * cmdtool 20 18 47 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
	    */
	   SerRecord.data[0] = usernum;  /* user 3 */
	   memset(&SerRecord.data[1],0,16);
	   memcpy(&SerRecord.data[1],rguser,strlen(rguser));
           ret = SetMiscEntry(SET_USER_NAME, &SerRecord, 17);
           printf("SetUserName(%d), ret = %d\n",usernum,ret);
	   /* set password for user 3 */
	   SerRecord.data[0] = usernum; 
	   SerRecord.data[1] = 0x02; 
	   memset(&SerRecord.data[2],0,PSW_LEN);
	   memcpy(&SerRecord.data[2],rgpasswd,strlen(rgpasswd));
           ret = SetMiscEntry(SET_USER_PASSWORD, &SerRecord, 2+PSW_LEN);
             printf("SetUserPassword(%d,2), ret = %d\n",usernum,ret);
	   /* enable user 3 */
	   SerRecord.data[0] = usernum; 
	   SerRecord.data[1] = 0x01; 
	   memset(&SerRecord.data[2],0,PSW_LEN);
           ret = SetMiscEntry(SET_USER_PASSWORD, &SerRecord, 2+PSW_LEN);
           printf("SetUserPassword(%d,1), ret = %d\n",usernum,ret);
	   
	   /* Testing User #3 password */
	   // cmdtool 20 18 47 3 3 70 61 73 73 77 6F 72 64 0 0 0 0 0 0 0 0
	   SerRecord.data[0] = usernum; 
	   SerRecord.data[1] = 0x03; 
	   memset(&SerRecord.data[2],0,PSW_LEN);
	   memcpy(&SerRecord.data[2],rgpasswd,strlen(rgpasswd));
           ret = SetMiscEntry(SET_USER_PASSWORD, &SerRecord, 2+PSW_LEN);
           printf("SetUserPassword(%d,3), ret = %d\n",usernum,ret);
	   
	   /* Set User #3 access up w/ ADMIN privilege for serial channel */
	   // cmdtool 20 18 43 91 3 4 0
	   SerRecord.data[0] = 0x90 | ser_ch;   /*0x91*/
	   SerRecord.data[1] = usernum;  /* user 3 */
	   SerRecord.data[2] = ser_access; /*usu 0x04; Admin*/
	   SerRecord.data[3] = 0x00; 
           ret = SetMiscEntry(SET_USER_ACCESS, &SerRecord, 4);
           printf("SetUserAccess(%d/%02x), ret = %d\n",usernum,ser_access,ret);
	  
	  if (ipmi_reserved_user(vend_id,0x01) == 0) {
	   /* Set NULL user access up w/ USER privilege for serial channel */
	   // cmdtool 20 18 43 91 1 2 0    
	   SerRecord.data[0] = 0x90 | ser_ch;   /*0x91*/
	   SerRecord.data[1] = 0x01;  /* user 1 (default) */
	   SerRecord.data[2] = 0x02;  /* user privilege */
	   SerRecord.data[3] = 0x00; 
           ret = SetMiscEntry(SET_USER_ACCESS, &SerRecord, 4);
           printf("SetUserAccess(1/user), ret = %d\n",ret);
          }
	 } else {   
          /* No username specified, use NULL user 1 for Serial */
	  if (ipmi_reserved_user(vend_id,0x01) == 0) {
	   /* Set NULL user password, if specified */
	   if (fSetPsw) {
	     SerRecord.data[0] = 0x01;  /*user 1*/
	     SerRecord.data[1] = 0x02; 
	     memset(&SerRecord.data[2],0,PSW_LEN);
	     memcpy(&SerRecord.data[2],rgpasswd,strlen(rgpasswd));
             ret = SetMiscEntry(SET_USER_PASSWORD, &SerRecord, 2+PSW_LEN);
             printf("SetUserPassword(1,2), ret = %d\n",ret);
	     /* make sure user 1 is enabled */
	     SerRecord.data[0] = 0x01;  
	     SerRecord.data[1] = 0x01; 
	     memset(&SerRecord.data[2],0,PSW_LEN);
             ret = SetMiscEntry(SET_USER_PASSWORD, &SerRecord, 2+PSW_LEN);
             printf("SetUserPassword(1,1), ret = %d\n",ret);
	   }
	   /* Set NULL user access up w/ ADMIN privilege for serial channel */
	   // cmdtool 20 18 43 91 1 4 0    
	   SerRecord.data[0] = 0x90 | ser_ch;   /*0x91*/
	   SerRecord.data[1] = 0x01;   /* user 1 */
	   SerRecord.data[2] = ser_access; /* admin */
	   SerRecord.data[3] = 0x00; 
           ret = SetMiscEntry(SET_USER_ACCESS, &SerRecord, 4);
           printf("SetUserAccess(1/%02x), ret = %d\n",ser_access,ret);
	  }
	 }

	 if (fSetTMode) {
	   /*
	    * Set the TMode configuration:
	    *    Enable line editing
	    *    Delete seq = bksp-sp-bksp 
	    *    Enable echo 
	    *    Handshake (hb) = off
	    *    Output newline seq = CR-LF
	    *    Input newline seq = CR
	    */
	   if ((vend_id != VENDOR_SUPERMICROX) &&
	       (vend_id != VENDOR_SUPERMICRO)) {
#ifdef TEST
	     SerRecord.data[0] = 0xA6;    /* sets bit for volatile - wrong */
	     SerRecord.data[1] = 0x11;
             ret = SetSerEntry(29, &SerRecord,2);
#endif
	     SerRecord.data[0] = 0x66;
	     SerRecord.data[1] = 0x11;
             ret = SetSerEntry(29, &SerRecord,2);
             printf("SetSerEntry(29), ret = %d\n",ret);
           }

	   /* Force mux switch to the BMC and start talking... */
	   /* Set Serial/Modem Mux */
	   /* cmdtool 20 30 12 1 4 */
	   SerRecord.data[0] = ser_ch;   /* channel 1 = EMP */
	   SerRecord.data[1] = 0x02;   /* was 0x04 to force switch to BMC */
           i = SetMiscEntry(SET_SER_MUX, &SerRecord, 2);
           printf("SetSerialMux(BMC), ret = %d, value = %02x\n",
		i,SerRecord.data[0]);
	 } /*endif fSetTMode*/

	 else {   /* fBMode */ 
	   if (fShared) {
	     uchar bval;
	     /* workaround for BMC bug w BIOS Console Redirect */
	     SerRecord.data[0] = 0x03;   /* Boot Param 3 */
	     if (bootflags < 16) {   /* user specified a boot flag */
	        SerRecord.data[1] = bootflags; /* Flags */
	        bval = SerRecord.data[1];
                ret = SetMiscEntry(SET_BOOT_OPTIONS, &SerRecord, 2);
                printf("SetBootOptions(3), new value = %02x, ret = %d\n",
		    bval,ret);
	     }

	     /* Force mux switch to the Baseboard initially */
	     SerRecord.data[0] = ser_ch;   /* channel 1 = EMP */
	     SerRecord.data[1] = 0x03;   /* force switch to Baseboard */
             i = SetMiscEntry(SET_SER_MUX, &SerRecord, 2);
             printf("SetSerialMux(System), ret = %d, value = %02x\n",
	    	    i,SerRecord.data[0]);
	   } else {  /* not shared, BMode only */
	     /* Force mux switch to the BMC and start talking... */
	     SerRecord.data[0] = ser_ch;   /* channel 1 = EMP */
	     SerRecord.data[1] = 0x04;   /* 0x04 to force switch to BMC */
             i = SetMiscEntry(SET_SER_MUX, &SerRecord, 2);
             printf("SetSerialMux(BMC), ret = %d, value = %02x\n",
	 	    i,SerRecord.data[0]);
	   }
	 }  /*end-else BMode*/
        }  /*end-else Enable (not Disable) */
	else {  /*not enable or disable BMode/TMode */
	  if (!fcanonical)
	     printf("Please specify a configuration mode (b,d,e,m,s,t)\n");
	}
       }  /*endif not readonly */
   }  /* endif ok */
do_exit:
   ipmi_close_();
   // show_outcome(progname,ret); 
   return(ret);
}  /* end main()*/

/************************
DPC configuration stuff on serial.
16:25:08.165  outgoing: set system boot options[08] 20 00 E0 81 6C 08 02 02 07
16:25:08.165  outgoing: set system boot options[08] 20 00 E0 81 70 08 06 01 0B 28 11 02 45 1F 96 3C 84
16:25:08.165  outgoing: set system boot options[08] 20 00 E0 81 74 08 04 FF FF 01
16:25:08.165  outgoing: set system boot options[08] 20 00 E0 81 78 08 03 00 FC
16:25:08.245  INCOMING: SET SYSTEM BOOT OPTIONS[08] 81 04 7B 20 6C 08 -[00]- 6C
16:25:08.245  INCOMING: SET SYSTEM BOOT OPTIONS[08] 81 04 7B 20 70 08 -[00]- 68
16:25:08.245  outgoing: set system boot options[08] 20 00 E0 81 7C 08 05 80 00 4A 00 00 2C
16:25:08.255  outgoing: chassis control[02] 20 00 E0 81 80 02 03 FA
 ************************/
/* end iserial.c */