Browse Source

Add Chassis Indentify

zhangbo 4 years ago
commit
f5c9921491
100 changed files with 20681 additions and 0 deletions
  1. 8 0
      .gitignore
  2. 958 0
      GD32F450_BMC_BaseCode.busybox
  3. 235 0
      GD32F450_BMC_BaseCode.initramfs
  4. 400 0
      GD32F450_BMC_BaseCode.lds.STMDISCO
  5. 14 0
      Makefile
  6. 1 0
      README.md
  7. 38 0
      app/Makefile
  8. 49 0
      app/NCP81111_Config/Makefile
  9. 242 0
      app/NCP81111_Config/NCP81111_main.c
  10. BIN
      app/NCP81111_Config/ncp81111_cfg
  11. 49 0
      app/UpdateFirmware/Makefile
  12. 101 0
      app/UpdateFirmware/main.c
  13. 0 0
      app/UpdateFirmware/main.h
  14. BIN
      app/UpdateFirmware/updateFW_app
  15. 1036 0
      app/bmc/Api.c
  16. 54 0
      app/bmc/Api.h
  17. 35 0
      app/bmc/AuthChip/CM_BURNFUZE.c
  18. 41 0
      app/bmc/AuthChip/CM_DATA.c
  19. 184 0
      app/bmc/AuthChip/CM_GPA.c
  20. 61 0
      app/bmc/AuthChip/CM_GPA.h
  21. 353 0
      app/bmc/AuthChip/CM_I2C.c
  22. 125 0
      app/bmc/AuthChip/CM_I2C.h
  23. 48 0
      app/bmc/AuthChip/CM_I2C_L.h
  24. 190 0
      app/bmc/AuthChip/CM_LIB.h
  25. 78 0
      app/bmc/AuthChip/CM_NOPOWER.c
  26. 53 0
      app/bmc/AuthChip/CM_PASSWORD.c
  27. 34 0
      app/bmc/AuthChip/CM_RDCFG.c
  28. 29 0
      app/bmc/AuthChip/CM_RDCKSUM.c
  29. 27 0
      app/bmc/AuthChip/CM_RDFUZE.c
  30. 33 0
      app/bmc/AuthChip/CM_RDUSER.c
  31. 38 0
      app/bmc/AuthChip/CM_READ.c
  32. 13 0
      app/bmc/AuthChip/CM_RESETPSW.c
  33. 19 0
      app/bmc/AuthChip/CM_RESETSEC.c
  34. 22 0
      app/bmc/AuthChip/CM_RND.c
  35. 122 0
      app/bmc/AuthChip/CM_SECURE.c
  36. 70 0
      app/bmc/AuthChip/CM_SELECT.c
  37. 30 0
      app/bmc/AuthChip/CM_SETUSER.c
  38. 36 0
      app/bmc/AuthChip/CM_SRDUSER.c
  39. 35 0
      app/bmc/AuthChip/CM_SWRUSER.c
  40. 701 0
      app/bmc/AuthChip/CM_TEST.c
  41. 10 0
      app/bmc/AuthChip/CM_TRUE.c
  42. 38 0
      app/bmc/AuthChip/CM_WRCFG.c
  43. 33 0
      app/bmc/AuthChip/CM_WRCKSUM.c
  44. 33 0
      app/bmc/AuthChip/CM_WRITE.c
  45. 35 0
      app/bmc/AuthChip/CM_WRUSER.c
  46. 154 0
      app/bmc/BmcType.h
  47. 156 0
      app/bmc/ChassisTimer/ChassisTimerTask.c
  48. 14 0
      app/bmc/ChassisTimer/ChassisTimerTask.h
  49. 176 0
      app/bmc/Makefile
  50. 112 0
      app/bmc/OemFRU.c
  51. 195 0
      app/bmc/PendActionTask/PendActionTask.c
  52. 14 0
      app/bmc/PendActionTask/PendActionTask.h
  53. 1262 0
      app/bmc/Session.c
  54. 250 0
      app/bmc/Session.h
  55. 101 0
      app/bmc/SysTimer/TimerTask.c
  56. 7 0
      app/bmc/SysTimer/TimerTask.h
  57. 249 0
      app/bmc/Util.c
  58. 82 0
      app/bmc/Util.h
  59. BIN
      app/bmc/bmc_app
  60. 91 0
      app/bmc/encryption/AuthCode.c
  61. 15 0
      app/bmc/encryption/AuthCode.h
  62. 68 0
      app/bmc/encryption/MD.h
  63. 93 0
      app/bmc/encryption/MD2.c
  64. 70 0
      app/bmc/encryption/MD5.c
  65. 63 0
      app/bmc/encryption/MD5_128.c
  66. 23 0
      app/bmc/encryption/MD5_128.h
  67. 88 0
      app/bmc/encryption/md2.h
  68. 171 0
      app/bmc/encryption/md2_dgst.c
  69. 59 0
      app/bmc/encryption/md5.h
  70. 311 0
      app/bmc/encryption/md5c.c
  71. 270 0
      app/bmc/encryption/sha1.c
  72. 73 0
      app/bmc/encryption/sha1.h
  73. 824 0
      app/bmc/encryption/sha2.c
  74. 108 0
      app/bmc/encryption/sha2.h
  75. 501 0
      app/bmc/ipmb/IPMBIfc.c
  76. 7 0
      app/bmc/ipmb/IPMBIfc.h
  77. 44 0
      app/bmc/lan/Ciphertable.h
  78. 723 0
      app/bmc/lan/LANIfc.c
  79. 86 0
      app/bmc/lan/LANIfc.h
  80. 1224 0
      app/bmc/lan/RMCP+.c
  81. 73 0
      app/bmc/lan/RMCP+.h
  82. 1388 0
      app/bmc/lan/RMCP.c
  83. 103 0
      app/bmc/lan/RMCP.h
  84. 285 0
      app/bmc/main.c
  85. 127 0
      app/bmc/main.h
  86. 133 0
      app/bmc/message.c
  87. 30 0
      app/bmc/message.h
  88. 112 0
      app/bmc/msghndlr/App/App.c
  89. 19 0
      app/bmc/msghndlr/App/App.h
  90. 52 0
      app/bmc/msghndlr/App/AppDevice+.h
  91. 95 0
      app/bmc/msghndlr/App/AppDevice.h
  92. 3631 0
      app/bmc/msghndlr/App/AppDevice/AppDevice.c
  93. 417 0
      app/bmc/msghndlr/App/AppDevice/WDT.c
  94. 304 0
      app/bmc/msghndlr/App/IPMDevice/Firewall.c
  95. 53 0
      app/bmc/msghndlr/App/IPMDevice/Firewall.h
  96. 222 0
      app/bmc/msghndlr/App/IPMDevice/IPMDevice.c
  97. 72 0
      app/bmc/msghndlr/App/IPMDevice/IPMDevice.h
  98. 77 0
      app/bmc/msghndlr/App/WDT.h
  99. 73 0
      app/bmc/msghndlr/Bridge/Bridge.c
  100. 20 0
      app/bmc/msghndlr/Bridge/Bridge.h

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+app/goahead-3.6.5/build/
+*.uImage
+*.o
+*.kernel.STMDISCO
+*.gdb
+#ignore switch file
+*~
+*.swp

+ 958 - 0
GD32F450_BMC_BaseCode.busybox

@@ -0,0 +1,958 @@
+#
+# Automatically generated make config: don't edit
+# Busybox version: 1.17.0
+# Wed Aug  5 14:02:36 2020
+#
+CONFIG_HAVE_DOT_CONFIG=y
+
+#
+# Busybox Settings
+#
+
+#
+# General Configuration
+#
+# CONFIG_DESKTOP is not set
+# CONFIG_EXTRA_COMPAT is not set
+# CONFIG_INCLUDE_SUSv2 is not set
+# CONFIG_USE_PORTABLE_CODE is not set
+CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
+# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
+# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
+CONFIG_SHOW_USAGE=y
+CONFIG_FEATURE_VERBOSE_USAGE=y
+# CONFIG_FEATURE_COMPRESS_USAGE is not set
+# CONFIG_FEATURE_INSTALLER is not set
+# CONFIG_LOCALE_SUPPORT is not set
+# CONFIG_UNICODE_SUPPORT is not set
+# CONFIG_UNICODE_USING_LOCALE is not set
+# CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set
+CONFIG_SUBST_WCHAR=0
+CONFIG_LAST_SUPPORTED_WCHAR=0
+# CONFIG_UNICODE_COMBINING_WCHARS is not set
+# CONFIG_UNICODE_WIDE_WCHARS is not set
+# CONFIG_UNICODE_BIDI_SUPPORT is not set
+# CONFIG_UNICODE_NEUTRAL_TABLE is not set
+# CONFIG_UNICODE_PRESERVE_BROKEN is not set
+# CONFIG_LONG_OPTS is not set
+CONFIG_FEATURE_DEVPTS=y
+# CONFIG_FEATURE_CLEAN_UP is not set
+# CONFIG_FEATURE_UTMP is not set
+# CONFIG_FEATURE_WTMP is not set
+# CONFIG_FEATURE_PIDFILE is not set
+CONFIG_FEATURE_SUID=y
+# CONFIG_FEATURE_SUID_CONFIG is not set
+# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
+# CONFIG_SELINUX is not set
+# CONFIG_FEATURE_PREFER_APPLETS is not set
+CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
+CONFIG_FEATURE_SYSLOG=y
+CONFIG_FEATURE_HAVE_RPC=y
+
+#
+# Build Options
+#
+CONFIG_STATIC=y
+# CONFIG_PIE is not set
+CONFIG_NOMMU=y
+# CONFIG_BUILD_LIBBUSYBOX is not set
+# CONFIG_FEATURE_INDIVIDUAL is not set
+# CONFIG_FEATURE_SHARED_BUSYBOX is not set
+# CONFIG_LFS is not set
+CONFIG_CROSS_COMPILER_PREFIX="arm-uclinuxeabi-"
+CONFIG_EXTRA_CFLAGS="-mcpu=cortex-m3 -mthumb -Wl,-elf2flt=-s -Wl,-elf2flt=16384"
+
+#
+# Debugging Options
+#
+# CONFIG_DEBUG is not set
+# CONFIG_DEBUG_PESSIMIZE is not set
+# CONFIG_WERROR is not set
+CONFIG_NO_DEBUG_LIB=y
+# CONFIG_DMALLOC is not set
+# CONFIG_EFENCE is not set
+
+#
+# Installation Options
+#
+# CONFIG_INSTALL_NO_USR is not set
+CONFIG_INSTALL_APPLET_SYMLINKS=y
+# CONFIG_INSTALL_APPLET_HARDLINKS is not set
+# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
+# CONFIG_INSTALL_APPLET_DONT is not set
+# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
+# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
+# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
+CONFIG_PREFIX="./_install"
+
+#
+# Busybox Library Tuning
+#
+CONFIG_PASSWORD_MINLEN=6
+CONFIG_MD5_SIZE_VS_SPEED=2
+# CONFIG_FEATURE_FAST_TOP is not set
+CONFIG_FEATURE_ETC_NETWORKS=y
+CONFIG_FEATURE_EDITING=y
+CONFIG_FEATURE_EDITING_MAX_LEN=256
+# CONFIG_FEATURE_EDITING_VI is not set
+CONFIG_FEATURE_EDITING_HISTORY=16
+# CONFIG_FEATURE_EDITING_SAVEHISTORY is not set
+CONFIG_FEATURE_TAB_COMPLETION=y
+# CONFIG_FEATURE_USERNAME_COMPLETION is not set
+CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
+# CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set
+# CONFIG_FEATURE_NON_POSIX_CP is not set
+# CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set
+CONFIG_FEATURE_COPYBUF_KB=4
+# CONFIG_MONOTONIC_SYSCALL is not set
+CONFIG_IOCTL_HEX2STR_ERROR=y
+# CONFIG_FEATURE_HWIB is not set
+
+#
+# Applets
+#
+
+#
+# Archival Utilities
+#
+# CONFIG_FEATURE_SEAMLESS_XZ is not set
+# CONFIG_FEATURE_SEAMLESS_LZMA is not set
+# CONFIG_FEATURE_SEAMLESS_BZ2 is not set
+# CONFIG_FEATURE_SEAMLESS_GZ is not set
+# CONFIG_FEATURE_SEAMLESS_Z is not set
+# CONFIG_AR is not set
+# CONFIG_FEATURE_AR_LONG_FILENAMES is not set
+# CONFIG_FEATURE_AR_CREATE is not set
+# CONFIG_BUNZIP2 is not set
+# CONFIG_BZIP2 is not set
+# CONFIG_CPIO is not set
+# CONFIG_FEATURE_CPIO_O is not set
+# CONFIG_FEATURE_CPIO_P is not set
+# CONFIG_DPKG is not set
+# CONFIG_DPKG_DEB is not set
+# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
+# CONFIG_GUNZIP is not set
+# CONFIG_GZIP is not set
+# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
+# CONFIG_LZOP is not set
+# CONFIG_LZOP_COMPR_HIGH is not set
+# CONFIG_RPM2CPIO is not set
+# CONFIG_RPM is not set
+# CONFIG_TAR is not set
+# CONFIG_FEATURE_TAR_CREATE is not set
+# CONFIG_FEATURE_TAR_AUTODETECT is not set
+# CONFIG_FEATURE_TAR_FROM is not set
+# CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set
+# CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set
+# CONFIG_FEATURE_TAR_GNU_EXTENSIONS is not set
+# CONFIG_FEATURE_TAR_LONG_OPTIONS is not set
+# CONFIG_FEATURE_TAR_TO_COMMAND is not set
+# CONFIG_FEATURE_TAR_UNAME_GNAME is not set
+# CONFIG_FEATURE_TAR_NOPRESERVE_TIME is not set
+# CONFIG_FEATURE_TAR_SELINUX is not set
+# CONFIG_UNCOMPRESS is not set
+# CONFIG_UNLZMA is not set
+# CONFIG_FEATURE_LZMA_FAST is not set
+# CONFIG_LZMA is not set
+# CONFIG_UNXZ is not set
+# CONFIG_XZ is not set
+# CONFIG_UNZIP is not set
+
+#
+# Coreutils
+#
+# CONFIG_BASENAME is not set
+CONFIG_CAT=y
+CONFIG_DATE=y
+CONFIG_FEATURE_DATE_ISOFMT=y
+# CONFIG_FEATURE_DATE_NANO is not set
+# CONFIG_FEATURE_DATE_COMPAT is not set
+CONFIG_TEST=y
+# CONFIG_FEATURE_TEST_64 is not set
+# CONFIG_TR is not set
+# CONFIG_FEATURE_TR_CLASSES is not set
+# CONFIG_FEATURE_TR_EQUIV is not set
+# CONFIG_CAL is not set
+# CONFIG_CATV is not set
+# CONFIG_CHGRP is not set
+CONFIG_CHMOD=y
+# CONFIG_CHOWN is not set
+# CONFIG_FEATURE_CHOWN_LONG_OPTIONS is not set
+# CONFIG_CHROOT is not set
+# CONFIG_CKSUM is not set
+# CONFIG_COMM is not set
+CONFIG_CP=y
+# CONFIG_FEATURE_CP_LONG_OPTIONS is not set
+# CONFIG_CUT is not set
+# CONFIG_DD is not set
+# CONFIG_FEATURE_DD_SIGNAL_HANDLING is not set
+# CONFIG_FEATURE_DD_THIRD_STATUS_LINE is not set
+# CONFIG_FEATURE_DD_IBS_OBS is not set
+# CONFIG_DF is not set
+# CONFIG_FEATURE_DF_FANCY is not set
+# CONFIG_DIRNAME is not set
+# CONFIG_DOS2UNIX is not set
+# CONFIG_UNIX2DOS is not set
+# CONFIG_DU is not set
+# CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K is not set
+CONFIG_ECHO=y
+CONFIG_FEATURE_FANCY_ECHO=y
+# CONFIG_ENV is not set
+# CONFIG_FEATURE_ENV_LONG_OPTIONS is not set
+# CONFIG_EXPAND is not set
+# CONFIG_FEATURE_EXPAND_LONG_OPTIONS is not set
+CONFIG_EXPR=y
+CONFIG_EXPR_MATH_SUPPORT_64=y
+CONFIG_FALSE=y
+# CONFIG_FOLD is not set
+# CONFIG_FSYNC is not set
+# CONFIG_HEAD is not set
+# CONFIG_FEATURE_FANCY_HEAD is not set
+# CONFIG_HOSTID is not set
+# CONFIG_ID is not set
+# CONFIG_INSTALL is not set
+# CONFIG_FEATURE_INSTALL_LONG_OPTIONS is not set
+# CONFIG_LENGTH is not set
+# CONFIG_LN is not set
+# CONFIG_LOGNAME is not set
+CONFIG_LS=y
+CONFIG_FEATURE_LS_FILETYPES=y
+CONFIG_FEATURE_LS_FOLLOWLINKS=y
+CONFIG_FEATURE_LS_RECURSIVE=y
+CONFIG_FEATURE_LS_SORTFILES=y
+CONFIG_FEATURE_LS_TIMESTAMPS=y
+CONFIG_FEATURE_LS_USERNAME=y
+# CONFIG_FEATURE_LS_COLOR is not set
+# CONFIG_FEATURE_LS_COLOR_IS_DEFAULT is not set
+# CONFIG_MD5SUM is not set
+CONFIG_MKDIR=y
+# CONFIG_FEATURE_MKDIR_LONG_OPTIONS is not set
+CONFIG_MKFIFO=y
+CONFIG_MKNOD=y
+CONFIG_MV=y
+# CONFIG_FEATURE_MV_LONG_OPTIONS is not set
+# CONFIG_NICE is not set
+CONFIG_NOHUP=y
+# CONFIG_OD is not set
+CONFIG_PRINTENV=y
+CONFIG_PRINTF=y
+CONFIG_PWD=y
+# CONFIG_READLINK is not set
+# CONFIG_FEATURE_READLINK_FOLLOW is not set
+# CONFIG_REALPATH is not set
+CONFIG_RM=y
+# CONFIG_RMDIR is not set
+# CONFIG_FEATURE_RMDIR_LONG_OPTIONS is not set
+# CONFIG_SEQ is not set
+# CONFIG_SHA1SUM is not set
+# CONFIG_SHA256SUM is not set
+# CONFIG_SHA512SUM is not set
+CONFIG_SLEEP=y
+# CONFIG_FEATURE_FANCY_SLEEP is not set
+# CONFIG_FEATURE_FLOAT_SLEEP is not set
+# CONFIG_SORT is not set
+# CONFIG_FEATURE_SORT_BIG is not set
+# CONFIG_SPLIT is not set
+# CONFIG_FEATURE_SPLIT_FANCY is not set
+# CONFIG_STAT is not set
+# CONFIG_FEATURE_STAT_FORMAT is not set
+CONFIG_STTY=y
+# CONFIG_SUM is not set
+# CONFIG_SYNC is not set
+# CONFIG_TAC is not set
+CONFIG_TAIL=y
+CONFIG_FEATURE_FANCY_TAIL=y
+# CONFIG_TEE is not set
+# CONFIG_FEATURE_TEE_USE_BLOCK_IO is not set
+# CONFIG_TOUCH is not set
+CONFIG_TRUE=y
+# CONFIG_TTY is not set
+# CONFIG_UNAME is not set
+# CONFIG_UNEXPAND is not set
+# CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS is not set
+# CONFIG_UNIQ is not set
+CONFIG_USLEEP=y
+# CONFIG_UUDECODE is not set
+# CONFIG_UUENCODE is not set
+# CONFIG_WC is not set
+# CONFIG_FEATURE_WC_LARGE is not set
+# CONFIG_WHO is not set
+CONFIG_WHOAMI=y
+CONFIG_YES=y
+
+#
+# Common options for cp and mv
+#
+CONFIG_FEATURE_PRESERVE_HARDLINKS=y
+
+#
+# Common options for ls, more and telnet
+#
+CONFIG_FEATURE_AUTOWIDTH=y
+
+#
+# Common options for df, du, ls
+#
+CONFIG_FEATURE_HUMAN_READABLE=y
+# CONFIG_FEATURE_MD5_SHA1_SUM_CHECK is not set
+
+#
+# Console Utilities
+#
+# CONFIG_CHVT is not set
+# CONFIG_FGCONSOLE is not set
+# CONFIG_CLEAR is not set
+# CONFIG_DEALLOCVT is not set
+# CONFIG_DUMPKMAP is not set
+# CONFIG_KBD_MODE is not set
+# CONFIG_LOADFONT is not set
+# CONFIG_LOADKMAP is not set
+# CONFIG_OPENVT is not set
+# CONFIG_RESET is not set
+# CONFIG_RESIZE is not set
+# CONFIG_FEATURE_RESIZE_PRINT is not set
+# CONFIG_SETCONSOLE is not set
+# CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS is not set
+# CONFIG_SETFONT is not set
+# CONFIG_FEATURE_SETFONT_TEXTUAL_MAP is not set
+CONFIG_DEFAULT_SETFONT_DIR=""
+# CONFIG_SETKEYCODES is not set
+# CONFIG_SETLOGCONS is not set
+# CONFIG_SHOWKEY is not set
+# CONFIG_FEATURE_LOADFONT_PSF2 is not set
+# CONFIG_FEATURE_LOADFONT_RAW is not set
+
+#
+# Debian Utilities
+#
+# CONFIG_MKTEMP is not set
+# CONFIG_PIPE_PROGRESS is not set
+# CONFIG_RUN_PARTS is not set
+# CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS is not set
+# CONFIG_FEATURE_RUN_PARTS_FANCY is not set
+# CONFIG_START_STOP_DAEMON is not set
+# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
+# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
+# CONFIG_WHICH is not set
+
+#
+# Editors
+#
+# CONFIG_AWK is not set
+# CONFIG_FEATURE_AWK_LIBM is not set
+# CONFIG_CMP is not set
+# CONFIG_DIFF is not set
+# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
+# CONFIG_FEATURE_DIFF_DIR is not set
+# CONFIG_ED is not set
+# CONFIG_PATCH is not set
+# CONFIG_SED is not set
+CONFIG_VI=y
+CONFIG_FEATURE_VI_MAX_LEN=4096
+# CONFIG_FEATURE_VI_8BIT is not set
+CONFIG_FEATURE_VI_COLON=y
+CONFIG_FEATURE_VI_YANKMARK=y
+CONFIG_FEATURE_VI_SEARCH=y
+CONFIG_FEATURE_VI_USE_SIGNALS=y
+CONFIG_FEATURE_VI_DOT_CMD=y
+CONFIG_FEATURE_VI_READONLY=y
+CONFIG_FEATURE_VI_SETOPTS=y
+CONFIG_FEATURE_VI_SET=y
+CONFIG_FEATURE_VI_WIN_RESIZE=y
+CONFIG_FEATURE_VI_ASK_TERMINAL=y
+CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y
+CONFIG_FEATURE_ALLOW_EXEC=y
+
+#
+# Finding Utilities
+#
+CONFIG_FIND=y
+CONFIG_FEATURE_FIND_PRINT0=y
+CONFIG_FEATURE_FIND_MTIME=y
+CONFIG_FEATURE_FIND_MMIN=y
+CONFIG_FEATURE_FIND_PERM=y
+CONFIG_FEATURE_FIND_TYPE=y
+CONFIG_FEATURE_FIND_XDEV=y
+CONFIG_FEATURE_FIND_MAXDEPTH=y
+CONFIG_FEATURE_FIND_NEWER=y
+CONFIG_FEATURE_FIND_INUM=y
+CONFIG_FEATURE_FIND_EXEC=y
+CONFIG_FEATURE_FIND_USER=y
+CONFIG_FEATURE_FIND_GROUP=y
+CONFIG_FEATURE_FIND_NOT=y
+CONFIG_FEATURE_FIND_DEPTH=y
+CONFIG_FEATURE_FIND_PAREN=y
+CONFIG_FEATURE_FIND_SIZE=y
+CONFIG_FEATURE_FIND_PRUNE=y
+CONFIG_FEATURE_FIND_DELETE=y
+CONFIG_FEATURE_FIND_PATH=y
+CONFIG_FEATURE_FIND_REGEX=y
+# CONFIG_FEATURE_FIND_CONTEXT is not set
+CONFIG_FEATURE_FIND_LINKS=y
+CONFIG_GREP=y
+CONFIG_FEATURE_GREP_EGREP_ALIAS=y
+CONFIG_FEATURE_GREP_FGREP_ALIAS=y
+CONFIG_FEATURE_GREP_CONTEXT=y
+# CONFIG_XARGS is not set
+# CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION is not set
+# CONFIG_FEATURE_XARGS_SUPPORT_QUOTES is not set
+# CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT is not set
+# CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM is not set
+
+#
+# Init Utilities
+#
+# CONFIG_BOOTCHARTD is not set
+# CONFIG_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set
+# CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE is not set
+CONFIG_INIT=y
+CONFIG_FEATURE_USE_INITTAB=y
+CONFIG_FEATURE_KILL_REMOVED=y
+CONFIG_FEATURE_KILL_DELAY=0
+CONFIG_FEATURE_INIT_SCTTY=y
+# CONFIG_FEATURE_INIT_SYSLOG is not set
+# CONFIG_FEATURE_EXTRA_QUIET is not set
+# CONFIG_FEATURE_INIT_COREDUMPS is not set
+# CONFIG_FEATURE_INITRD is not set
+CONFIG_HALT=y
+# CONFIG_FEATURE_CALL_TELINIT is not set
+CONFIG_TELINIT_PATH=""
+# CONFIG_MESG is not set
+
+#
+# Login/Password Management Utilities
+#
+CONFIG_FEATURE_SHADOWPASSWDS=y
+# CONFIG_USE_BB_PWD_GRP is not set
+# CONFIG_USE_BB_SHADOW is not set
+# CONFIG_USE_BB_CRYPT is not set
+# CONFIG_USE_BB_CRYPT_SHA is not set
+# CONFIG_ADDGROUP is not set
+# CONFIG_FEATURE_ADDGROUP_LONG_OPTIONS is not set
+# CONFIG_FEATURE_ADDUSER_TO_GROUP is not set
+# CONFIG_DELGROUP is not set
+# CONFIG_FEATURE_DEL_USER_FROM_GROUP is not set
+# CONFIG_FEATURE_CHECK_NAMES is not set
+# CONFIG_ADDUSER is not set
+# CONFIG_FEATURE_ADDUSER_LONG_OPTIONS is not set
+CONFIG_FIRST_SYSTEM_ID=0
+CONFIG_LAST_SYSTEM_ID=0
+# CONFIG_DELUSER is not set
+# CONFIG_GETTY is not set
+CONFIG_LOGIN=y
+# CONFIG_PAM is not set
+# CONFIG_LOGIN_SCRIPTS is not set
+# CONFIG_FEATURE_NOLOGIN is not set
+# CONFIG_FEATURE_SECURETTY is not set
+# CONFIG_PASSWD is not set
+# CONFIG_FEATURE_PASSWD_WEAK_CHECK is not set
+# CONFIG_CRYPTPW is not set
+# CONFIG_CHPASSWD is not set
+# CONFIG_SU is not set
+# CONFIG_FEATURE_SU_SYSLOG is not set
+# CONFIG_FEATURE_SU_CHECKS_SHELLS is not set
+# CONFIG_SULOGIN is not set
+# CONFIG_VLOCK is not set
+
+#
+# Linux Ext2 FS Progs
+#
+# CONFIG_CHATTR is not set
+# CONFIG_FSCK is not set
+# CONFIG_LSATTR is not set
+# CONFIG_TUNE2FS is not set
+
+#
+# Linux Module Utilities
+#
+CONFIG_MODINFO=y
+# CONFIG_MODPROBE_SMALL is not set
+# CONFIG_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE is not set
+# CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set
+CONFIG_INSMOD=y
+CONFIG_RMMOD=y
+CONFIG_LSMOD=y
+CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT=y
+CONFIG_MODPROBE=y
+# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
+CONFIG_DEPMOD=y
+
+#
+# Options common to multiple modutils
+#
+# CONFIG_FEATURE_2_4_MODULES is not set
+# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
+# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
+# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
+# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
+# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
+# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
+CONFIG_FEATURE_CHECK_TAINTED_MODULE=y
+CONFIG_FEATURE_MODUTILS_ALIAS=y
+CONFIG_FEATURE_MODUTILS_SYMBOLS=y
+CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
+CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
+
+#
+# Linux System Utilities
+#
+# CONFIG_REV is not set
+# CONFIG_ACPID is not set
+# CONFIG_FEATURE_ACPID_COMPAT is not set
+# CONFIG_BLKID is not set
+# CONFIG_DMESG is not set
+# CONFIG_FEATURE_DMESG_PRETTY is not set
+# CONFIG_FBSET is not set
+# CONFIG_FEATURE_FBSET_FANCY is not set
+# CONFIG_FEATURE_FBSET_READMODE is not set
+# CONFIG_FDFLUSH is not set
+# CONFIG_FDFORMAT is not set
+# CONFIG_FDISK is not set
+# CONFIG_FDISK_SUPPORT_LARGE_DISKS is not set
+# CONFIG_FEATURE_FDISK_WRITABLE is not set
+# CONFIG_FEATURE_AIX_LABEL is not set
+# CONFIG_FEATURE_SGI_LABEL is not set
+# CONFIG_FEATURE_SUN_LABEL is not set
+# CONFIG_FEATURE_OSF_LABEL is not set
+# CONFIG_FEATURE_FDISK_ADVANCED is not set
+# CONFIG_FINDFS is not set
+# CONFIG_FLOCK is not set
+# CONFIG_FREERAMDISK is not set
+# CONFIG_FSCK_MINIX is not set
+# CONFIG_MKFS_EXT2 is not set
+# CONFIG_MKFS_MINIX is not set
+# CONFIG_FEATURE_MINIX2 is not set
+# CONFIG_MKFS_REISER is not set
+# CONFIG_MKFS_VFAT is not set
+# CONFIG_GETOPT is not set
+# CONFIG_FEATURE_GETOPT_LONG is not set
+# CONFIG_HEXDUMP is not set
+# CONFIG_FEATURE_HEXDUMP_REVERSE is not set
+# CONFIG_HD is not set
+# CONFIG_HWCLOCK is not set
+# CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS is not set
+# CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS is not set
+# CONFIG_IPCRM is not set
+# CONFIG_IPCS is not set
+# CONFIG_LOSETUP is not set
+# CONFIG_LSPCI is not set
+# CONFIG_LSUSB is not set
+# CONFIG_MDEV is not set
+# CONFIG_FEATURE_MDEV_CONF is not set
+# CONFIG_FEATURE_MDEV_RENAME is not set
+# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set
+# CONFIG_FEATURE_MDEV_EXEC is not set
+# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set
+# CONFIG_MKSWAP is not set
+# CONFIG_FEATURE_MKSWAP_UUID is not set
+# CONFIG_MORE is not set
+CONFIG_FEATURE_USE_TERMIOS=y
+CONFIG_VOLUMEID=y
+CONFIG_FEATURE_VOLUMEID_EXT=y
+CONFIG_FEATURE_VOLUMEID_BTRFS=y
+CONFIG_FEATURE_VOLUMEID_REISERFS=y
+CONFIG_FEATURE_VOLUMEID_FAT=y
+CONFIG_FEATURE_VOLUMEID_HFS=y
+CONFIG_FEATURE_VOLUMEID_JFS=y
+CONFIG_FEATURE_VOLUMEID_XFS=y
+CONFIG_FEATURE_VOLUMEID_NTFS=y
+CONFIG_FEATURE_VOLUMEID_ISO9660=y
+CONFIG_FEATURE_VOLUMEID_UDF=y
+CONFIG_FEATURE_VOLUMEID_LUKS=y
+CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
+CONFIG_FEATURE_VOLUMEID_CRAMFS=y
+CONFIG_FEATURE_VOLUMEID_ROMFS=y
+CONFIG_FEATURE_VOLUMEID_SYSV=y
+CONFIG_FEATURE_VOLUMEID_OCFS2=y
+CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
+CONFIG_MOUNT=y
+CONFIG_FEATURE_MOUNT_FAKE=y
+CONFIG_FEATURE_MOUNT_VERBOSE=y
+# CONFIG_FEATURE_MOUNT_HELPERS is not set
+CONFIG_FEATURE_MOUNT_LABEL=y
+CONFIG_FEATURE_MOUNT_NFS=y
+CONFIG_FEATURE_MOUNT_CIFS=y
+CONFIG_FEATURE_MOUNT_FLAGS=y
+CONFIG_FEATURE_MOUNT_FSTAB=y
+# CONFIG_PIVOT_ROOT is not set
+# CONFIG_RDATE is not set
+# CONFIG_RDEV is not set
+# CONFIG_READPROFILE is not set
+# CONFIG_RTCWAKE is not set
+# CONFIG_SCRIPT is not set
+# CONFIG_SCRIPTREPLAY is not set
+# CONFIG_SETARCH is not set
+# CONFIG_SWAPONOFF is not set
+# CONFIG_FEATURE_SWAPON_PRI is not set
+# CONFIG_SWITCH_ROOT is not set
+CONFIG_UMOUNT=y
+CONFIG_FEATURE_UMOUNT_ALL=y
+
+#
+# Common options for mount/umount
+#
+CONFIG_FEATURE_MOUNT_LOOP=y
+CONFIG_FEATURE_MOUNT_LOOP_CREATE=y
+# CONFIG_FEATURE_MTAB_SUPPORT is not set
+
+#
+# Miscellaneous Utilities
+#
+# CONFIG_CONSPY is not set
+# CONFIG_UBIATTACH is not set
+# CONFIG_UBIDETACH is not set
+# CONFIG_ADJTIMEX is not set
+# CONFIG_BBCONFIG is not set
+# CONFIG_BEEP is not set
+CONFIG_FEATURE_BEEP_FREQ=0
+CONFIG_FEATURE_BEEP_LENGTH_MS=0
+# CONFIG_CHAT is not set
+# CONFIG_FEATURE_CHAT_NOFAIL is not set
+# CONFIG_FEATURE_CHAT_TTY_HIFI is not set
+# CONFIG_FEATURE_CHAT_IMPLICIT_CR is not set
+# CONFIG_FEATURE_CHAT_SWALLOW_OPTS is not set
+# CONFIG_FEATURE_CHAT_SEND_ESCAPES is not set
+# CONFIG_FEATURE_CHAT_VAR_ABORT_LEN is not set
+# CONFIG_FEATURE_CHAT_CLR_ABORT is not set
+# CONFIG_CHRT is not set
+# CONFIG_CROND is not set
+# CONFIG_FEATURE_CROND_D is not set
+# CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
+CONFIG_FEATURE_CROND_DIR=""
+# CONFIG_CRONTAB is not set
+# CONFIG_DC is not set
+# CONFIG_FEATURE_DC_LIBM is not set
+# CONFIG_DEVFSD is not set
+# CONFIG_DEVFSD_MODLOAD is not set
+# CONFIG_DEVFSD_FG_NP is not set
+# CONFIG_DEVFSD_VERBOSE is not set
+# CONFIG_FEATURE_DEVFS is not set
+# CONFIG_DEVMEM is not set
+# CONFIG_EJECT is not set
+# CONFIG_FEATURE_EJECT_SCSI is not set
+# CONFIG_FBSPLASH is not set
+# CONFIG_FLASHCP is not set
+# CONFIG_FLASH_LOCK is not set
+# CONFIG_FLASH_UNLOCK is not set
+# CONFIG_FLASH_ERASEALL is not set
+# CONFIG_IONICE is not set
+# CONFIG_INOTIFYD is not set
+# CONFIG_LAST is not set
+# CONFIG_FEATURE_LAST_SMALL is not set
+# CONFIG_FEATURE_LAST_FANCY is not set
+# CONFIG_LESS is not set
+CONFIG_FEATURE_LESS_MAXLINES=0
+# CONFIG_FEATURE_LESS_BRACKETS is not set
+# CONFIG_FEATURE_LESS_FLAGS is not set
+# CONFIG_FEATURE_LESS_MARKS is not set
+# CONFIG_FEATURE_LESS_REGEXP is not set
+# CONFIG_FEATURE_LESS_WINCH is not set
+# CONFIG_FEATURE_LESS_DASHCMD is not set
+# CONFIG_FEATURE_LESS_LINENUMS is not set
+# CONFIG_HDPARM is not set
+# CONFIG_FEATURE_HDPARM_GET_IDENTITY is not set
+# CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set
+# CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set
+# CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set
+# CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set
+# CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA is not set
+# CONFIG_MAKEDEVS is not set
+# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
+# CONFIG_FEATURE_MAKEDEVS_TABLE is not set
+# CONFIG_MAN is not set
+# CONFIG_MICROCOM is not set
+# CONFIG_MOUNTPOINT is not set
+# CONFIG_MT is not set
+# CONFIG_RAIDAUTORUN is not set
+# CONFIG_READAHEAD is not set
+# CONFIG_RFKILL is not set
+# CONFIG_RUNLEVEL is not set
+# CONFIG_RX is not set
+# CONFIG_SETSID is not set
+# CONFIG_STRINGS is not set
+# CONFIG_TASKSET is not set
+# CONFIG_FEATURE_TASKSET_FANCY is not set
+# CONFIG_TIME is not set
+# CONFIG_TIMEOUT is not set
+# CONFIG_TTYSIZE is not set
+# CONFIG_VOLNAME is not set
+# CONFIG_WALL is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Networking Utilities
+#
+# CONFIG_NC is not set
+# CONFIG_NC_SERVER is not set
+# CONFIG_NC_EXTRA is not set
+# CONFIG_NC_110_COMPAT is not set
+# CONFIG_FEATURE_IPV6 is not set
+CONFIG_FEATURE_UNIX_LOCAL=y
+# CONFIG_FEATURE_PREFER_IPV4_ADDRESS is not set
+# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
+# CONFIG_ARP is not set
+# CONFIG_ARPING is not set
+# CONFIG_BRCTL is not set
+# CONFIG_FEATURE_BRCTL_FANCY is not set
+# CONFIG_FEATURE_BRCTL_SHOW is not set
+# CONFIG_DNSD is not set
+# CONFIG_ETHER_WAKE is not set
+# CONFIG_FAKEIDENTD is not set
+CONFIG_FTPD=y
+CONFIG_FEATURE_FTP_WRITE=y
+CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
+CONFIG_FTPGET=y
+CONFIG_FTPPUT=y
+# CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
+CONFIG_HOSTNAME=y
+# CONFIG_HTTPD is not set
+# CONFIG_FEATURE_HTTPD_RANGES is not set
+# CONFIG_FEATURE_HTTPD_USE_SENDFILE is not set
+# CONFIG_FEATURE_HTTPD_SETUID is not set
+# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
+# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
+# CONFIG_FEATURE_HTTPD_CGI is not set
+# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
+# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
+# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
+# CONFIG_FEATURE_HTTPD_ERROR_PAGES is not set
+# CONFIG_FEATURE_HTTPD_PROXY is not set
+CONFIG_IFCONFIG=y
+CONFIG_FEATURE_IFCONFIG_STATUS=y
+CONFIG_FEATURE_IFCONFIG_SLIP=y
+CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
+CONFIG_FEATURE_IFCONFIG_HW=y
+CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
+# CONFIG_IFENSLAVE is not set
+# CONFIG_IFPLUGD is not set
+# CONFIG_IFUPDOWN is not set
+CONFIG_IFUPDOWN_IFSTATE_PATH=""
+# CONFIG_FEATURE_IFUPDOWN_IP is not set
+# CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN is not set
+# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set
+# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
+# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
+# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
+# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
+# CONFIG_INETD is not set
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
+# CONFIG_FEATURE_INETD_RPC is not set
+# CONFIG_IP is not set
+# CONFIG_FEATURE_IP_ADDRESS is not set
+# CONFIG_FEATURE_IP_LINK is not set
+# CONFIG_FEATURE_IP_ROUTE is not set
+# CONFIG_FEATURE_IP_TUNNEL is not set
+# CONFIG_FEATURE_IP_RULE is not set
+# CONFIG_FEATURE_IP_SHORT_FORMS is not set
+# CONFIG_FEATURE_IP_RARE_PROTOCOLS is not set
+# CONFIG_IPADDR is not set
+# CONFIG_IPLINK is not set
+# CONFIG_IPROUTE is not set
+# CONFIG_IPTUNNEL is not set
+# CONFIG_IPRULE is not set
+# CONFIG_IPCALC is not set
+# CONFIG_FEATURE_IPCALC_FANCY is not set
+# CONFIG_FEATURE_IPCALC_LONG_OPTIONS is not set
+# CONFIG_NAMEIF is not set
+# CONFIG_FEATURE_NAMEIF_EXTENDED is not set
+CONFIG_NETSTAT=y
+CONFIG_FEATURE_NETSTAT_WIDE=y
+CONFIG_FEATURE_NETSTAT_PRG=y
+CONFIG_NSLOOKUP=y
+CONFIG_NTPD=y
+CONFIG_FEATURE_NTPD_SERVER=y
+CONFIG_PING=y
+# CONFIG_PING6 is not set
+CONFIG_FEATURE_FANCY_PING=y
+# CONFIG_PSCAN is not set
+CONFIG_ROUTE=y
+# CONFIG_SLATTACH is not set
+# CONFIG_TCPSVD is not set
+# CONFIG_TELNET is not set
+# CONFIG_FEATURE_TELNET_TTYPE is not set
+# CONFIG_FEATURE_TELNET_AUTOLOGIN is not set
+CONFIG_TELNETD=y
+CONFIG_FEATURE_TELNETD_STANDALONE=y
+# CONFIG_FEATURE_TELNETD_INETD_WAIT is not set
+CONFIG_TFTP=y
+CONFIG_TFTPD=y
+
+#
+# Common options for tftp/tftpd
+#
+CONFIG_FEATURE_TFTP_GET=y
+CONFIG_FEATURE_TFTP_PUT=y
+CONFIG_FEATURE_TFTP_BLOCKSIZE=y
+CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
+# CONFIG_TFTP_DEBUG is not set
+CONFIG_TRACEROUTE=y
+# CONFIG_TRACEROUTE6 is not set
+CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
+# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
+# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
+# CONFIG_TUNCTL is not set
+# CONFIG_FEATURE_TUNCTL_UG is not set
+# CONFIG_UDHCPD is not set
+# CONFIG_DHCPRELAY is not set
+# CONFIG_DUMPLEASES is not set
+# CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set
+CONFIG_DHCPD_LEASES_FILE=""
+CONFIG_UDHCPC=y
+CONFIG_FEATURE_UDHCPC_ARPING=y
+CONFIG_FEATURE_UDHCP_PORT=y
+CONFIG_UDHCP_DEBUG=9
+CONFIG_FEATURE_UDHCP_RFC3397=y
+CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
+CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
+CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
+# CONFIG_UDPSVD is not set
+# CONFIG_VCONFIG is not set
+# CONFIG_WGET is not set
+# CONFIG_FEATURE_WGET_STATUSBAR is not set
+# CONFIG_FEATURE_WGET_AUTHENTICATION is not set
+# CONFIG_FEATURE_WGET_LONG_OPTIONS is not set
+# CONFIG_ZCIP is not set
+
+#
+# Print Utilities
+#
+# CONFIG_LPD is not set
+# CONFIG_LPR is not set
+# CONFIG_LPQ is not set
+
+#
+# Mail Utilities
+#
+# CONFIG_MAKEMIME is not set
+CONFIG_FEATURE_MIME_CHARSET=""
+# CONFIG_POPMAILDIR is not set
+# CONFIG_FEATURE_POPMAILDIR_DELIVERY is not set
+# CONFIG_REFORMIME is not set
+# CONFIG_FEATURE_REFORMIME_COMPAT is not set
+# CONFIG_SENDMAIL is not set
+
+#
+# Process Utilities
+#
+# CONFIG_SMEMCAP is not set
+CONFIG_FREE=y
+# CONFIG_FUSER is not set
+CONFIG_KILL=y
+CONFIG_KILLALL=y
+# CONFIG_KILLALL5 is not set
+# CONFIG_NMETER is not set
+# CONFIG_PGREP is not set
+# CONFIG_PIDOF is not set
+# CONFIG_FEATURE_PIDOF_SINGLE is not set
+# CONFIG_FEATURE_PIDOF_OMIT is not set
+# CONFIG_PKILL is not set
+CONFIG_PS=y
+CONFIG_FEATURE_PS_WIDE=y
+# CONFIG_FEATURE_PS_TIME is not set
+# CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS is not set
+# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
+# CONFIG_RENICE is not set
+# CONFIG_BB_SYSCTL is not set
+CONFIG_TOP=y
+CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
+CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
+CONFIG_FEATURE_TOP_SMP_CPU=y
+CONFIG_FEATURE_TOP_DECIMALS=y
+CONFIG_FEATURE_TOP_SMP_PROCESS=y
+CONFIG_FEATURE_TOPMEM=y
+CONFIG_FEATURE_SHOW_THREADS=y
+# CONFIG_UPTIME is not set
+# CONFIG_WATCH is not set
+
+#
+# Runit Utilities
+#
+# CONFIG_RUNSV is not set
+# CONFIG_RUNSVDIR is not set
+# CONFIG_FEATURE_RUNSVDIR_LOG is not set
+# CONFIG_SV is not set
+CONFIG_SV_DEFAULT_SERVICE_DIR=""
+# CONFIG_SVLOGD is not set
+# CONFIG_CHPST is not set
+# CONFIG_SETUIDGID is not set
+# CONFIG_ENVUIDGID is not set
+# CONFIG_ENVDIR is not set
+# CONFIG_SOFTLIMIT is not set
+# CONFIG_CHCON is not set
+# CONFIG_FEATURE_CHCON_LONG_OPTIONS is not set
+# CONFIG_GETENFORCE is not set
+# CONFIG_GETSEBOOL is not set
+# CONFIG_LOAD_POLICY is not set
+# CONFIG_MATCHPATHCON is not set
+# CONFIG_RESTORECON is not set
+# CONFIG_RUNCON is not set
+# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set
+# CONFIG_SELINUXENABLED is not set
+# CONFIG_SETENFORCE is not set
+# CONFIG_SETFILES is not set
+# CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set
+# CONFIG_SETSEBOOL is not set
+# CONFIG_SESTATUS is not set
+
+#
+# Shells
+#
+# CONFIG_ASH is not set
+# CONFIG_ASH_BASH_COMPAT is not set
+# CONFIG_ASH_JOB_CONTROL is not set
+# CONFIG_ASH_ALIAS is not set
+# CONFIG_ASH_GETOPTS is not set
+# CONFIG_ASH_BUILTIN_ECHO is not set
+# CONFIG_ASH_BUILTIN_PRINTF is not set
+# CONFIG_ASH_BUILTIN_TEST is not set
+# CONFIG_ASH_CMDCMD is not set
+# CONFIG_ASH_MAIL is not set
+# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
+# CONFIG_ASH_RANDOM_SUPPORT is not set
+# CONFIG_ASH_EXPAND_PRMT is not set
+CONFIG_HUSH=y
+CONFIG_HUSH_BASH_COMPAT=y
+# CONFIG_HUSH_HELP is not set
+CONFIG_HUSH_INTERACTIVE=y
+CONFIG_HUSH_JOB=y
+CONFIG_HUSH_TICK=y
+CONFIG_HUSH_IF=y
+CONFIG_HUSH_LOOPS=y
+CONFIG_HUSH_CASE=y
+CONFIG_HUSH_FUNCTIONS=y
+CONFIG_HUSH_LOCAL=y
+CONFIG_HUSH_EXPORT_N=y
+CONFIG_HUSH_RANDOM_SUPPORT=y
+# CONFIG_FEATURE_SH_IS_ASH is not set
+CONFIG_FEATURE_SH_IS_HUSH=y
+# CONFIG_FEATURE_SH_IS_NONE is not set
+# CONFIG_FEATURE_BASH_IS_ASH is not set
+# CONFIG_FEATURE_BASH_IS_HUSH is not set
+CONFIG_FEATURE_BASH_IS_NONE=y
+# CONFIG_LASH is not set
+# CONFIG_MSH is not set
+# CONFIG_SH_MATH_SUPPORT is not set
+# CONFIG_SH_MATH_SUPPORT_64 is not set
+CONFIG_FEATURE_SH_EXTRA_QUIET=y
+# CONFIG_FEATURE_SH_STANDALONE is not set
+# CONFIG_FEATURE_SH_NOFORK is not set
+CONFIG_CTTYHACK=y
+
+#
+# System Logging Utilities
+#
+# CONFIG_SYSLOGD is not set
+# CONFIG_FEATURE_ROTATE_LOGFILE is not set
+# CONFIG_FEATURE_REMOTE_LOG is not set
+# CONFIG_FEATURE_SYSLOGD_DUP is not set
+CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
+# CONFIG_FEATURE_IPC_SYSLOG is not set
+CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
+# CONFIG_LOGREAD is not set
+# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
+# CONFIG_KLOGD is not set
+# CONFIG_LOGGER is not set

+ 235 - 0
GD32F450_BMC_BaseCode.initramfs

@@ -0,0 +1,235 @@
+dir /dev 0755 0 0
+dir /dev/pts 0755 0 0
+dir /root 0700 0 0
+dir /proc 0755 0 0
+dir /sys 0755 0 0
+dir /etc 0755 0 0
+dir /var 0755 0 0
+dir /var/config 0755 0 0
+dir /var/tmp 0755 0 0
+dir /var/log 0755 0 0
+dir /var/run 0755 0 0
+dir /var/lock 0755 0 0
+dir /bin 755 0 0
+
+nod /dev/tty 0666 0 0 c 5 0
+nod /dev/console 0600 0 0 c 5 1
+nod /dev/ptmx 0666 0 0 c 5 2
+nod /dev/ttyS0 0666 0 0 c 4 64
+nod /dev/ttyS1 0666 0 0 c 4 65
+nod /dev/ttyS2 0666 0 0 c 4 66
+nod /dev/ttyS3 0666 0 0 c 4 67
+nod /dev/ttyS4 0666 0 0 c 4 68
+nod /dev/ttyS5 0666 0 0 c 4 69
+nod /dev/null 0600 0 0 c 1 3
+nod /dev/mem 0600 0 0 c 1 1
+nod /dev/kmem 0600 0 0 c 1 2
+nod /dev/zero 0600 0 0 c 1 5
+nod /dev/random 0600 0 0 c 1 8
+nod /dev/urandom 0600 0 0 c 1 9
+
+ifarch STM file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.STM 755 0 0
+ifarch STM32F4 file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.STM 755 0 0
+ifarch STM32F4X9 file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.ALL 755 0 0
+ifarch STMDISCO file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.ALL 755 0 0
+ifarch STM32F7DISCO file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.STM32F7DISCO 755 0 0
+ifarch A2F file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.ALL 755 0 0
+ifarch LPC file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.ALL 755 0 0
+ifarch LPC18XX file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.ALL 755 0 0
+ifarch K70 file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.K70 755 0 0
+ifarch M2S file /etc/inittab ${INSTALL_ROOT}/projects/${SAMPLE}/local/inittab.M2S 755 0 0
+file /etc/rc ${INSTALL_ROOT}/projects/${SAMPLE}/local/rc 755 0 0
+file /etc/hosts ${INSTALL_ROOT}/projects/${SAMPLE}/local/hosts 644 0 0
+file /etc/services ${INSTALL_ROOT}/projects/${SAMPLE}/local/services 644 0 0
+file /etc/passwd ${INSTALL_ROOT}/projects/${SAMPLE}/local/passwd 644 0 0
+file /etc/group ${INSTALL_ROOT}/projects/${SAMPLE}/local/group 644 0 0
+file /etc/shadow ${INSTALL_ROOT}/projects/${SAMPLE}/local/shadow 644 0 0
+file /etc/securetty ${INSTALL_ROOT}/projects/${SAMPLE}/local/securetty 644 0 0
+
+file /bin/busybox ${INSTALL_ROOT}/A2F/busybox/busybox 755 0 0
+slink /bin/init busybox 777 0 0
+slink /init /bin/init 777 0 0
+slink /bin/insmod busybox 777 0 0
+slink /bin/rmmod busybox 777 0 0
+slink /bin/lsmod busybox 777 0 0
+slink /bin/hostname busybox 777 0 0
+slink /bin/cat busybox 777 0 0
+slink /bin/cp busybox 777 0 0
+#slink /bin/chmod busybox 777 0 0
+#slink /bin/chown busybox 777 0 0
+slink /bin/date busybox 777 0 0
+#slink /bin/dd busybox 777 0 0
+slink /bin/echo busybox 777 0 0
+slink /bin/hush busybox 777 0 0
+slink /bin/kill busybox 777 0 0
+slink /bin/killall busybox 777 0 0
+#slink /bin/ln busybox 777 0 0
+slink /bin/login /bin/busybox 777 0 0
+slink /bin/ls busybox 777 0 0
+slink /bin/mkdir busybox 777 0 0
+slink /bin/mknod busybox 777 0 0
+slink /bin/mv busybox 777 0 0
+slink /bin/ps busybox 777 0 0
+slink /bin/pwd busybox 777 0 0
+slink /bin/reboot busybox 777 0 0
+slink /bin/rm busybox 777 0 0
+slink /bin/sh busybox 777 0 0
+slink /bin/sleep busybox 777 0 0
+slink /bin/mount busybox 777 0 0
+slink /bin/umount busybox 777 0 0
+slink /bin/ping busybox 777 0 0
+slink /bin/ifconfig busybox 777 0 0
+slink /bin/telnetd busybox 777 0 0
+#slink /bin/wc busybox 777 0 0
+slink /bin/netstat busybox 777 0 0
+slink /bin/nslookup busybox 777 0 0
+slink /bin/ntpd busybox 777 0 0
+slink /bin/route busybox 777 0 0
+#slink /bin/telnet busybox 777 0 0
+slink /bin/traceroute busybox 777 0 0
+#slink /bin/wget busybox 777 0 0
+slink /bin/vi busybox 777 0 0
+slink /bin/top busybox 777 0 0
+slink /bin/free busybox 777 0 0
+slink /bin/tftp busybox 777 0 0
+slink /bin/tftpd busybox 777 0 0
+slink /bin/ftpd busybox 777 0 0
+slink /bin/ftpget busybox 777 0 0
+slink /bin/ftpput busybox 777 0 0
+slink /bin/find busybox 777 0 0
+slink /bin/grep busybox 777 0 0
+slink /bin/chmod busybox 777 0 0
+slink /bin/cttyhack busybox 777 0 0
+slink /bin/depmod busybox 777 0 0
+slink /bin/dnsdomainname busybox 777 0 0
+slink /bin/egrep busybox 777 0 0
+slink /bin/expr busybox 777 0 0
+slink /bin/false busybox 777 0 0
+slink /bin/fgrep busybox 777 0 0
+slink /bin/halt busybox 777 0 0
+slink /bin/mkfifo busybox 777 0 0 
+slink /bin/modinfo busybox 777 0 0
+slink /bin/modprobe busybox 777 0 0
+slink /bin/nohup busybox 777 0 0
+slink /bin/poweroff busybox 777 0 0
+slink /bin/printenv busybox 777 0 0
+slink /bin/printf busybox 777 0 0
+slink /bin/stty busybox 777 0 0
+slink /bin/tail busybox 777 0 0
+slink /bin/test busybox 777 0 0
+slink /bin/true busybox 777 0 0
+slink /bin/udhcpc busybox 777 0 0
+slink /bin/usleep busybox 777 0 0 
+slink /bin/whoami busybox 777 0 0
+slink /bin/yes busybox 777 0 0
+
+
+ifarch A2F file /bin/iap_tool ${INSTALL_ROOT}/A2F/root/usr/bin/iap_tool 755 0 0
+
+dir /usr 755 0 0
+dir /usr/bin 755 0 0
+dir /usr/share 755 0 0
+dir /usr/share/udhcpc 755 0 0
+file /usr/share/udhcpc/default.script ${INSTALL_ROOT}/projects/${SAMPLE}/local/default.script 755 0 0
+
+slink /usr/bin/[ ../../bin/busybox 777 0 0
+slink /usr/bin/[[ ../../bin/busybox 777 0 0
+
+
+
+file /usr/bin/gpio.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/GPIO/gpio.ko 755 0 0
+file /usr/bin/i2c.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/I2C/i2c.ko 755 0 0
+#file /usr/bin/gpio_i2c.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/GPIO_I2C/gpio_i2c.ko 755 0 0
+#file /usr/bin/fmc.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/FMC/fmc.ko 755 0 0
+#file /usr/bin/test_module.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/test/test_module.ko 755 0 0
+file /usr/bin/platform.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/Platform/platform.ko 755 0 0
+file /usr/bin/adc.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/ADC/adc.ko 755 0 0
+file /usr/bin/spi.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/SPI/spi.ko 755 0 0
+file /usr/bin/crypto.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/Crypto/crypto.ko 755 0 0
+file /usr/bin/iwdg.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/WatchDog/iwdg.ko 755 0 0
+#
+#
+#
+#
+#
+file /usr/bin/test_app ${INSTALL_ROOT}/projects/${SAMPLE}/app/test_app/test_app 755 0 0
+file /usr/bin/bmc_app ${INSTALL_ROOT}/projects/${SAMPLE}/app/bmc/bmc_app 755 0 0
+file /usr/bin/ipmitool ${INSTALL_ROOT}/projects/${SAMPLE}/app/ipmitool-1.8.18/ipmitool 755 0 0
+file /usr/bin/goahead-3.6.5 ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/build/linux-arm-static/bin/goahead 755 0 0
+file /usr/bin/updateFW_app ${INSTALL_ROOT}/projects/${SAMPLE}/app/UpdateFirmware/updateFW_app 755 0 0
+file /usr/bin/i2c-scan ${INSTALL_ROOT}/projects/${SAMPLE}/app/i2c_scan/i2c-scan 755 0 0
+file /usr/bin/ncp81111_cfg ${INSTALL_ROOT}/projects/${SAMPLE}/app/NCP81111_Config/ncp81111_cfg 755 0 0
+file /usr/bin/damon.sh ${INSTALL_ROOT}/projects/${SAMPLE}/app/damon.sh 777 0 0
+
+dir /etc/goahead 755 0 0 
+dir /var/www 755 0 0
+dir /var/www/goahead 755 0 0
+dir /var/www/goahead/tmp 755 0 0
+dir /var/www/goahead/static 755 0 0
+dir /var/www/goahead/static/css 755 0 0
+dir /var/www/goahead/static/img 755 0 0
+dir /var/www/goahead/static/js 755 0 0 
+dir /var/www/goahead/static/fonts 755 0 0
+file /etc/goahead/self.crt ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/self.crt 755 0 0
+file /etc/goahead/self.key ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/self.key 755 0 0
+file /etc/goahead/auth.txt ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/auth.txt 755 0 0
+file /etc/goahead/route.txt ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/route.txt 755 0 0
+
+
+
+
+
+file /var/www/goahead/favicon.ico ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/favicon.ico 755 0 0
+file /var/www/goahead/index.html ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/index.html 755 0 0
+file /var/www/goahead/static/css/app.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/app.css 755 0 0
+file /var/www/goahead/static/css/chunk-vendors.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/chunk-vendors.css 755 0 0
+file /var/www/goahead/static/css/dashbord.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/dashbord.css 755 0 0
+file /var/www/goahead/static/css/event_logs.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/event_logs.css 755 0 0
+file /var/www/goahead/static/css/fan.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/fan.css 755 0 0
+file /var/www/goahead/static/css/fru_info.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/fru_info.css 755 0 0
+file /var/www/goahead/static/css/index.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/index.css 755 0 0
+file /var/www/goahead/static/css/login.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/login.css 755 0 0
+file /var/www/goahead/static/css/RemotPwrCtrl.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/RemotPwrCtrl.css 755 0 0
+file /var/www/goahead/static/css/sensor_history.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/sensor_history.css 755 0 0
+file /var/www/goahead/static/css/setting.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/setting.css 755 0 0
+file /var/www/goahead/static/css/set_proctrol.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/set_proctrol.css 755 0 0
+file /var/www/goahead/static/css/system_logs.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/system_logs.css 755 0 0
+file /var/www/goahead/static/css/UploadProgre.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/UploadProgre.css 755 0 0
+file /var/www/goahead/static/css/UserManage.css ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/css/UserManage.css 755 0 0
+file /var/www/goahead/static/fonts/ionicons.ttf ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/fonts/ionicons.ttf 755 0 0
+file /var/www/goahead/static/fonts/ionicons.woff ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/fonts/ionicons.woff 755 0 0
+file /var/www/goahead/static/fonts/ionicons.woff2 ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/fonts/ionicons.woff2 755 0 0
+file /var/www/goahead/static/img/active.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/active.png 755 0 0
+file /var/www/goahead/static/img/bg1.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/bg1.png 755 0 0
+file /var/www/goahead/static/img/cart.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/cart.png 755 0 0
+file /var/www/goahead/static/img/cart_active.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/cart_active.png 755 0 0
+file /var/www/goahead/static/img/checked-card.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/checked-card.png 755 0 0
+file /var/www/goahead/static/img/icon_right.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/icon_right.png 755 0 0
+file /var/www/goahead/static/img/ionicons.svg ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/ionicons.svg 755 0 0
+file /var/www/goahead/static/img/logout_1.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/logout_1.png 755 0 0
+file /var/www/goahead/static/img/refresh.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/refresh.png 755 0 0
+file /var/www/goahead/static/img/sortup.gif ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/sortup.gif 755 0 0
+file /var/www/goahead/static/img/status_critical.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/status_critical.png 755 0 0
+file /var/www/goahead/static/img/status_ok.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/status_ok.png 755 0 0
+file /var/www/goahead/static/img/status_warning.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/status_warning.png 755 0 0
+file /var/www/goahead/static/img/user.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/user.png 755 0 0
+file /var/www/goahead/static/img/view.png ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/img/view.png 755 0 0
+file /var/www/goahead/static/js/app.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/app.js 755 0 0
+file /var/www/goahead/static/js/BSODScreen.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/BSODScreen.js 755 0 0
+file /var/www/goahead/static/js/chunk-vendors.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/chunk-vendors.js 755 0 0
+file /var/www/goahead/static/js/dashbord.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/dashbord.js 755 0 0
+file /var/www/goahead/static/js/event_logs.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/event_logs.js 755 0 0
+file /var/www/goahead/static/js/fan.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/fan.js 755 0 0
+file /var/www/goahead/static/js/fru_info.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/fru_info.js 755 0 0
+file /var/www/goahead/static/js/index.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/index.js 755 0 0
+file /var/www/goahead/static/js/login.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/login.js 755 0 0
+file /var/www/goahead/static/js/RemotPwrCtrl.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/RemotPwrCtrl.js 755 0 0
+file /var/www/goahead/static/js/SelList.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/SelList.js 755 0 0
+file /var/www/goahead/static/js/sensor_history.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/sensor_history.js 755 0 0
+file /var/www/goahead/static/js/setting.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/setting.js 755 0 0
+file /var/www/goahead/static/js/set_proctrol.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/set_proctrol.js 755 0 0
+file /var/www/goahead/static/js/system_logs.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/system_logs.js 755 0 0
+file /var/www/goahead/static/js/UploadProgre.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/UploadProgre.js 755 0 0
+file /var/www/goahead/static/js/UserManage.js ${INSTALL_ROOT}/projects/${SAMPLE}/app/goahead-3.6.5/src/web/static/js/UserManage.js 755 0 0
+
+

+ 400 - 0
GD32F450_BMC_BaseCode.lds.STMDISCO

@@ -0,0 +1,400 @@
+/* ld script to make ARM Linux kernel
+ * taken from the i386 version by Russell King
+ * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ */
+
+#include <asm-generic/vmlinux.lds.h>
+#include <asm/thread_info.h>
+#include <asm/memory.h>
+#include <asm/page.h>
+	
+OUTPUT_ARCH(arm)
+ENTRY(stext)
+
+#ifndef __ARMEB__
+jiffies = jiffies_64;
+#else
+jiffies = jiffies_64 + 4;
+#endif
+
+SECTIONS
+{
+
+#ifdef CONFIG_XIP_KERNEL
+	. = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR);
+#else
+#if defined(PHYS_ALIAS_OFFSET)
+	. = PHYS_ALIAS_OFFSET + TEXT_OFFSET;
+#else
+	. = PAGE_OFFSET + TEXT_OFFSET;
+#endif
+#endif
+
+	.init : {			/* Init code and data		*/
+		_stext = .;
+		_sinittext = .;
+			HEAD_TEXT
+#if !defined(CONFIG_M2S_CACHE) && !defined(CONFIG_KERNEL_IN_ENVM)
+			INIT_TEXT
+#endif
+		_einittext = .;
+#if !defined(CONFIG_INITRAMFS_IS_LARGE)
+		/*
+		 * In case the kernel links in a built-in initramfs
+		 * and that initramfs is large enough, there is a symbol
+		 * in .proc.info.init that makes a relative reference
+		 * (in an assembly-level file) to a symbol in the kernel text.
+		 * The initramfs being large, that relative reference 
+		 * doesn't work because the linker is not able to fit
+		 * in the relative offset into the 24 bit offset field.
+		 * The solution (well, part of it) is to move .proc.info.init
+		 * closer to the kernel text section.
+		 */
+		__proc_info_begin = .;
+			*(.proc.info.init)
+		__proc_info_end = .;
+#endif
+		__arch_info_begin = .;
+			*(.arch.info.init)
+		__arch_info_end = .;
+		__tagtable_begin = .;
+			*(.taglist.init)
+		__tagtable_end = .;
+
+#if !defined(CONFIG_M2S_CACHE) && !defined(CONFIG_KERNEL_IN_ENVM)
+		INIT_SETUP(16)
+#endif
+
+		__early_begin = .;
+			*(.early_param.init)
+		__early_end = .;
+
+#if !defined(CONFIG_M2S_CACHE) && !defined(CONFIG_KERNEL_IN_ENVM)
+		INIT_CALLS
+		CON_INITCALL
+		SECURITY_INITCALL
+		INIT_RAM_FS
+#endif
+
+#ifndef CONFIG_XIP_KERNEL
+		__init_begin = _stext;
+		INIT_DATA
+#endif
+	} 
+
+	PERCPU(PAGE_SIZE)
+
+#ifndef CONFIG_XIP_KERNEL
+	. = ALIGN(PAGE_SIZE);
+	__init_end = .;
+#endif
+
+	/*
+	 * unwind exit sections must be discarded before the rest of the
+	 * unwind sections get included.
+	 */
+	/DISCARD/ : {
+		*(.ARM.exidx.exit.text)
+		*(.ARM.extab.exit.text)
+#ifndef CONFIG_HOTPLUG_CPU
+		*(.ARM.exidx.cpuexit.text)
+		*(.ARM.extab.cpuexit.text)
+#endif
+#ifndef CONFIG_HOTPLUG
+		*(.ARM.exidx.devexit.text)
+		*(.ARM.extab.devexit.text)
+#endif
+#ifndef CONFIG_MMU
+		*(.fixup)
+		*(__ex_table)
+#endif
+	}
+
+/*
+ * On Microsemi SmartFusion2, kernel code is linked into
+ * an alias address region, which is cacheable. Anything that
+ * is not code MUST reside in the non-cached address region.
+ */
+#if defined(CONFIG_M2S_CACHE)
+	_non_cached_start = .;
+	.cached m2s_phys_to_cached(_non_cached_start) : {
+		_cached_init = .;
+
+		INIT_TEXT
+		INIT_SETUP(16)
+		INIT_CALLS
+		CON_INITCALL
+		SECURITY_INITCALL
+
+		*(.text)
+		SCHED_TEXT
+		LOCK_TEXT
+		KPROBES_TEXT
+
+		_cached_end = .;
+	}
+	. = _non_cached_start + SIZEOF(.cached);
+#endif
+
+/*
+ * In case we run parts of the kernel in embedded Flash,
+ * relocate critical kernel code to that fast Flash.
+ */
+#ifdef CONFIG_KERNEL_IN_ENVM
+	_envm_loc = .;
+
+
+	.envm  ENVM_PHYS_OFFSET + CONFIG_KERNEL_IN_ENVM_OFFSET * 1024 : {
+		_envm_start = .;
+
+#if CONFIG_KERNEL_IN_ENVM_SIZE>0
+		INIT_TEXT
+		INIT_SETUP(16)
+		INIT_CALLS
+		CON_INITCALL
+		SECURITY_INITCALL
+		INIT_RAM_FS
+		__exception_text_start = .;
+		*(.exception.text*)
+		*(.exception.rodata*)
+		__exception_text_end = .;
+		SCHED_TEXT
+		LOCK_TEXT
+		KPROBES_TEXT
+
+		usr/built-in.o(.text)
+		usr/built-in.o(.rodata*)
+		init/built-in.o(.text)
+		init/built-in.o(.rodata*)
+		mm/built-in.o(.text)
+		mm/built-in.o(.rodata*)
+		arch/arm/mm/built-in.o(.text)
+		arch/arm/mm/built-in.o(.rodata*)
+		arch/arm/common/built-in.o(.text)
+		arch/arm/common/built-in.o(.rodata*)
+
+		arch/arm/lib/lib.a(.text)
+		arch/arm/lib/lib.a(.rodata*)
+		arch/arm/lib/built-in.o(.text)
+		arch/arm/lib/built-in.o(.rodata*)
+		lib/built-in.o(.text)
+		lib/built-in.o(.rodata*)
+
+#if CONFIG_KERNEL_IN_ENVM_SIZE>128
+		kernel/built-in.o(.text)
+		kernel/built-in.o(.rodata*)
+		ipc/built-in.o(.text)
+		ipc/built-in.o(.rodata*)
+		block/built-in.o(.text)
+		block/built-in.o(.rodata*)
+		security/built-in.o(.text)
+		security/built-in.o(.rodata*)
+		crypto/built-in.o(.text)
+		crypto/built-in.o(.rodata*)
+		firmware/built-in.o(.text)
+		firmware/built-in.o(.rodata*)
+
+#if CONFIG_KERNEL_IN_ENVM_SIZE>384
+		drivers/built-in.o(.text)
+		drivers/built-in.o(.rodata*)
+		fs/built-in.o(.text)
+		fs/built-in.o(.rodata*)
+		net/built-in.o(.text)
+		net/built-in.o(.rodata*)
+
+#endif /* CONFIG_KERNEL_IN_ENVM_SIZE>384 */
+#endif /* CONFIG_KERNEL_IN_ENVM_SIZE>128 */
+#endif /* CONFIG_KERNEL_IN_ENVM_SIZE>0 */
+
+		_envm_end = .;
+	} 
+
+	. = _envm_loc;
+#endif /* CONFIG_KERNEL_IN_ENVM */
+
+	.text : {			/* Real text segment		*/
+		_text = .;		/* Text and read-only data	*/
+			__exception_text_start = .;
+			*(.exception.text)
+			__exception_text_end = .;
+#if defined(CONFIG_INITRAMFS_IS_LARGE)
+			__proc_info_begin = .;
+				*(.proc.info.init)
+			__proc_info_end = .;
+#endif
+			TEXT_TEXT
+			SCHED_TEXT
+			LOCK_TEXT
+			KPROBES_TEXT
+#ifdef CONFIG_MMU
+			*(.fixup)
+#endif
+			*(.gnu.warning)
+			*(.rodata)
+			*(.rodata.*)
+			*(.glue_7)
+			*(.glue_7t)
+		*(.got)			/* Global offset table		*/
+	}
+
+	RO_DATA(PAGE_SIZE)
+
+	_etext = .;			/* End of text and rodata section */
+
+#ifdef CONFIG_ARM_UNWIND
+	/*
+	 * Stack unwinding tables
+	 */
+	. = ALIGN(8);
+	.ARM.unwind_idx : {
+		__start_unwind_idx = .;
+		*(.ARM.exidx*)
+		__stop_unwind_idx = .;
+	}
+	.ARM.unwind_tab : {
+		__start_unwind_tab = .;
+		*(.ARM.extab*)
+		__stop_unwind_tab = .;
+	}
+#endif
+
+#ifdef CONFIG_XIP_KERNEL
+	__data_loc = ALIGN(4);		/* location in binary */
+	. = PAGE_OFFSET + TEXT_OFFSET;
+#else
+	. = ALIGN(THREAD_SIZE);
+	__data_loc = .;
+#endif
+
+	.data : AT(__data_loc) {
+		_data = .;		/* address in memory */
+		_sdata = .;
+
+		/*
+		 * first, the init task union, aligned
+		 * to an 8192 byte boundary.
+		 */
+		INIT_TASK_DATA(THREAD_SIZE)
+
+#ifdef CONFIG_XIP_KERNEL
+		. = ALIGN(PAGE_SIZE);
+		__init_begin = .;
+		INIT_DATA
+		. = ALIGN(PAGE_SIZE);
+		__init_end = .;
+#endif
+
+		NOSAVE_DATA
+		CACHELINE_ALIGNED_DATA(32)
+
+		/*
+		 * The exception fixup table (might need resorting at runtime)
+		 */
+		. = ALIGN(32);
+		__start___ex_table = .;
+#ifdef CONFIG_MMU
+		*(__ex_table)
+#endif
+		__stop___ex_table = .;
+
+		/*
+		 * and the usual data section
+		 */
+		DATA_DATA
+		CONSTRUCTORS
+
+		_edata = .;
+	}
+	_edata_loc = __data_loc + SIZEOF(.data);
+
+#ifdef SRAM_PHYS_OFFSET
+/*
+ * SRAM code for Flash/SDRAM issue, see errata 2.8.7
+ */
+	. = ALIGN(PAGE_SIZE);
+	__sram_loc = .;
+	.sram SRAM_PHYS_OFFSET + vector_table_end - vector_table : AT(__sram_loc) {
+		_sram_start = .;
+		*(.sram.text)
+		*(.sram.data)
+		_sram_end = .;
+	}
+	_esram_loc = __sram_loc + SIZEOF(.sram);
+	. = _esram_loc;
+	. = ALIGN(4);
+#endif
+
+#ifdef CONFIG_HAVE_TCM
+        /*
+	 * We align everything to a page boundary so we can
+	 * free it after init has commenced and TCM contents have
+	 * been copied to its destination.
+	 */
+	.tcm_start : {
+		. = ALIGN(PAGE_SIZE);
+		__tcm_start = .;
+		__itcm_start = .;
+	}
+
+	/*
+	 * Link these to the ITCM RAM
+	 * Put VMA to the TCM address and LMA to the common RAM
+	 * and we'll upload the contents from RAM to TCM and free
+	 * the used RAM after that.
+	 */
+	.text_itcm ITCM_OFFSET : AT(__itcm_start)
+	{
+		__sitcm_text = .;
+		*(.tcm.text)
+		*(.tcm.rodata)
+		. = ALIGN(4);
+		__eitcm_text = .;
+	}
+
+	/*
+	 * Reset the dot pointer, this is needed to create the
+	 * relative __dtcm_start below (to be used as extern in code).
+	 */
+	. = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm);
+
+	.dtcm_start : {
+		__dtcm_start = .;
+	}
+
+	/* TODO: add remainder of ITCM as well, that can be used for data! */
+	.data_dtcm DTCM_OFFSET : AT(__dtcm_start)
+	{
+		. = ALIGN(4);
+		__sdtcm_data = .;
+		*(.tcm.data)
+		. = ALIGN(4);
+		__edtcm_data = .;
+	}
+
+	/* Reset the dot pointer or the linker gets confused */
+	. = ADDR(.dtcm_start) + SIZEOF(.data_dtcm);
+
+	/* End marker for freeing TCM copy in linked object */
+	.tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){
+		. = ALIGN(PAGE_SIZE);
+		__tcm_end = .;
+	}
+#endif
+
+	BSS_SECTION(0, 0, 0)
+	_end = .;
+
+	STABS_DEBUG
+	.comment 0 : { *(.comment) }
+
+	/* Default discards */
+	DISCARDS
+}
+
+/*
+ * These must never be empty
+ * If you have to comment these two assert statements out, your
+ * binutils is too old (for other reasons as well)
+ */
+ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
+ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")

+ 14 - 0
Makefile

@@ -0,0 +1,14 @@
+# Makefile for an A2F-Linux project
+
+# This project's name
+SAMPLE		:= GD32F450_BMC_BaseCode
+
+# Custom applcations subdirectories that this project
+# needs to build. Edit this list as appropriate for your application.
+CUSTOM_APPS	:= app
+
+# Include Make rules applicable to all projects
+include ../Rules.make
+
+export SAMPLE
+export CUSTOM_APPS

+ 1 - 0
README.md

@@ -0,0 +1 @@
+niao

+ 38 - 0
app/Makefile

@@ -0,0 +1,38 @@
+all	:
+	# make drivers
+	make -C ./driver/Platform
+	make -C ./driver/GPIO
+	make -C ./driver/FMC
+	make -C ./driver/ADC
+	make -C ./driver/I2C 
+	make -C ./driver/SPI
+	make -C ./driver/GPIO_I2C
+	make -C ./driver/Crypto
+	make -C ./driver/WatchDog
+	
+	# make apps
+	make -C ./bmc
+	make -C ./goahead-3.6.5
+	make -C ./test_app
+	make -C ./ipmitool-1.8.18
+	make -C ./UpdateFirmware
+	make -C ./i2c_scan
+	make -C ./NCP81111_Config
+clean	: 
+	make -C ./goahead-3.6.5 clean
+	make -C ./bmc clean
+	make -C ./test_app clean
+	make -C ./ipmitool-1.8.18 clean
+	make -C ./UpdateFirmware clean
+
+	make -C ./driver/Platform clean
+	make -C ./driver/GPIO clean
+	make -C ./driver/FMC clean
+	make -C ./driver/ADC clean
+	make -C ./driver/I2C clean
+	make -C ./driver/SPI clean
+	make -C ./driver/GPIO_I2C clean
+	make -C ./driver/Crypto clean
+	make -C ./NCP81111_Config clean
+	make -C ./i2c_scan clean
+	make -C ./driver/WatchDog clean

+ 49 - 0
app/NCP81111_Config/Makefile

@@ -0,0 +1,49 @@
+EXEC		= ncp81111_cfg
+
+CFLAGS		:= -Os -mcpu=cortex-m3 -mthumb
+LDFLAGS		:= -mcpu=cortex-m3 -mthumb -L$(INSTALL_ROOT)/A2F/root/usr/lib
+#BUILD_TIME 	= $(shell date +"%Y-%m-%d %H:%M:%S")
+
+
+
+CC	= $(CROSS_COMPILE_APPS)gcc
+
+#source
+SRC	= NCP81111_main.c
+
+# hal_api
+SRC += $(wildcard ../hal_api/*.c) 
+
+#incldue
+CFLAGS	+= -I$(INSTALL_ROOT)/A2F/root/usr/include
+CFLAGS	+= -I ./
+CFLAGS	+= -I ../common_include
+CFLAGS	+= -I ../driver
+CFLAGS	+= -I ../hal_api
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc/Legacy
+
+
+#library
+
+#sub-directory
+#SUBDIR 	= ./sensor
+
+
+
+
+
+
+$(EXEC): $(SRC)
+	#echo $(BUILD_TIME)
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS) -lpthread
+
+
+#object
+OBJS	= $(SRC:%.c=%.o)
+
+clean:
+	rm -f $(EXEC) $(OBJS)
+	rm -f *.gdb 
+

+ 242 - 0
app/NCP81111_Config/NCP81111_main.c

@@ -0,0 +1,242 @@
+#include <stdio.h>
+#include <stdint.h>
+#include "driver.h"
+#include "hal_interface_api.h"
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+i2c-scan -b 0
+*/
+
+int main(int argc, char* argv[])
+{
+	int fd;
+	int i;
+	int ret;
+	int channel;
+	uint8_t target_addr, start_addr = 2, end_addr = 254;
+	int regVal, regAddr;
+	i2c_arg_t i2c_arg;
+	char devname[20] = "/dev/i2c1";
+	char chr;
+	
+	if((argc != 1) && (argc != 3))
+	{
+		printf("ncp81111_cfg [regAddr] [regVal]\n");
+		printf("    regAddr: decimal or hexadecimal start with '0x'\n");
+		printf("    regVal: decimal or hexadecimal start with '0x'\n\n");
+		printf("example:\n");
+		printf("    ncp81111_cfg 51 32\n");
+		printf("  = ncp81111_cfg 0x33 32 \n");
+		printf("  = ncp81111_cfg 51 0x20\n");
+		printf("  = ncp81111_cfg 0x33 0x20\n");
+	}
+
+	fd = open(devname, O_RDWR);
+	i2c_arg.DevAddress = 0x50;
+
+	if(argc == 3)
+	{
+		//Get RegAddr
+		if((strncmp(argv[1], "0x", 2) == 0) || (strncmp(argv[1], "0X", 2) == 0))
+		{			
+			if(strlen(argv[1]) > 4)
+			{
+				printf("Invalid Register Address %s\n", argv[1]);
+				close(fd);
+				return -1;
+			}
+
+			chr = argv[1][2];
+			printf("chr2 = %c\n", chr);
+			if((chr >= '0') && (chr <= '9'))
+			{
+				regAddr = chr - '0';
+			}
+			else if((chr >= 'a') && (chr <= 'f'))
+			{
+				regAddr = chr - 'a' + 10;
+			}
+			else if((chr >= 'A') && (chr <= 'F'))
+			{
+				regAddr = chr - 'A' + 10;
+			}
+			else
+			{
+				printf("Invalid Register Address %s\n", argv[1]);
+				close(fd);
+				return -1;
+			}
+
+			if(argv[1][3] != '\0')
+			{
+				chr = argv[1][3];
+				printf("chr3 = %c\n", chr);
+				regAddr <<= 4; 
+				if((chr >= '0') && (chr <= '9'))
+					regAddr += chr - '0';
+				else if((chr >= 'a') && (chr <= 'f'))
+					regAddr += chr - 'a' + 10;
+				else if((chr >= 'A') && (chr <= 'F'))
+					regAddr += chr - 'A' + 10;
+				else
+				{
+					printf("Invalid Register Address %s\n", argv[1]);
+					close(fd);
+					return -1;
+				}
+			}
+		}
+		else
+		{
+			regAddr = atoi(argv[1]);
+		}
+		//printf("---> RegAddr %#02x(%d) \n", regAddr, regAddr);
+
+		//Get RegVal
+		if((strncmp(argv[2], "0x", 2) == 0) || (strncmp(argv[2], "0X", 2) == 0))
+		{			
+			if(strlen(argv[2]) > 4)
+			{
+				printf("Invalid Register Address %s\n", argv[2]);
+				close(fd);
+				return -1;
+			}
+
+			chr = argv[2][2];
+			if((chr >= '0') && (chr <= '9'))
+				regVal = chr - '0';
+			else if((chr >= 'a') && (chr <= 'f'))
+				regVal = chr - 'a' + 10;
+			else if((chr >= 'A') && (chr <= 'F'))
+				regVal = chr - 'A' + 10;
+			else
+			{
+				printf("Invalid Register Address %s\n", argv[2]);
+				close(fd);
+				return -1;
+			}
+
+			if(argv[2][3] != '\0')
+			{
+				chr = argv[2][3];
+				regVal <<= 4; 
+				if((chr >= '0') && (chr <= '9'))
+					regVal += chr - '0';
+				else if((chr >= 'a') && (chr <= 'f'))
+					regVal += chr - 'a' + 10;
+				else if((chr >= 'A') && (chr <= 'F'))
+					regVal += chr - 'A' + 10;
+				else
+				{
+					printf("Invalid Register Address %s\n", argv[2]);
+					close(fd);
+					return -1;
+				}
+			}			
+		}
+		else
+		{
+			regVal = atoi(argv[2]);
+		}
+
+		//printf("---> RegVal %#02x(%d)\n", regVal, regVal);
+
+		printf("write reg %#02x(%d), val %#02x(%d)\n", regAddr, regAddr, regVal, regVal);
+
+		//Disable NCP81111
+		i2c_arg.Buf[0] = 0x05; //Enter disable state
+		i2c_arg.Buf[1] = 0x00;
+		i2c_arg.WriteLen = 2;
+		ret = ioctl(fd, I2C_MASTER_TRANSFER, &i2c_arg);
+		if(ret == -1)
+		{
+			printf("---> Enter disable error\n");
+			close(fd);
+			return -1;
+		}
+
+		//Configurate user register
+		i2c_arg.Buf[0] = 0x02; //write
+		i2c_arg.Buf[1] = regAddr;
+		i2c_arg.Buf[2] = regVal;
+		i2c_arg.WriteLen = 3;
+		ret = ioctl(fd, I2C_MASTER_TRANSFER, &i2c_arg);
+		if(ret == -1)
+		{
+			printf("---> write error\n");
+			close(fd);
+			return -1;
+		}
+
+		//Save to NVM
+		i2c_arg.Buf[0] = 0x04; //write NVM
+		i2c_arg.WriteLen = 1;
+		ret = ioctl(fd, I2C_MASTER_TRANSFER, &i2c_arg);
+		if(ret == -1)
+		{
+			printf("---> write NVM error\n");
+			close(fd);
+			return -1;
+		}
+
+		//Enable NCP81111
+		i2c_arg.Buf[0] = 0x05; //Enter operation state
+		i2c_arg.Buf[1] = 0x09;
+		i2c_arg.WriteLen = 2;
+		ret = ioctl(fd, I2C_MASTER_TRANSFER, &i2c_arg);
+		if(ret == -1)
+		{
+			printf("---> Enter operation error\n");
+			close(fd);
+		}
+		sleep(1);
+	}
+
+	i2c_arg.Buf[0] = 0x01; //read
+	i2c_arg.Buf[1] = 0x00;	//register address
+	i2c_arg.WriteLen = 2;
+	i2c_arg.ReadLen = 110;
+	ret = ioctl(fd, I2C_MASTER_TRANSFER_RECEIVE, &i2c_arg);
+	if(ret == -1)
+	{
+		printf("---> read error!\n");
+		close(fd);
+		return -1;
+	}
+	else
+	{
+		printf("======= NCP81111 User Register Map ======= ");
+		for(i=0;i<i2c_arg.ReadLen;i++)
+		{
+			if(i%16 == 0) printf("\n%03d: ", i);
+			printf("%02x ", i2c_arg.Buf[i]);
+		}
+	}
+
+	i2c_arg.Buf[0] = 0x01; //read
+	i2c_arg.Buf[1] = 110;	//register address
+	i2c_arg.WriteLen = 2;
+	i2c_arg.ReadLen = 110;
+	ret = ioctl(fd, I2C_MASTER_TRANSFER_RECEIVE, &i2c_arg);
+	if(ret == -1)
+	{
+		printf("---> read error!\n");
+		close(fd);
+		return -1;
+	}
+	else
+	{
+		for(i=0;i<i2c_arg.ReadLen;i++)
+		{
+			if((i+110)%16 == 0) printf("\n%03d: ", i+110);
+			printf("%02x ", i2c_arg.Buf[i]);
+		}
+		printf("\n");
+	}
+
+	close(fd);
+	return 0;
+}

BIN
app/NCP81111_Config/ncp81111_cfg


+ 49 - 0
app/UpdateFirmware/Makefile

@@ -0,0 +1,49 @@
+EXEC		= updateFW_app
+
+CFLAGS		:= -Os -mcpu=cortex-m3 -mthumb
+LDFLAGS		:= -mcpu=cortex-m3 -mthumb -L$(INSTALL_ROOT)/A2F/root/usr/lib
+#BUILD_TIME 	= $(shell date +"%Y-%m-%d %H:%M:%S")
+
+
+
+CC	= $(CROSS_COMPILE_APPS)gcc
+
+#source
+SRC	= main.c
+
+# hal_api
+SRC += $(wildcard ../hal_api/*.c) 
+
+#incldue
+CFLAGS	+= -I$(INSTALL_ROOT)/A2F/root/usr/include
+CFLAGS	+= -I ./
+CFLAGS	+= -I ../common_include
+CFLAGS	+= -I ../driver
+CFLAGS	+= -I ../hal_api
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc/Legacy
+
+
+#library
+
+#sub-directory
+#SUBDIR 	= ./sensor
+
+
+
+
+
+
+$(EXEC): $(SRC)
+	#echo $(BUILD_TIME)
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS) -lpthread
+
+
+#object
+OBJS	= $(SRC:%.c=%.o)
+
+clean:
+	rm -f $(EXEC) $(OBJS)
+	rm -f *.gdb 
+

+ 101 - 0
app/UpdateFirmware/main.c

@@ -0,0 +1,101 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <linux/types.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <netdb.h>        /* getaddrinfo(3) et al.                       */
+#include <netinet/in.h>   /* sockaddr_in & sockaddr_in6 definition.      */
+#include  <net/if.h>
+#include <sys/prctl.h>
+#include "driver.h"
+#include "hal_interface_api.h"
+#include "main.h"
+
+int main()
+{
+	int i;
+	uint8_t buf[4*1024] = {0};	//4KB, one sector
+	uint8_t chkBuf[4*1024] = {0};
+	FILE *fp;
+	size_t len, totalSize = 1, writeSize = 0;
+	FILE *fprogress;
+	uint8_t progressStr[10] = {0};
+	uint8_t rate = 0;
+
+	fp = fopen("/var/www/goahead/tmp/tmp.uImage", "rb");
+	if(NULL == fp)
+	{
+		printf("Open image file fail!\n");
+		return -1;
+	}
+
+	//get file total size
+	fseek(fp, 0, SEEK_END);
+	totalSize = ftell(fp);
+	fseek(fp, 0, SEEK_SET);
+	printf("Image size: %d\n", totalSize);
+
+	
+
+	do{
+		len = fread(buf, 1, 4*1024, fp);
+		if(len <= 0)
+		{
+			close(fp);
+			printf("Read file fail!\n");
+			break;
+		}
+
+		//update Flash
+		sf_sector_erase(5, writeSize);
+		sf_write(5, writeSize, buf, len);
+		
+		// sf_read(5, writeSize, chkBuf, len);
+		// if(memcmp(buf, chkBuf, len) != 0)
+		// {
+		// 	printf("---> chk fail, offset %#x, len %d\n", writeSize, len);
+		// 	break;
+		// }
+	
+		writeSize += len;
+		rate = (writeSize*100)/totalSize;
+		printf("writeSize: %d, len: %d, rate: %d\n", writeSize, len, rate);			
+
+		//用来保存更新的进度
+		fprogress = fopen("/var/www/goahead/tmp/UpdateProgress.log", "w");
+		if(NULL == fp)
+		{
+			printf("Create UpdateProgress.log file fail!\n");
+			//return -1;
+		}
+		sprintf(progressStr, "%d", rate);
+		fputs(progressStr, fprogress);	
+		fclose(fprogress);	
+	}while(writeSize < totalSize);
+	
+	close(fp);
+
+	printf("Update Flash finish.\n");
+
+	//Verify
+	printf("Verigy successful.\n");
+	//用来保存校验结果
+	fprogress = fopen("/var/www/goahead/tmp/Verify.log", "w");
+	if(NULL == fp)
+	{
+		printf("Create UpdateProgress.log file fail!\n");
+	}
+	sprintf(progressStr, "Verify OK");
+	fputs(progressStr, fprogress);
+	fclose(fprogress);
+
+	fclose(fp);
+	return 0;
+}

+ 0 - 0
app/UpdateFirmware/main.h


BIN
app/UpdateFirmware/updateFW_app


+ 1036 - 0
app/bmc/Api.c

@@ -0,0 +1,1036 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <sys/ioctl.h>
+
+#include "main.h"
+#include "Api.h"
+#include "SDRRecord.h"
+#include "SELRecord.h"
+#include "SEL.h"
+#include "MsgHndlr.h"
+
+pthread_mutex_t Flash_Mutex;
+
+int PlatformInit(void)
+{
+	uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
+	printf("Init Platform...\r\n");
+
+	//hardware init
+	//槽位号识别
+	GPIO_InitTypeDef GPIO_InitStruct;
+	GPIO_InitStruct.Pin = GA0_PIN | GA1_PIN | GA2_PIN | GA3_PIN | GA4_PIN | RACKID2_PIN;
+	GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+	GPIO_InitStruct.Pull = GPIO_NOPULL;
+	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+	stm32_gpio_init(GPIOH, &GPIO_InitStruct);
+
+	GPIO_InitStruct.Pin = GAP_PIN | RACKID1_PIN | RACKID3_PIN | RACKID4_PIN | RACKID5_PIN;
+	stm32_gpio_init(GPIOI, &GPIO_InitStruct);
+
+	//LED灯 D2
+	GPIO_InitStruct.Pin = GPIO1_PIN;
+	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+	GPIO_InitStruct.Pull = GPIO_NOPULL;
+	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+	stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
+	stm32_gpio_init(GPIO1_PORT, &GPIO_InitStruct);
+
+	g_BMCInfo.SelfTestByte 	=	0;
+	g_BMCInfo.SlotID		=	PDK_GetSlotID();
+	g_BMCInfo.ChassisID		=	PDK_GetChassisID();
+
+	g_BMCInfo.PrimaryIPMBAddr = (0x40+(g_BMCInfo.SlotID&0x1F))<<1;
+	g_BMCInfo.SecondaryIPMBAddr = (0x40+(g_BMCInfo.SlotID&0x1F))<<1;
+	//LAN
+	LanInfo_T *pSetLanInfo = &g_BMCInfo.LanInfo[0];
+	strcpy(pSetLanInfo->EthName, "eth0");
+	pSetLanInfo->IPAddrSrc 	= 	0x01;	//static
+	pSetLanInfo->IPAddr[0] = 192;
+	pSetLanInfo->IPAddr[1] = 168;
+	pSetLanInfo->IPAddr[2] = 1;		//网段
+	pSetLanInfo->IPAddr[3] = 10+g_BMCInfo.SlotID; 
+	pSetLanInfo->BroadCast[0] = 192;
+	pSetLanInfo->BroadCast[1] = 168; 
+	pSetLanInfo->BroadCast[2] = 1; //网段
+	pSetLanInfo->BroadCast[3] = 255;	
+	pSetLanInfo->NetMask[0] = 255; 
+	pSetLanInfo->NetMask[1] = 255; 
+	pSetLanInfo->NetMask[2] = 255;
+	pSetLanInfo->NetMask[3] = 0;
+	pSetLanInfo->DefaultGW[0] 	= 	pSetLanInfo->IPAddr[0];
+	pSetLanInfo->DefaultGW[1] 	= 	pSetLanInfo->IPAddr[1];
+	pSetLanInfo->DefaultGW[2] 	= 	pSetLanInfo->IPAddr[2];
+	pSetLanInfo->DefaultGW[3] 	= 	1;
+	pSetLanInfo->MACAddr[0]	=	0; //no default mac
+	pSetLanInfo->MACAddr[1]	=	0;
+	pSetLanInfo->MACAddr[2]	=	0;
+	pSetLanInfo->MACAddr[3]	=	0;
+	pSetLanInfo->MACAddr[4]	=	0;
+	pSetLanInfo->MACAddr[5]	=	0;
+
+	//机箱及刀片信息
+	g_BMCInfo.ChassisIdentify		=	FALSE;
+	g_BMCInfo.ChassisIdentifyForce  = 	FALSE;
+	g_BMCInfo.ChassisIdentifyTimeout = 0;
+	g_BMCInfo.PowerGoodFlag =  	1;
+	g_BMCInfo.BladeManageEn = 0;
+	g_BMCInfo.isChMC 		= 0;
+
+	switch(g_BMCInfo.SlotID)
+	{
+		// case 0x:
+		// 	g_BMCInfo.IndexInChassis = 0;
+		// 	break;
+		case 0x6:
+			g_BMCInfo.IndexInChassis = 1;
+			break;
+		case 0x5:
+			g_BMCInfo.IndexInChassis = 2;
+			break;
+		case 0x4:
+			g_BMCInfo.IndexInChassis = 3;
+			break;
+		case 0x3:
+			g_BMCInfo.IndexInChassis = 4;
+			break;
+		case 0x9:
+			g_BMCInfo.IndexInChassis = 5;
+			break;
+		case 0xa:
+			g_BMCInfo.IndexInChassis = 7;
+			break;
+		case 0xb:
+			g_BMCInfo.IndexInChassis = 8;
+			break;
+		default:
+			g_BMCInfo.IndexInChassis = 0;
+	}
+
+	gBladeStatus[g_BMCInfo.IndexInChassis].healthStatus = 1;
+	memset(gBladeStatus[g_BMCInfo.IndexInChassis].bladeName,0,12);
+	memcpy(gBladeStatus[g_BMCInfo.IndexInChassis].bladeName,"光纤卡",12);
+	gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
+	gBladeStatus[g_BMCInfo.IndexInChassis].pwrStatus = g_BMCInfo.PowerGoodFlag;
+	
+	gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
+	
+	//init DevGUID
+	g_BMCInfo.DeviceGUID[0]	=	0x01;
+	g_BMCInfo.DeviceGUID[1]	=	0x01;
+	g_BMCInfo.DeviceGUID[2]	=	0x01;
+	g_BMCInfo.DeviceGUID[3]	=	0x01;
+	g_BMCInfo.DeviceGUID[4]	=	0x01;
+	g_BMCInfo.DeviceGUID[5]	=	0x01;
+	g_BMCInfo.DeviceGUID[6]	=	0x01;
+	g_BMCInfo.DeviceGUID[7]	=	0x01;
+	g_BMCInfo.DeviceGUID[8]	=	0x01;
+	g_BMCInfo.DeviceGUID[9]	=	0x01;
+	g_BMCInfo.DeviceGUID[10]	=	0x01;
+	g_BMCInfo.DeviceGUID[11]	=	0x01;
+	g_BMCInfo.DeviceGUID[12]	=	0x01;
+	g_BMCInfo.DeviceGUID[13]	=	0x01;
+	g_BMCInfo.DeviceGUID[14]	=	0x01;
+	g_BMCInfo.DeviceGUID[15]	=	0x01;
+	
+	g_BMCInfo.FwMajorVer		=	FW_VERSION_MAJOR;
+	g_BMCInfo.FwMinorVer		=	FW_VERSION_MINOR;
+	g_BMCInfo.SendMsgSeqNum				=	0;
+	
+	// g_BMCInfo.OemFlags.BladeWorkMode			=	BLADE_IPMC;
+	// g_BMCInfo.OemFlags.chassisManageFnEnable	=	0;
+	// g_BMCInfo.OemFlags.thisBladeIndex			=	0;
+	// g_BMCInfo.OemFlags.bladeStatus				=	1;	//0: not present, 1: normal, 2: error, others: reserved.
+	
+	g_BMCInfo.HealthLevel		=	SENSOR_STATUS_NORMAL;
+	g_BMCInfo.SensorSharedMem.SensorTick=	0;	
+	g_BMCInfo.SenConfig.PowerOnTick		=	0;
+	g_BMCInfo.SenConfig.SysResetTick	=	0;
+	g_BMCInfo.CurTimerTick				=	0;
+	g_BMCInfo.CurTimerSecond			=	0;
+	g_BMCInfo.BootValidMinutes			=	0;
+	g_BMCInfo.m_Lan_SetInProgress 		=	0;
+
+	return 0;
+}
+
+int InitTimerTaskTbl(void)
+{
+	printf("InitTimerTaskTbl...\n");
+	g_BMCInfo.TimerTaskTblSize = 2;
+    memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl, sizeof(TimerTaskTbl_T)*g_BMCInfo.TimerTaskTblSize);
+}
+
+int Init_SessionTbl(void)
+{
+	printf("Init_SessionTbl...\n");
+	g_BMCInfo.SessionHandle 					=	0;
+	g_BMCInfo.UDSSessionHandle 					=	0;
+
+	g_BMCInfo.IpmiConfig.MaxSession				= 	10;
+	g_BMCInfo.IpmiConfig.SessionTimeOut			= 	10;	//10s
+	g_BMCInfo.IpmiConfig.SendMsgTimeout			=	10;	//10s
+	
+	/*Allocating Memory to hold session Table informations */
+    g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
+    if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
+    {
+        printf("Error in allocating memory for SessionTbl \n");
+        return 1;
+    }
+    g_BMCInfo.SessionTblInfo.Count = 0;
+    /*Initialize the Session Table memory */
+    memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
+
+    /*Allocating Memory to hold UDS session Table informations */
+    g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl = (UDSSessionTbl_T *) malloc(sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
+    if(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl == NULL)
+    {
+        printf("Error in allocating memory for SessionTbl \n");
+        return 1;
+    }
+    g_BMCInfo.UDSSessionTblInfo.SessionCount = 0;
+    /*Initialize the UDS Session Table memory */
+    memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
+}
+
+const char FirstPowerOnStr[] = "First power on the bmc";
+int Init_IPMI_FRU_SDR_SEL(void)
+{
+	int i;
+	uint32_t	sdrSize =
+		sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
+	uint32_t	selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;	
+	uint8_t*	pSDR = NULL;
+	uint8_t*	pSEL = NULL;
+	
+	
+	g_BMCInfo.pSDR = malloc(sdrSize);
+	if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
+	{
+		printf("g_BMCInfo.pSDR Malloc failed!\r\n");
+	}
+	g_BMCInfo.pSEL = malloc(selSize);
+	if((g_BMCInfo.pSEL == NULL) && (selSize != 0))
+	{
+		printf("g_BMCInfo.pSEL Malloc failed!\r\n");
+	}
+	
+	GetIPMIFromFlash();
+	if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
+//	if(1)
+	{
+		//first power on
+		printf("\n\n*** BMC first power on! ***\n\n");
+		/************************** Init IPMI ******************************/
+		memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
+		
+		g_BMCInfo.IpmiConfig.SerialIfcSupport		=	SERIAL_IFC_SUPPORT;
+		g_BMCInfo.IpmiConfig.SerialTerminalSupport	=	SERIAL_TERMINAL_SUPPORT;
+		g_BMCInfo.IpmiConfig.LANIfcSupport			=	LAN_IFC_SUPPORT;
+		g_BMCInfo.IpmiConfig.SYSIfcSupport			=	SYS_IFC_SUPPORT;
+		g_BMCInfo.IpmiConfig.GrpExtnSupport 		= 	GROUP_EXTERN_SUPPORT;
+		g_BMCInfo.IpmiConfig.UDSIfcSupport			=	UDS_IFC_SUPPORT;
+		g_BMCInfo.IpmiConfig.ChassisTimerInterval	=	CHASSIS_TIMER_INTERVAL;	
+		g_BMCInfo.IpmiConfig.PowerCycleInterval		=	PWR_CYCLE_INTERVAL;
+		g_BMCInfo.IpmiConfig.FanControlInterval		=	FAN_CONTROL_INTERVAL;		
+		g_BMCInfo.IpmiConfig.RearmSetSensorThreshold	=	REARM_SET_SENSOR_THRESHOLD;
+		g_BMCInfo.IpmiConfig.SELTimeUTCOffset		=	8*60;
+		
+		//IPMB
+		g_BMCInfo.IpmiConfig.PrimaryIPMBSupport		=	PRIMARY_IPMB_SUPPORT;
+		g_BMCInfo.IpmiConfig.SecondaryIPMBSupport	=	SECONDARY_IPMB_SUPPORT;
+		g_BMCInfo.IpmiConfig.PrimaryIPMBBus 		= 	PRIMARY_IPMB_BUS;
+		g_BMCInfo.IpmiConfig.SecondaryIPMBBus 		= 	SECONDARY_IPMB_BUS;
+		
+		//Init FRU
+		memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
+		
+		/************************ Init SDR *************************************/
+
+		pSDR = g_BMCInfo.pSDR;
+		//init SDR repository header
+		((SDRRepository_T*)pSDR)->Signature[0]	=	0x00;
+		((SDRRepository_T*)pSDR)->Signature[1]	=	0x11;
+		((SDRRepository_T*)pSDR)->Signature[2]	=	0x22;
+		((SDRRepository_T*)pSDR)->Signature[3]	=	0x33;
+		
+		((SDRRepository_T*)pSDR)->NumRecords		=	SENSOR_NUMBERS + 1;
+		((SDRRepository_T*)pSDR)->Size			=	sdrSize;
+		((SDRRepository_T*)pSDR)->AddTimeStamp	=	0;
+		((SDRRepository_T*)pSDR)->EraseTimeStamp	=	0;
+		//init MgmtCtrlrDevLocator SDR
+		pSDR	+= sizeof(SDRRepository_T);
+		((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid	=	1;
+		((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len	=	sizeof(HdrMgmtCtrlrDevLocator_T); 
+		memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
+		//init FullSensorRec SDR
+		pSDR	+= sizeof(HdrMgmtCtrlrDevLocator_T);
+		for(i=0;i<SENSOR_NUMBERS;i++)
+		{
+			((HdrFullSensorRec_T*)pSDR)->Valid	=	1;
+			((HdrFullSensorRec_T*)pSDR)->Len	=	sizeof(HdrFullSensorRec_T); 
+			memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
+			pSDR	+= sizeof(HdrFullSensorRec_T);
+		}
+
+		
+		
+		
+		/******************************* Init SEL *************************************/	    
+		pSEL = g_BMCInfo.pSEL;
+		((SELRepository_T*)pSEL)->Signature[0] 	= 0x00;
+		((SELRepository_T*)pSEL)->Signature[1] 	= 0x11;
+		((SELRepository_T*)pSEL)->Signature[2] 	= 0x22;
+		((SELRepository_T*)pSEL)->Signature[3] 	= 0x33;
+		((SELRepository_T*)pSEL)->NumRecords	= 0;
+		((SELRepository_T*)pSEL)->Padding		= 0;
+		((SELRepository_T*)pSEL)->AddTimeStamp	= 0;
+		((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
+		((SELRepository_T*)pSEL)->FirstRecID	= 0;
+		((SELRepository_T*)pSEL)->LastRecID		= 0;
+		((SELRepository_T*)pSEL)->SELIndex		= 0;
+		((SELRepository_T*)pSEL)->SELRecord		= (SELRec_T*)(pSEL + sizeof(SELRepository_T));
+		
+		g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
+	    g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS		=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecordID	=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecOffset	=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.PartialAdd		=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.SenMonSELFlag	=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.MaxSELRecord	=	MAX_SEL_RECORD;
+	//    g_BMCInfo.SELConfig.RsrvIDCancelled	=	FALSE;
+	    g_BMCInfo.IpmiConfig.SELConfig.SELOverFlow		=	FALSE;
+	    g_BMCInfo.IpmiConfig.SELConfig.selalmostfull	=	0;
+		
+		memset(g_BMCInfo.UserInfoTbl, 0x0, sizeof(UserInfo_T)*MAX_USER_NUM);
+		g_BMCInfo.UserInfoTbl[2].UserId = 3;
+		strcpy(g_BMCInfo.UserInfoTbl[2].UserName, "admin");
+		strcpy(g_BMCInfo.UserInfoTbl[2].UserPassword, "admin");
+		g_BMCInfo.UserInfoTbl[2].UserStatus = TRUE;
+
+		g_BMCInfo.CurrentNoUser = 1;
+		g_BMCInfo.pUserInfo = NULL;
+
+		/************** Sensor History ****************/
+		memset(gSensorHistoryInfo, 0, sizeof(SensorHistoryInfo_T)*SENSOR_NUMBERS);
+		FlushSensorHistoryToFlash();
+
+		FlushUserInfoTbl();
+		UpdateFlash();
+	}
+	else
+	{
+		//Init FRU
+		GetFRUFromFlash();
+		
+		//Init SDR
+		GetSDRFromFlash();
+		
+		//Init SEL
+		GetSELFromFlash();
+		((SELRepository_T*)g_BMCInfo.pSEL)->SELRecord		= (SELRec_T*)(g_BMCInfo.pSEL + sizeof(SELRepository_T));
+
+		
+
+		g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
+	    g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS		=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecordID	=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecOffset	=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.PartialAdd		=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.SenMonSELFlag	=	0;
+	    g_BMCInfo.IpmiConfig.SELConfig.MaxSELRecord	=	MAX_SEL_RECORD;
+	//    g_BMCInfo.SELConfig.RsrvIDCancelled	=	FALSE;
+	    g_BMCInfo.IpmiConfig.SELConfig.SELOverFlow		=	FALSE;
+	    g_BMCInfo.IpmiConfig.SELConfig.selalmostfull	=	0;
+
+	    //Init SensorHistory
+		GetSensorHistoryFromFlash();
+
+	    UpdateUserInfoTble();
+		g_BMCInfo.CurrentNoUser = 0;
+		for(i=0;i<MAX_USER_NUM;i++)
+		{
+			if((g_BMCInfo.UserInfoTbl[i].UserId != 0) && (g_BMCInfo.UserInfoTbl[i].UserStatus == TRUE))
+				g_BMCInfo.CurrentNoUser++;
+		}
+		g_BMCInfo.pUserInfo = NULL;
+	}
+
+	g_BMCInfo.IpmiConfig.SDRConfig.UpdatingSDR	=	FALSE;
+	g_BMCInfo.IpmiConfig.SDRConfig.UpdatingChannel	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.TrackPOffset	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.TrackRecID		=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.IPMB_Seqnum		=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.PartAddbytes	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.LatestRecordID	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.NumMarkedRecords	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.Version	=	0x51;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.FreeSpace	=	0xffff;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.AddTimeStamp	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.EraseTimeStamp	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.OpSupport	=	0x23;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.NumAllocUnits	=	MAX_SENSOR_NUMBERS+1;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.AllocUnitSize	=	SDR_ALLOC_UNIT_SIZE;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits	=	MAX_SENSOR_NUMBERS - SENSOR_NUMBERS;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.LargestFreeBlock	=	SDR_MAX_RECORD_SIZE;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.MaxRecSize	=	SDR_MAX_RECORD_SIZE;	//Maximum record size in allocation units
+	g_BMCInfo.IpmiConfig.SDRConfig.SDRRAM			=	(SDRRepository_T*)g_BMCInfo.pSDR;
+	g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.RecCt	=	((SDRRepository_T*)g_BMCInfo.IpmiConfig.SDRConfig.SDRRAM)->NumRecords;
+	g_BMCInfo.IpmiConfig.SDRConfig.SDRError	=	0;
+	g_BMCInfo.IpmiConfig.SDRConfig.ReservationID	=	0;
+
+
+	
+	return 0;
+}
+
+
+int SetSysTime(uint32_t *timeSecond)
+{
+	time_t tt;
+	tt = *timeSecond;
+	stime(&tt);	//TODO:注意时区
+	return 0;
+}
+
+long int GetSysTime(void)
+{
+	time_t tt;
+	time(&tt);
+	//TODO: 注意时区
+	//tt += 8*60*60;	UTC+8
+	return tt;
+}
+
+int PostEventMessage (uint8_t *EventMsg,uint8_t size)
+{
+	uint8_t             SelReq [sizeof(SELEventRecord_T)];
+	uint8_t             SelRes [sizeof(AddSELRes_T)];
+	SELEventRecord_T*   SelRecord = ( SELEventRecord_T*) SelReq;
+
+	SelRecord->hdr.Type = 0x02;
+	SelRecord->hdr.TimeStamp = GetSysTime ();
+	memcpy (SelRecord->GenID, EventMsg, size);
+	
+	LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
+
+	return 0;
+}
+
+uint8_t PDK_GetSlotID(void)
+{
+	uint8_t SlotID = 0;
+	// uint8_t check = 0;
+
+	if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
+		SlotID |= 0x01;
+	if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
+		SlotID |= 0x02;
+	if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
+		SlotID |= 0x04;
+	if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
+		SlotID |= 0x08;
+	if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
+		SlotID |= 0x10;
+
+	// if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
+	// 	SlotID |= 0x20;
+
+	// int i;
+	// for(i=0;i<6;i++)
+	// 	check ^= (SlotID>>i)&0x01;
+
+	// if(check == 0)
+	// 	printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));
+
+	// return SlotID&0x1f;
+
+	return SlotID;
+
+}
+
+uint8_t PDK_GetChassisID(void)
+{
+	uint8_t ChassisID = 0;
+	// if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
+	// 	ChassisID |= 0x01;
+	// if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
+	// 	ChassisID |= 0x02;
+	// if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
+	// 	ChassisID |= 0x04;
+	// if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
+	// 	ChassisID |= 0x08;
+	// if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
+	// 	ChassisID |= 0x10;
+	// if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
+	// 	ChassisID |= 0x20;
+
+	return ChassisID;
+}
+
+int PDK_PowerOffChassis(void)
+{
+	//printf("Api power off chassis\n");
+	//g_BMCInfo.PowerGoodFlag = 0;
+	printf("Not support power control!\n");
+	return 0;
+}
+
+int PDK_PowerOnChassis(void)
+{
+	//printf("power on chassis\n");
+	//g_BMCInfo.PowerGoodFlag = 1;
+	printf("Not support power control!\n");
+}
+
+int PDK_SoftOffChassis(void)
+{
+	//printf("soft off chassis\n");
+	//g_BMCInfo.PowerGoodFlag = 0;
+	printf("Not support power control!\n");
+}
+
+int PDK_GetPowerStatus(void)
+{
+	//TODO:
+	return 1;
+}
+
+int PDK_PowerCycleChassis(void)
+{
+	//printf("power cycle chassis\n");
+	printf("Not support power control!\n");
+	return 0;
+}
+
+int PDK_ResetChassis(void)
+{
+	//printf("power reset chassis\n");
+	printf("Not support power control!\n");
+	return 0;
+}
+
+int PDK_DiagInterruptChassis(void)
+{
+	printf("power diag chassis\n");
+}
+
+int PDK_FanControl(void)
+{
+	;
+}
+
+//设置IP地址
+/*
+ * 函数名称 : int setip(char *ip)
+ * 函数功能 : 设置系统IP地址
+ * 参    数 : 
+ *char *ip :设置的IP地址,以点分十进制的字符串方式表示,如“192.168.0.5” 
+ * 返 回 值 : 0 : 成功 ;  -1 :  失败 
+ */
+int setip(char *ip)
+{
+    struct ifreq temp;
+    struct sockaddr_in *addr;
+    int fd = 0;
+    int ret = -1;
+    strcpy(temp.ifr_name, "eth0");
+    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
+    {
+      return -1;
+    }
+    addr = (struct sockaddr_in *)&(temp.ifr_addr);
+    addr->sin_family = AF_INET;
+    addr->sin_addr.s_addr = inet_addr(ip);
+    ret = ioctl(fd, SIOCSIFADDR, &temp);
+    close(fd);
+    if(ret < 0)
+       return -1;
+    return 0;
+}
+
+//获取IP地址
+/*
+ * 函数名称 : char * getip(char *ip_buf)
+ * 函数功能 : 获取系統IP地址
+ * 参    数 : 
+ *char *ip_buf :用来存放IP地址的内存空间
+ * 返 回 值 : ip_buf : 存放IP地址的内存地址
+ */
+char* getip(char *ip_buf)
+{
+    struct ifreq temp;
+    struct sockaddr_in *myaddr;
+    int fd = 0;
+    int ret = -1;
+    strcpy(temp.ifr_name, "eth0");
+    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
+    {
+        return NULL;
+    }
+    ret = ioctl(fd, SIOCGIFADDR, &temp);
+    close(fd);
+    if(ret < 0)
+        return NULL;
+    myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
+    strcpy(ip_buf, (char*)inet_ntoa(myaddr->sin_addr));
+    return ip_buf;
+}
+
+char* getnetmask(char *netmask_buf)
+{
+    struct ifreq temp;
+    struct sockaddr_in *myaddr;
+    int fd = 0;
+    int ret = -1;
+    strcpy(temp.ifr_name, "eth0");
+    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
+    {
+        return NULL;
+    }
+    ret = ioctl(fd, SIOCGIFNETMASK, &temp);
+    close(fd);
+    if(ret < 0)
+        return NULL;
+    myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
+    strcpy(netmask_buf, (char*)inet_ntoa(myaddr->sin_addr));
+
+    return netmask_buf;
+}
+
+char* getbroadcast(char *broadcast_buf)
+{
+    struct ifreq temp;
+    struct sockaddr_in *myaddr;
+    int fd = 0;
+    int ret = -1;
+    strcpy(temp.ifr_name, "eth0");
+    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
+    {
+        return NULL;
+    }
+    ret = ioctl(fd, SIOCGIFBRDADDR, &temp);
+    close(fd);
+    if(ret < 0)
+        return NULL;
+    myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
+    strcpy(broadcast_buf, (char*)inet_ntoa(myaddr->sin_addr));
+
+    return broadcast_buf;
+}
+
+
+char* getmac(char *mac_buf)
+{
+    struct ifreq temp;
+    struct sockaddr_in *myaddr;
+    int fd = 0;
+    int ret = -1;
+    strcpy(temp.ifr_name, "eth0");
+    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
+    {
+        return NULL;
+    }
+    if(ioctl(fd,SIOCGIFHWADDR,&temp)<0)
+    {
+        printf("Get mac address ioctl fail!\n");
+    }
+    else
+    {
+        sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
+                (unsigned char)temp.ifr_hwaddr.sa_data[0],
+                (unsigned char)temp.ifr_hwaddr.sa_data[1],
+                (unsigned char)temp.ifr_hwaddr.sa_data[2],
+                (unsigned char)temp.ifr_hwaddr.sa_data[3],
+                (unsigned char)temp.ifr_hwaddr.sa_data[4],
+                (unsigned char)temp.ifr_hwaddr.sa_data[5]);
+    }
+    close(fd);
+    return mac_buf;
+}
+
+int getSensorHistory(uint8_t sensorNum, uint8_t *phistoryBuf)
+{
+	int i =0;
+	for(i=0;i<SENSOR_NUMBERS;i++)
+	{
+		if(gSensorHistoryInfo[i].SensorNum == sensorNum)
+		{
+			memcpy(phistoryBuf, gSensorHistoryInfo[i].History, HISTORY_DATA_SIZE);
+			return 0;
+		}
+	}
+	
+	if(i >= SENSOR_NUMBERS)
+	{
+		printf("Warning: Can't find sensorNum!\n");
+		return -1;
+	}
+}
+
+
+pthread_mutex_t api_bridge_mutex;	
+int API_BridgeInternal(MsgPkt_T* pReqPkt, MsgPkt_T* pResPkt, uint8_t DestAddr, int Channel)
+{
+    
+    IPMIMsgHdr_T*  pReqMsgHdr;
+    IPMIMsgHdr_T*  pResMsgHdr;
+    uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
+	int 			RetVal;
+	int 			fd_BridgeQue;
+	uint8_t 		PBTbl;
+	
+	pthread_mutex_lock(&api_bridge_mutex);
+	//create BRIDGE_QUEUE
+    if(-1 != access(BRIDGE_QUEUE, F_OK))
+    {
+        remove(BRIDGE_QUEUE);
+    }
+    if(0 != mkfifo (BRIDGE_QUEUE, 0777))
+    {
+        printf("%s: Create %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
+        pthread_mutex_unlock(&api_bridge_mutex);
+        return -1;
+    }
+    fd_BridgeQue = open (BRIDGE_QUEUE, O_RDWR);
+    if(-1 == fd_BridgeQue)
+    {
+        printf("%s: Open %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
+        pthread_mutex_unlock(&api_bridge_mutex);
+        return -1;
+    }
+	
+    if(NULL != pReqPkt)
+    {
+		memcpy(&(pReqPkt->Data[sizeof(IPMIMsgHdr_T)]), pReqPkt->Data, pReqPkt->Size);
+		pReqPkt->Size += sizeof(IPMIMsgHdr_T);
+		pReqMsgHdr = (IPMIMsgHdr_T*)pReqPkt->Data;
+    }
+    else
+    {
+        printf("Warning: Message Packet to be bridged is NULL\r\n");
+		remove(BRIDGE_QUEUE);
+		pthread_mutex_unlock(&api_bridge_mutex);
+        return -1;
+    }    
+    if(NULL != pResPkt)
+    {
+      pResMsgHdr = (IPMIMsgHdr_T*)pResPkt->Data;
+    }
+    else
+    {
+        printf("Warning: Message Packet to be bridged is NULL\r\n");
+		remove(BRIDGE_QUEUE);
+		pthread_mutex_unlock(&api_bridge_mutex);
+        return -1;
+    }   
+    /* Format IPMI message header */
+    pReqMsgHdr->ResAddr  = DestAddr;
+	pReqMsgHdr->NetFnLUN = pReqPkt->NetFnLUN;
+    pReqMsgHdr->ChkSum   = ~(pReqMsgHdr->ResAddr + pReqMsgHdr->NetFnLUN) + 1;
+	
+    if(Channel == PRIMARY_IPMB_CHANNEL)
+    {
+        pReqMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr;	//PRIMARY_IPMB_ADDR;
+    }
+    else if(Channel == SECONDARY_IPMB_CHANNEL) 
+    {
+        pReqMsgHdr->ReqAddr = g_BMCInfo.SecondaryIPMBAddr;	//PRIMARY_IPMB_ADDR;
+    }
+    else
+    {
+        printf ("Warning: Invalid IPMB Channel: %d\r\n", Channel);
+		remove(BRIDGE_QUEUE);
+		pthread_mutex_unlock(&api_bridge_mutex);
+        return -1;
+    }
+	
+	pResPkt->NetFnLUN 	=	pReqPkt->NetFnLUN + 0x40;
+	pResPkt->Cmd 		=	pReqPkt->Cmd;
+	
+	pReqMsgHdr->Cmd		=	pReqPkt->Cmd;
+	
+	pResMsgHdr->ResAddr  = pReqMsgHdr->ReqAddr;
+	pResMsgHdr->ChkSum   = ~(pResMsgHdr->ResAddr + pResMsgHdr->NetFnLUN) + 1;
+	pResMsgHdr->ReqAddr	= pReqMsgHdr->ResAddr;
+	pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN;
+	pResMsgHdr->Cmd 	= pReqMsgHdr->Cmd;
+	
+	PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
+	/* Store in the table for response tracking */
+	while(TRUE)
+	{
+		if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
+		{			
+			m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = DEFAULT_TIMEOUT;
+	  
+			m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = pReqPkt->Channel; 
+			m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc  = ORIGIN_INT_REQ;
+			g_BMCInfo.SendMsgSeqNum = SeqNum;
+			
+			/* Format Sequence Number */
+			pReqMsgHdr->RqSeqLUN = ((g_BMCInfo.SendMsgSeqNum) << 2) & 0xFC;
+			pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN + 0x40;
+			
+			memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pReqMsgHdr, sizeof (IPMIMsgHdr_T));
+			memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pResMsgHdr,  sizeof (IPMIMsgHdr_T));
+			m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = fd_BridgeQue;
+			
+			/* Store Session ID for final response to the origin for KCS*/
+			//m_PendingBridgedResTbl[SeqNum].SrcSessionID = pReqPkt->SessionID;
+			
+			m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
+			//printf( "---> oemApi.c:  Bridged message added index = %d.\n", SeqNum );
+			
+			break;
+		}
+		else
+		{
+			SeqNum = (SeqNum + 1) & 0x3F;
+			if(SeqNum == g_BMCInfo.SendMsgSeqNum)
+			{
+				printf ("Warning: Pending Bridge Response Table is full \n");
+				remove(BRIDGE_QUEUE);
+				pthread_mutex_unlock(&api_bridge_mutex);
+				return -1;
+			}
+		}
+	}
+    
+    /* Format message packet */
+    pReqPkt->Channel = Channel;
+    pReqPkt->Param   = PARAM_BRIDGE;
+    
+    /* Recalculate the checksum */
+    pReqPkt->Data [pReqPkt->Size] =  CalculateCheckSum2 (pReqPkt->Data, pReqPkt->Size);
+	pReqPkt->Size++;
+    
+	if(Channel == PRIMARY_IPMB_CHANNEL) 
+	{
+		pReqPkt->SrcQ = gFd_PrimaryIpmbIfcQ; 
+	}
+	else if(Channel == SECONDARY_IPMB_CHANNEL)
+	{
+		pReqPkt->SrcQ = gFd_SecondaryIpmbIfcQ; 
+	}
+	else
+	{
+		printf("Warning: Invalid Channel %d\n", Channel);
+		remove(BRIDGE_QUEUE);
+		pthread_mutex_unlock(&api_bridge_mutex);
+		return -1;
+	}
+  
+    /* Post Message to the bridge queue */
+    if(0 != PostMsg(pReqPkt->SrcQ, pReqPkt) )
+    {
+        printf ("Warning: oemApi.c : Error posting message to Queue %p \n", pReqPkt->SrcQ);
+		remove(BRIDGE_QUEUE);
+		pthread_mutex_unlock(&api_bridge_mutex);
+        return -1;
+    }
+	
+	m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 1;
+	
+    RetVal = GetMsg (fd_BridgeQue, pResPkt, 5000);  //3s
+	remove(BRIDGE_QUEUE);
+	pthread_mutex_unlock(&api_bridge_mutex);
+	if(RetVal != 0)
+	{
+		return -1;
+	}
+	
+	memcpy(pResPkt->Data, &(pResPkt->Data[sizeof(IPMIMsgHdr_T)]), pResPkt->Size - sizeof(IPMIMsgHdr_T)-1);
+	pResPkt->Size = pResPkt->Size - sizeof(IPMIMsgHdr_T)-1;	//remove header & checksum2
+
+    return 0;
+}
+
+
+/***************** Flash 保存非易失数据 *******************/
+
+int FlushSDRToFlash()
+{
+	uint32_t 	writeLen = 0;
+	uint32_t 	offset = 0;
+	uint32_t	sdrSize =
+		sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
+		
+	pthread_mutex_lock(&Flash_Mutex);
+	while(sdrSize > 0)
+	{
+		if(sdrSize > 4*1024)
+			writeLen = 4*1024;
+		else
+			writeLen = sdrSize;
+
+		sf_sector_erase(5, SDR_FLASH_ADDR+offset);
+		sf_write(5, SDR_FLASH_ADDR+offset, g_BMCInfo.pSDR+offset, writeLen);
+		offset += writeLen;
+		sdrSize -= writeLen;
+	}
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int GetSDRFromFlash()
+{
+	uint32_t	sdrSize =
+		sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
+		
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_read(5, SDR_FLASH_ADDR, g_BMCInfo.pSDR, sdrSize);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int FlushSELToFlash()
+{
+	uint32_t 	writeLen = 0;
+	uint32_t 	offset = 0;
+	uint32_t	selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;	
+
+	pthread_mutex_lock(&Flash_Mutex);
+	while(selSize > 0)
+	{
+		if(selSize > 4*1024)
+			writeLen = 4*1024;
+		else
+			writeLen = selSize;
+
+		sf_sector_erase(5, SEL_FLASH_ADDR+offset);
+		sf_write(5, SEL_FLASH_ADDR+offset, g_BMCInfo.pSEL+offset, writeLen);
+		offset += writeLen;
+		selSize -= writeLen;
+	}
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int GetSELFromFlash()
+{
+	uint32_t	selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;	
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_read(5, SEL_FLASH_ADDR, g_BMCInfo.pSEL, selSize);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int FlushIPMIToFlash()
+{
+	uint32_t 	writeLen = 0;
+	uint32_t 	offset = 0;
+	uint32_t	ipmiSize = sizeof(IPMIConfig_T);
+	pthread_mutex_lock(&Flash_Mutex);
+	while(ipmiSize > 0)
+	{
+		if(ipmiSize > 4*1024)
+			writeLen = 4*1024;
+		else
+			writeLen = ipmiSize;
+
+		sf_sector_erase(5, IPMI_CFG_FLASH_ADDR+offset);
+		sf_write(5, IPMI_CFG_FLASH_ADDR+offset, ((uint8_t*)&g_BMCInfo.IpmiConfig)+offset, writeLen);
+		offset += writeLen;
+		ipmiSize -= writeLen;
+	}
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int GetIPMIFromFlash()
+{
+	uint32_t	ipmiSize = sizeof(IPMIConfig_T);
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_read(5, IPMI_CFG_FLASH_ADDR, (uint8_t*)&g_BMCInfo.IpmiConfig, ipmiSize);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int FlushFRUToFlash()
+{
+	uint32_t	fruSize = sizeof(OemFRUData_T);
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_sector_erase(5, FRU_FLASH_ADDR);
+	sf_write(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int GetFRUFromFlash()
+{
+	uint32_t	fruSize = sizeof(OemFRUData_T);
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_read(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int FlushSensorHistoryToFlash()
+{
+	uint32_t	writeLen = 0;
+	uint32_t 	offset = 0;
+	uint32_t	sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
+
+	pthread_mutex_lock(&Flash_Mutex);
+	while(sensorSize > 0)
+	{
+		if(sensorSize > 4*1024)
+			writeLen = 4*1024;
+		else
+			writeLen = sensorSize;
+
+		sf_sector_erase(5, SENSOR_HISTORY_FLASH_ADDR+offset);
+		sf_write(5, SENSOR_HISTORY_FLASH_ADDR+offset, ((uint8_t*)gSensorHistoryInfo)+offset, writeLen);
+		offset += writeLen;
+		sensorSize -= writeLen;
+	}
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int GetSensorHistoryFromFlash()
+{
+	uint32_t	sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
+
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_read(5, SENSOR_HISTORY_FLASH_ADDR, (uint8_t*)gSensorHistoryInfo, sensorSize);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+
+int FlushUserInfoTbl(void)
+{
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_sector_erase(5, USERTBL_FLASH_ADDR);
+	sf_write(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+int UpdateUserInfoTble(void)
+{
+	pthread_mutex_lock(&Flash_Mutex);
+	sf_read(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
+	pthread_mutex_unlock(&Flash_Mutex);
+	return 0;
+}
+
+
+int UpdateFlash(void)
+{
+	FlushSDRToFlash();
+	FlushSELToFlash();
+	FlushIPMIToFlash();
+	FlushFRUToFlash();
+	return 0;
+}

+ 54 - 0
app/bmc/Api.h

@@ -0,0 +1,54 @@
+#ifndef __API_H__
+#define __API_H__
+
+int PlatformInit(void);
+int Init_IPMI_FRU_SDR_SEL(void);
+int Init_SessionTbl(void);
+int InitTimerTaskTbl(void);
+
+int UpdateFlash(void);
+int SetSysTime(uint32_t *timeSecond);
+long int GetSysTime(void);
+#define SET_SYSTEM_TIME_STAMP(time) SetSysTime(time)
+#define GET_SYSTEM_TIME_STAMP GetSysTime
+
+int PostEventMessage (uint8_t *EventMsg,uint8_t size);
+
+ uint8_t PDK_GetSlotID(void);
+ uint8_t PDK_GetChassisID(void);
+ int PDK_PowerOffChassis(void);
+ int PDK_PowerOnChassis(void);
+ int PDK_SoftOffChassis(void);
+ int PDK_GetPowerStatus(void);
+ int PDK_PowerCycleChassis(void);
+ int PDK_ResetChassis(void);
+ int PDK_DiagInterruptChassis(void);
+ int PDK_FanControl(void);
+
+char* getip(char *ip_buf);
+int setip(char *ip);
+char* getnetmask(char *netmask_buf);
+char* getbroadcast(char *broadcast_buf);
+char* getmac(char *mac_buf);
+
+int FlushUserInfoTbl(void);
+int UpdateUserInfoTble(void);
+int GetSensorHistoryFromFlash();
+int FlushSensorHistoryToFlash();
+int GetFRUFromFlash();
+int FlushFRUToFlash();
+int GetIPMIFromFlash();
+int FlushIPMIToFlash();
+int GetSELFromFlash();
+int FlushSELToFlash();
+int GetSDRFromFlash();
+int FlushSDRToFlash();
+int UpdateFlash(void);
+
+	
+int API_BridgeInternal(MsgPkt_T* pReqPkt, MsgPkt_T* pResPkt, uint8_t DestAddr, int Channel);
+
+extern pthread_mutex_t api_bridge_mutex;
+extern pthread_mutex_t Flash_Mutex;
+
+#endif /* __API_H__ */

+ 35 - 0
app/bmc/AuthChip/CM_BURNFUZE.c

@@ -0,0 +1,35 @@
+// Burn Fuze
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include <stdint.h>
+#include <stdio.h>
+
+uint8_t ucCmdWrFuze[4] = {0xb4, 0x01, 0x00, 0x00};
+
+// Burn Fuse
+uint8_t cm_BurnFuse(uint8_t ucFuze)
+{
+	uint8_t ucReturn;
+	
+  // Burn Fuze
+	ucCmdWrFuze[2] = ucFuze;
+	if((ucReturn = CM_LOW_LEVEL.SendCommand(ucCmdWrFuze))!= SUCCESS) 
+	{
+		printf("---> cm_BurnFuse log1\n");
+		return ucReturn;
+	}
+	
+  // done	
+	ucReturn = CM_LOW_LEVEL.ReceiveRet(NULL,0);
+	if(ucReturn != SUCCESS)
+	{
+		printf("---> cm_BurnFuse log2\n");
+		return ucReturn;
+	}
+
+	return  SUCCESS;
+}

+ 41 - 0
app/bmc/AuthChip/CM_DATA.c

@@ -0,0 +1,41 @@
+// Data and Configuration for the CryptoMemory Library
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "hal_interface_api.h"
+// Data Structures that configure the low level CryptoMemory functions
+
+// CryptoMemory Low Level Linkage
+// 
+cm_low_level CM_LOW_LEVEL = {
+    cm_TRUE,         // Carddetect
+    cm_PowerOff,     // PowerOff
+    cm_PowerOn,      // PowerOn
+    cm_SendCommand,  // SendCommand
+    cm_ReceiveData,  // ReceiveRet
+    cm_SendData,     // SendData
+    cm_RandGen,      // RandomGen
+    cm_WaitClock,    // WaitClock
+    cm_SendCmdByte   // SendCmdByte
+};
+
+// CryptoMemory Low Level Configuration
+//
+// Note: the port address is included in a manner that does not require a chip
+//       specific header file. Note, the address of the port is the LAST address
+//       of the group of three addresses of the port (the port output register).
+//
+cm_port_cfg  CM_PORT_CFG = {
+    0xb0, // ucChipSelect        (0xb0 is default address for CryptoMemory)
+    0x32, // ucClockPort         (0x32 is PORTD)
+    0,    // ucClockPin          (SCL on bit 0)
+    0x32, // ucDataPort          (0x32 is PORTD)
+    2,    // ucDataPin           (SDA on bit 2)    
+    0x32, // ucCardSensePort     (0x32 is PORTD)
+    1,    // ucCardSensePin      (card sense switch, if any, on bit 2) 
+    TRUE, // ucCardSensePolarity (TRUE -> "1" on bit in register means card is inserted)
+    0x32, // ucPowerPort         (0x32 is PORTD)
+    3,    // ucPowerPin          (power control, if any, on bit 3)
+    TRUE, // ucPowerPolarity     (TRUE -> "1" on bit in register supplies power)
+    100,  // ucDelayCount
+    10    // ucStartTries
+};

+ 184 - 0
app/bmc/AuthChip/CM_GPA.c

@@ -0,0 +1,184 @@
+// Encryption Functions
+//
+// Note: the naming conventions in this module do not match those used in all other modules. This
+//       is because the name used in this module are intended to be as close to those used in the
+//       Atmel documentation to make verification of these functions simpler.
+
+#include "CM_GPA.h"
+#include <stdint.h>
+
+// -------------------------------------------------------------------------------------------------
+// Data
+// -------------------------------------------------------------------------------------------------
+
+uint8_t ucGpaRegisters[Gpa_Regs];
+
+// -------------------------------------------------------------------------------------------------
+// Functions
+// -------------------------------------------------------------------------------------------------
+
+// Reset the cryptographic state
+void cm_ResetCrypto(void)
+{
+    uint8_t i;
+    
+    for (i = 0; i < Gpa_Regs; ++i) ucGpaRegisters[i] = 0;
+    ucCM_Encrypt = ucCM_Authenticate = FALSE;
+}
+
+// Generate next value
+uint8_t cm_GPAGen(uint8_t Datain)
+{
+	uint8_t Din_gpa;
+	uint8_t Ri, Si, Ti;
+	uint8_t R_sum, S_sum, T_sum;
+	
+	// Input Character
+	Din_gpa = Datain^Gpa_byte;
+	Ri = Din_gpa&0x1f;   			                //Ri[4:0] = Din_gpa[4:0]
+	Si = ((Din_gpa<<3)&0x78)|((Din_gpa>>5)&0x07);   //Si[6:0] = {Din_gpa[3:0], Din_gpa[7:5]}
+	Ti = (Din_gpa>>3)&0x1f;  		                //Ti[4:0] = Din_gpa[7:3];
+       
+	//R polynomial
+	R_sum = cm_Mod(RD, cm_RotR(RG), CM_MOD_R);
+	RG = RF;
+	RF = RE;
+	RE = RD;
+	RD = RC^Ri;
+	RC = RB;
+	RB = RA;
+	RA = R_sum;
+	
+	//S ploynomial
+	S_sum = cm_Mod(SF, cm_RotS(SG), CM_MOD_S);
+	SG = SF;
+	SF = SE^Si;
+	SE = SD;
+	SD = SC;
+	SC = SB;
+	SB = SA;
+	SA = S_sum;
+	
+	//T polynomial
+	T_sum = cm_Mod(TE,TC,CM_MOD_T);
+	TE = TD;
+	TD = TC;
+	TC = TB^Ti;
+	TB = TA;
+	TA = T_sum;
+
+    // Output Stage
+    Gpa_byte =(Gpa_byte<<4)&0xF0;                                  // shift gpa_byte left by 4
+    Gpa_byte |= ((((RA^RE)&0x1F)&(~SA))|(((TA^TD)&0x1F)&SA))&0x0F; // concat 4 prev bits and 4 new bits
+	return Gpa_byte;
+}
+
+// Do authenticate/encrypt chalange encryption
+void cm_AuthenEncryptCal(uint8_t *Ci, uint8_t *G_Sk, uint8_t *Q, uint8_t *Ch)
+{	
+    uint8_t i, j;
+    
+    // Reset all registers
+		cm_ResetCrypto();//by jgw must attention this : its will infect ucCM_Authenticate and ucCM_Encrypt
+    
+    // Setup the cyptographic registers
+    for(j = 0; j < 4; j++) {
+	    for(i = 0; i<3; i++) cm_GPAGen(Ci[2*j]);	
+	    for(i = 0; i<3; i++) cm_GPAGen(Ci[2*j+1]);
+	    cm_GPAGen(Q[j]);
+    }
+	
+    for(j = 0; j<4; j++ ) {
+	    for(i = 0; i<3; i++) cm_GPAGen(G_Sk[2*j]);
+	    for(i = 0; i<3; i++) cm_GPAGen(G_Sk[2*j+1]);
+	    cm_GPAGen(Q[j+4]);
+    }
+	
+    // begin to generate Ch
+    cm_GPAGenN(6);                    // 6 0x00s
+    Ch[0] = Gpa_byte;
+
+    for (j = 1; j<8; j++) {
+	    cm_GPAGenN(7);                // 7 0x00s
+	    Ch[j] = Gpa_byte;
+    }
+	
+    // then calculate new Ci and Sk, to compare with the new Ci and Sk read from eeprom
+    Ci[0] = 0xff;		              // reset AAC 
+    for(j = 1; j<8; j++) {
+	    cm_GPAGenN(2);                // 2 0x00s
+	      Ci[j] = Gpa_byte;
+    }
+
+    for(j = 0; j<8; j++) {
+	     cm_GPAGenN(2);                // 2 0x00s
+	     G_Sk[j] = Gpa_byte;
+    }
+   
+	cm_GPAGenN(3);                    // 3 0x00s
+}
+
+// Calaculate Checksum
+void cm_CalChecksum(uint8_t *Ck_sum)
+{
+	cm_GPAGenN(15);                    // 15 0x00s
+	Ck_sum[0] = Gpa_byte;
+	cm_GPAGenN(5);                     // 5 0x00s
+	Ck_sum[1] = Gpa_byte;	
+}
+
+// The following functions are "macros" for commonly done actions
+
+// Clock some zeros into the state machine
+void cm_GPAGenN(uint8_t Count)
+{
+    while(Count--) cm_GPAGen(0x00);
+}
+
+// Clock some zeros into the state machine, then clock in a byte of data
+void cm_GPAGenNF(uint8_t Count, uint8_t DataIn)
+{
+    cm_GPAGenN(Count);                             // First ones are allways zeros
+    cm_GPAGen(DataIn);                             // Final one is sometimes different
+}
+
+// Include 2 bytes of a command into a polynominal
+void cm_GPAcmd2(uint8_t * pucInsBuff)
+{
+	  cm_GPAGenNF(5, pucInsBuff[2]);
+	  cm_GPAGenNF(5, pucInsBuff[3]);
+}
+    
+// Include 3 bytes of a command into a polynominal
+void cm_GPAcmd3(uint8_t * pucInsBuff)
+{
+	  cm_GPAGenNF(5, pucInsBuff[1]);
+	  cm_GPAcmd2(pucInsBuff);
+}
+    
+// Include the data in the polynominals and decrypt it required
+void cm_GPAdecrypt(uint8_t ucEncrypt, uint8_t * pucBuffer, uint8_t ucCount)
+{
+	  uint8_t i;
+	   
+	  for (i = 0; i < ucCount; ++i) {
+          if (ucEncrypt) pucBuffer[i] = pucBuffer[i]^Gpa_byte;
+ 	      cm_GPAGen(pucBuffer[i]);
+          cm_GPAGenN(5);        // 5 clocks with 0x00 data
+    }
+}
+
+// Include the data in the polynominals and encrypt it required
+void cm_GPAencrypt(uint8_t ucEncrypt, uint8_t * pucBuffer, uint8_t ucCount)
+{
+    uint8_t i, ucData; 
+
+  	for (i = 0; i<ucCount; i++) {
+  		cm_GPAGenN(5);                          // 5 0x00s
+  		ucData = pucBuffer[i];
+  		if (ucEncrypt) pucBuffer[i] = pucBuffer[i]^Gpa_byte;
+  		cm_GPAGen(ucData);
+  	}
+}
+
+

+ 61 - 0
app/bmc/AuthChip/CM_GPA.h

@@ -0,0 +1,61 @@
+
+#ifndef CM_GPA_H
+#define CM_GPA_H
+
+// -------------------------------------------------------------------------------------------------
+// Other includes required by this header file
+// -------------------------------------------------------------------------------------------------
+
+#include "CM_LIB.h"
+
+// Macros for all of the registers
+#define RA       (ucGpaRegisters[0])
+#define RB       (ucGpaRegisters[1])
+#define RC       (ucGpaRegisters[2])
+#define RD       (ucGpaRegisters[3])
+#define RE       (ucGpaRegisters[4])
+#define RF       (ucGpaRegisters[5])
+#define RG       (ucGpaRegisters[6])
+#define TA       (ucGpaRegisters[7])
+#define TB       (ucGpaRegisters[8])
+#define TC       (ucGpaRegisters[9])
+#define TD       (ucGpaRegisters[10])
+#define TE       (ucGpaRegisters[11])
+#define SA       (ucGpaRegisters[12])
+#define SB       (ucGpaRegisters[13])
+#define SC       (ucGpaRegisters[14])
+#define SD       (ucGpaRegisters[15])
+#define SE       (ucGpaRegisters[16])
+#define SF       (ucGpaRegisters[17])
+#define SG       (ucGpaRegisters[18])
+#define Gpa_byte (ucGpaRegisters[19])
+#define Gpa_Regs (20)
+
+
+// Defines for constants used
+#define CM_MOD_R (0x1F)
+#define CM_MOD_T (0x1F)
+#define CM_MOD_S (0x7F)
+
+// Macros for common operations
+#define cm_Mod(x,y,m) ((x+y)>m?(x+y-m):(x+y))
+#define cm_RotT(x)    (((x<<1)&0x1e)|((x>>4)&0x01))
+#define cm_RotR(x)    (((x<<1)&0x1e)|((x>>4)&0x01))
+#define cm_RotS(x)    (((x<<1)&0x7e)|((x>>6)&0x01))
+
+// Externals
+extern uint8_t ucGpaRegisters[Gpa_Regs];
+
+// Function Prototypes
+void cm_ResetCrypto(void);
+uint8_t cm_GPAGen(uint8_t Datain);
+void cm_CalChecksum(uint8_t *Ck_sum);
+void cm_AuthenEncryptCal(uint8_t *Ci, uint8_t *G_Sk, uint8_t *Q, uint8_t *Ch);
+void cm_GPAGenN(uint8_t Count);
+void cm_GPAGenNF(uint8_t Count, uint8_t DataIn);
+void cm_GPAcmd2(uint8_t * pucInsBuff);
+void cm_GPAcmd3(uint8_t * pucInsBuff);
+void cm_GPAdecrypt(uint8_t ucEncrypt, uint8_t * pucBuffer, uint8_t ucCount);
+void cm_GPAencrypt(uint8_t ucEncrypt, uint8_t * pucBuffer, uint8_t ucCount); 
+
+#endif

+ 353 - 0
app/bmc/AuthChip/CM_I2C.c

@@ -0,0 +1,353 @@
+// Functions that directly control the hardware
+
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include <unistd.h>
+#include <stdio.h>
+#include "linux/fcntl.h"
+#include "driver.h"
+#include <string.h>
+// Delay
+void cm_Delay(uint8_t ucDelay)
+{
+	// uint32_t ucTimer;
+	// uint8_t a = 1,b = 2;  
+ //    while(ucDelay) {
+ //    	ucTimer = 3000; //2000;
+ //        while(ucTimer) 
+ //        {
+ //            ucTimer--;
+ //            a = a*b;
+ //        }
+ //    	ucDelay--;
+ //    }	
+    usleep(ucDelay);
+}
+
+#if 0
+// 1/2 Clock Cycle transition to HIGH
+//
+void cm_Clockhigh(void)
+{
+    cm_Delay(1);
+    CM_CLK_HI;
+    cm_Delay(1);
+}
+
+// 1/2 Clock Cycle transition to LOW
+//
+void cm_Clocklow(void)
+{
+    cm_Delay(1);
+    CM_CLK_LO;
+    cm_Delay(1);
+}
+
+// Do one full clock cycle
+//
+// Changed 1/19/05 to eliminate one level of return stack requirements
+//
+void cm_ClockCycle(void)
+{
+    cm_Clocklow();
+    cm_Clockhigh();
+}
+
+// Do a number of clock cycles
+//
+void cm_ClockCycles(uint8_t ucCount)
+{
+    uint8_t i;
+    
+    for (i = 0; i < ucCount; ++i) cm_ClockCycle();
+}
+
+// Send a start sequence
+//
+// Modified 7-21-04 to correctly set SDA to be an output
+// 
+void cm_Start(void)
+{
+	cm_Delay(50);//by jgw for delay to avoid i2c dead because of too fast
+	  CM_DATA_OUT;                         // Data line must be an output to send a start sequence
+	  //cm_Clocklow();
+	  CM_DATA_HI;
+	  cm_Delay(4);
+	  cm_Clockhigh();
+	  cm_Delay(40);    //4
+	  CM_DATA_LO;
+	  cm_Delay(8);
+	  cm_Clocklow();
+	  cm_Delay(8);
+}
+
+// Send a stop sequence
+//
+// Modified 7-21-04 to correctly set SDA to be an output
+// 
+void cm_Stop(void)
+{
+	cm_Delay(10);//by jgw for delay to avoid i2c dead because of too fast
+	cm_Clocklow();
+    CM_DATA_OUT;                         // Data line must be an output to send a stop sequence
+	CM_DATA_LO;
+	cm_Delay(4); 
+	cm_Clockhigh();
+	cm_Delay(80);  //8
+	CM_DATA_HI;
+	cm_Delay(4);
+}
+
+// Write a byte
+//
+// Returns 0 if write successed, 1 if write fails failure
+//
+// Modified 7-21-04 to correctly control SDA
+// 
+uint8_t cm_Write(uint8_t ucData)
+{
+    uint8_t i;
+
+	cm_Delay(10);//by jgw for delay to avoid i2c dead because of too fast
+    CM_DATA_OUT;                         // Set data line to be an output
+    for(i=0; i<8; i++) {                 // Send 8 bits of data
+        cm_Clocklow();
+        if (ucData&0x80) CM_DATA_HI;
+        else             CM_DATA_LO;
+        cm_Clockhigh();
+        ucData = ucData<<1;
+    }
+    cm_Clocklow();
+
+    // wait for the ack
+    CM_DATA_IN;                      // Set data line to be an input
+    cm_Delay(8);
+    cm_Clockhigh();
+    while(i>1) {                    // loop waiting for ack (loop above left i == 8)
+        cm_Delay(2);
+        if (CM_DATA_RD) i--;        // if SDA is high level decrement retry counter
+        else i = 0;
+    }      
+    cm_Clocklow();
+    CM_DATA_OUT;                     // Set data line to be an output
+    return i;
+}
+
+// Send a ACK or NAK or to the device
+void cm_AckNak(uint8_t ucAck)
+{
+	cm_Delay(10);//by jgw for delay to avoid i2c dead because of too fast
+	CM_DATA_OUT;                         // Data line must be an output to send an ACK
+	cm_Clocklow();
+	if (ucAck) CM_DATA_LO;               // Low on data line indicates an ACK
+	else       CM_DATA_HI;               // High on data line indicates an NACK
+	cm_Delay(2);
+	cm_Clockhigh();
+	cm_Delay(8);
+	cm_Clocklow();
+}
+
+//     Read a byte from device, MSB
+//
+// Modified 7-21-04 to correctly control SDA
+// 
+uint8_t cm_Read(void)
+{
+	uint8_t i;
+	uint8_t rByte = 0;	
+	CM_DATA_IN;                          // Set data line to be an input
+	CM_DATA_HI;
+	for(i=0x80; i; i=i>>1)
+	{
+		cm_ClockCycle();
+		if (CM_DATA_RD) rByte |= i;
+		cm_Clocklow();
+	}
+	CM_DATA_OUT;                         // Set data line to be an output
+	return rByte;
+}
+#endif
+
+void cm_WaitClock(uint8_t loop)
+{
+	int ret;
+	
+    crypto_t crypto_arg;
+    crypto_arg.loop = loop;
+
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return;
+    }
+
+    ret = ioctl(fd, CRYPTO_WAIT_CLOCK, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_WaitClock error!\n");
+    }
+    close(fd);
+
+	// CM_DATA_LO;
+	// for(j=0; j<loop; j++) {
+	// 	cm_Start();
+	// 	for(i = 0; i<15; i++) cm_ClockCycle();
+	// 	cm_Stop();
+	// }
+}
+
+// Send a command
+//
+uint8_t cm_SendCommand(uint8_t * pucInsBuff)
+{
+    
+	
+    //uint8_t i, ucCmd;
+    //i = CM_START_TRIES;
+    //ucCmd = (pucInsBuff[0]&0x0F)|CM_PORT_CFG.ucChipSelect;
+    // while (i) {
+    //     cm_Start();
+    //     printf("cm_SendCommand ucCmd=%#x\n", ucCmd);
+    //     if (cm_Write(ucCmd) == 0) break;
+    //     if (--i == 0) {printf("---> cm_SendCommand log1\n"); return FAIL_CMDSTART;}
+    // }
+	
+    // for(i = 1; i< 4; i++) 
+    // {
+    //     cm_Delay(1);
+    //     printf("cm_SendCommand i=%d, data=%#x\n", i, pucInsBuff[i]);
+    //     if (cm_Write(pucInsBuff[i]) != 0) 
+    //     {
+    //         printf("---> cm_SendCommand log2, i = %d\n", i); 
+    //         return FAIL_CMDSEND;
+    //     }
+    // }
+    int ret;
+    crypto_t crypto_arg;
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return FAIL_CMDSEND;
+    }
+
+    crypto_arg.data[0] =  (pucInsBuff[0]&0x0F)|CM_PORT_CFG.ucChipSelect;
+    crypto_arg.data[1] = pucInsBuff[1];
+    crypto_arg.data[2] = pucInsBuff[2];
+    crypto_arg.data[3] = pucInsBuff[3];
+    crypto_arg.size = 4;
+    ret = ioctl(fd, CRYPTO_SEND_COMMAND, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_SendCommand failed!\n");
+        close(fd);
+        return FAIL_CMDSEND;
+    }
+    close(fd);
+    return SUCCESS;
+}
+
+uint8_t cm_ReceiveData(uint8_t * pucRecBuf, uint8_t ucLen)
+{
+    // int i;
+
+    // for(i = 0; i < (ucLen-1); i++) {
+    //     pucRecBuf[i] = cm_Read();
+    //     cm_AckNak(TRUE);
+    // }
+    // pucRecBuf[i] = cm_Read();
+    // cm_AckNak(FALSE);
+    // cm_Stop();
+    int ret;
+    crypto_t crypto_arg;
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return -1;
+    }
+    crypto_arg.size = ucLen;
+    ret = ioctl(fd, CRYPTO_RECEIVE_DATA, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_ReceiveData failed!\n");
+        close(fd);
+        return -1;
+    }
+    close(fd);
+
+    memcpy(pucRecBuf, crypto_arg.data, ucLen);
+    return SUCCESS;
+}
+
+uint8_t cm_SendData(uint8_t * pucSendBuf, uint8_t ucLen)
+{
+	// int i;
+	// for(i = 0; i< ucLen; i++) {
+	// 	if (cm_Write(pucSendBuf[i])==1) {printf("---> cm_SendData log1, i=%d\n", i); return FAIL_WRDATA;}
+	// }
+	// cm_Stop();
+
+    int ret;
+    crypto_t crypto_arg;
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return FAIL_WRDATA;
+    }
+
+    memcpy(crypto_arg.data, pucSendBuf, ucLen);
+    crypto_arg.size = ucLen;
+    ret = ioctl(fd, CRYPTO_SEND_DATA, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_SendData failed!\n");
+        close(fd);
+        return FAIL_WRDATA;
+    }
+    close(fd);
+	
+	return SUCCESS;
+}
+
+
+// Send a command byte
+//
+uint8_t cm_SendCmdByte(uint8_t ucCommand)
+{
+    // uint8_t i, ucCmd;
+	
+    // i = CM_START_TRIES;
+
+    // ucCmd = (ucCommand&0x0F)|CM_PORT_CFG.ucChipSelect;
+    // while (i) {
+    //   cm_Start();
+	   //  if (cm_Write(ucCmd) == 0) break;
+	   //  if (--i == 0) return FAIL_CMDSTART;
+    // }
+
+    int ret;
+    crypto_t crypto_arg;
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return FAIL_CMDSTART;
+    }
+
+    crypto_arg.data[0] = (ucCommand&0x0F)|CM_PORT_CFG.ucChipSelect;
+    
+    ret = ioctl(fd, CRYPTO_SEND_CMD_BYTE, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_SendCmdByte failed!\n");
+        close(fd);
+        return FAIL_CMDSTART;
+    }
+    close(fd);
+
+    return SUCCESS;
+}

+ 125 - 0
app/bmc/AuthChip/CM_I2C.h

@@ -0,0 +1,125 @@
+// CryptoMemory I2C Header File
+//
+// This library is used in all of the low level hardware interface for I2C communications.
+//
+// Revision Date      Changes
+// -------- --------- -----------------------------------------------------------------
+//    0.1   26 Oct 04 First Release
+
+// Protect Library against multiple inclusion
+#ifndef CM_I2C_H
+#define CM_I2C_H
+
+//#include "hal_interface_api.h"
+//#include "com_gpio.h"
+
+// -------------------------------------------------------------------------------------------------
+// Other includes required by this header file
+// -------------------------------------------------------------------------------------------------
+
+#include "CM_LIB.h"
+
+// //Ô¬¿­À¬»ø³ÌÐò
+// #define CM_DETECT_PI  (*(volatile unsigned char *)(CM_PORT_CFG.ucCardSensePort+IO_PORT_IN))
+// #define CM_DETECT_PD  (*(volatile unsigned char *)(CM_PORT_CFG.ucCardSensePort+IO_PORT_DIR))
+// #define CM_DETECT_PIN (CM_PORT_CFG.ucCardSensePin)
+// #define CM_DETECT_POL (CM_PORT_CFG.ucCardSensePolarity)
+// #define CM_DETECT_IN  CM_DETECT_PD&=~(1<<CM_DETECT_PIN)
+// #define CM_DETECT_RD  CM_DETECT_PI&(1<<CM_DETECT_PIN)
+
+// #define CM_POWER_PD  (*(volatile unsigned char *)(CM_PORT_CFG.ucPowerPort+IO_PORT_DIR))
+// #define CM_POWER_PO  (*(volatile unsigned char *)(CM_PORT_CFG.ucPowerPort+IO_PORT_OUT))
+// #define CM_POWER_PIN (CM_PORT_CFG.ucPowerPin)
+// #define CM_POWER_POL (CM_PORT_CFG.ucPowerPolarity)
+// #define CM_POWER_OUT CM_POWER_PD|=(1<<CM_POWER_PIN)
+// #define CM_POWER_HI  CM_POWER_PO|=(1<<CM_POWER_PIN)
+// #define CM_POWER_LO  CM_POWER_PO&=~(1<<CM_POWER_PIN)
+// #define CM_DATA_BIT   ((CM_DATA_PI>>CM_DATA_PIN)&1)
+
+// #define CM_CLK_PD     (*(volatile unsigned char *)(CM_PORT_CFG.ucClockPort+IO_PORT_DIR))
+// #define CM_CLK_PO     (*(volatile unsigned char *)(CM_PORT_CFG.ucClockPort+IO_PORT_OUT)) 
+// #define CM_CLK_PIN    (CM_PORT_CFG.ucClockPin)
+
+// #define CM_DATA_PI    (*(volatile unsigned char *)(CM_PORT_CFG.ucDataPort+IO_PORT_IN))
+// #define CM_DATA_PD    (*(volatile unsigned char *)(CM_PORT_CFG.ucDataPort+IO_PORT_DIR))
+// #define CM_DATA_PO    (*(volatile unsigned char *)(CM_PORT_CFG.ucDataPort+IO_PORT_OUT))
+// #define CM_DATA_PIN   (CM_PORT_CFG.ucDataPin)
+
+// #define rPIOA_OER   (*(volatile unsigned *)0x40020000 + 0x14)
+// #define rPIOA_ODR   (*(volatile unsigned *)0x40020000 + 0x10)
+
+// #define rPIOA_SODR  (*(volatile unsigned *)0x40020000 + 0x18)
+// #define rPIOA_CODR  (*(volatile unsigned *)0x40020000 + 0x1A)
+
+// #define rPIOA_PDSR	(*(volatile unsigned *)0x40020000 + 0x10)
+
+// #define SDA ((rPIOA_PDSR&PIN25)?1:0)        
+// /*================================Àî=====================================*/
+
+// #define IO_PORT_DIR (-1)
+// #define IO_PORT_OUT (0)
+
+#if 0
+#define GIO_DIR_INPUT 0x00
+#define GIO_DIR_OUTPUT 0x01
+
+
+
+#define GPIO_CLK GPIO_PIN_6
+#define PORT_CLK GPIOE
+#define GPIO_DATA GPIO_PIN_5
+#define PORT_DATA GPIOE
+
+#define CM_CLK_OUT stm32_gpio_direct(PORT_CLK,GPIO_CLK,GIO_DIR_OUTPUT)
+#define CM_CLK_HI  stm32_gpio_write(PORT_CLK,GPIO_CLK,GPIO_PIN_SET)
+#define CM_CLK_LO   stm32_gpio_write(PORT_CLK,GPIO_CLK,GPIO_PIN_RESET)
+
+
+#define CM_DATA_OUT stm32_gpio_direct(PORT_DATA,GPIO_DATA,GIO_DIR_OUTPUT)
+#define CM_DATA_IN    stm32_gpio_direct(PORT_DATA,GPIO_DATA,GIO_DIR_INPUT)
+#define CM_DATA_HI stm32_gpio_write(PORT_DATA,GPIO_DATA,GPIO_PIN_SET)
+#define CM_DATA_LO stm32_gpio_write(PORT_DATA,GPIO_DATA,GPIO_PIN_RESET)
+#define CM_DATA_RD   stm32_gpio_read(PORT_DATA,GPIO_DATA)
+
+#define CM_START_TRIES 10	//(CM_PORT_CFG.ucStartTries)
+
+// -------------------------------------------------------------------------------------------------
+// Macros that replace small common function
+// -------------------------------------------------------------------------------------------------
+
+#define CM_CLOCKHIGH  cm_Delay(1);(CM_CLK_HI);cm_Delay(1)
+#define CM_CLOCKLOW   cm_Delay(1);(CM_CLK_LO);cm_Delay(1)
+#define CM_CLOCKCYCLE cm_Delay(1);(CM_CLK_LO);cm_Delay(2);(CM_CLK_HI);cm_Delay(1)
+
+#endif /* #if 0 */
+// -------------------------------------------------------------------------------------------------
+// Low Level Function Prototypes
+// -------------------------------------------------------------------------------------------------
+
+// Placeholder function that always returns TRUE
+uint8_t cm_TRUE(void);
+
+void cm_PowerOn(void);   
+void cm_PowerOff(void);
+
+// Send Command
+uint8_t cm_SendCommand(uint8_t * pucCommandBuffer);
+
+// Receive Data
+uint8_t cm_ReceiveData(uint8_t * pucReceiveData, uint8_t ucLength);
+
+// Send Data 
+uint8_t cm_SendData(uint8_t * pucSendData, uint8_t ucLength);
+
+// Random
+void cm_RandGen(uint8_t * pucRandomData);
+
+// Wait Clock
+void cm_WaitClock(uint8_t ucLoop);
+
+// Send Command Byte
+uint8_t cm_SendCmdByte(uint8_t ucCommand);
+
+
+// end of multiple inclusion protection
+#endif

+ 48 - 0
app/bmc/AuthChip/CM_I2C_L.h

@@ -0,0 +1,48 @@
+// CryptoMemory I2C Very Low Level Header File
+//
+// This library is used in all of the low level hardware interface for I2C communications.
+//
+// Revision Date      Changes
+// -------- --------- -----------------------------------------------------------------
+//    0.1   07 Nov 04 First Release
+
+// Protect Library against multiple inclusion
+#ifndef CM_I2C_L_H
+#define CM_I2C_L_H
+
+// -------------------------------------------------------------------------------------------------
+// Other includes required by this header file
+// -------------------------------------------------------------------------------------------------
+
+
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#define CM_PWRON_CLKS (15)
+// Constants used in low level functions
+// Power on clocks (spec call for 5, but California Card uses 15)
+
+// Mid-Level Functions
+uint8_t cm_ReadCommand(uint8_t * pucInsBuff, uint8_t * pucRetVal, uint8_t ucLen);
+uint8_t cm_WriteCommand(uint8_t * pucInsBuff, uint8_t * pucSendVal, uint8_t ucLen);
+
+// Functions in CM_I2C.C used internally by other low level functions
+void cm_Clockhigh(void);
+void cm_Clocklow(void);
+void cm_ClockCycle(void);
+void cm_ClockCycles(uint8_t ucCount);
+void cm_Start(void);
+void cm_Stop(void);
+uint8_t cm_Write(uint8_t ucData);
+void cm_Ack(void);
+void cm_N_Ack(void);
+uint8_t cm_Read(void);
+void cm_WaitClock(uint8_t loop);
+uint8_t cm_SendCommand(uint8_t * pucInsBuff);
+uint8_t cm_ReceiveRet(uint8_t * pucRecBuf, uint8_t ucLen);
+uint8_t cm_SendDat(uint8_t * pucSendBuf, uint8_t ucLen);
+void cm_RandomGen(uint8_t * pucRanddat);
+
+void cm_Delay(uint8_t ucDelay);
+
+// end of multiple inclusion protection
+#endif

+ 190 - 0
app/bmc/AuthChip/CM_LIB.h

@@ -0,0 +1,190 @@
+// CryptoMemory Header File
+//
+// Detailed descriptions of all functions and structures in the header file can be found in
+// the "CryptoMemory Library User Manual".
+//
+// Revision Date      Changes
+// -------- --------- -----------------------------------------------------------------
+//    0.1   26 Oct 04 First Release
+//    0.2   19 Nov 04 Major additions and corrections
+
+// Protect Library against multiple inclusion
+#ifndef __CM_LIB_H__
+#define __CM_LIB_H__
+
+#include "com_IPMIDefs.h"
+// -------------------------------------------------------------------------------------------------
+// Definations
+// -------------------------------------------------------------------------------------------------
+
+// Basic Definations (if not available elsewhere)
+#ifndef FALSE
+#define FALSE (0)
+#define TRUE  (!FALSE)
+#endif
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+// Device Configuration Register
+#define DCR_ADDR      (0x18)
+#define DCR_SME       (0x80)
+#define DCR_UCR       (0x40)
+#define DCR_UAT       (0x20)
+#define DCR_ETA       (0x10)
+#define DCR_CS        (0x0F)
+
+// Cryptograms
+#define CM_Ci         (0x50)
+#define CM_Sk         (0x58)
+#define CM_G          (0x90)
+
+// Fuses
+#define CM_FAB        (0x06)
+#define CM_CMA        (0x04)
+#define CM_PER        (0x00)
+
+// Password
+#define CM_PSW        (0xB0)
+#define CM_PWREAD     (1)
+#define CM_PWWRITE    (0)
+
+// Return Code Defination
+#define SUCCESS       (0)
+#define FAILED        (1)
+#define FAIL_CMDSTART (2)
+#define FAIL_CMDSEND  (3)
+#define FAIL_WRDATA   (4)
+#define FAIL_RDDATA   (5)
+// note: additional specific error codes may be added in the future
+
+// -------------------------------------------------------------------------------------------------
+void cm_InitTwiPio(void);
+void cm_RestorPio(void);
+// High Level Function Prototypes
+
+// Select Chip
+uint8_t cm_SelectChip(uint8_t ucChipId);
+
+// Activate Security
+uint8_t cm_ActiveSecurity(uint8_t ucKeySet, uint8_t * pucKey, uint8_t * pucRandom, uint8_t ucEncrypt);
+
+// Deactivate Security
+uint8_t cm_DeactiveSecurity(void);
+
+// Verify Password
+uint8_t cm_VerifyPassword(uint8_t * pucPassword, uint8_t ucSet, uint8_t ucRW);
+
+// Reset Password
+uint8_t cm_ResetPassword(void);
+
+// Verify Secure Code
+//#define cm_VerifySecureCode(CM_PW) cm_VerifyPassword(CM_PWRON_CLKS, 7, CM_PWWRITE) 
+#define cm_VerifySecureCode(CM_PW) cm_VerifyPassword(CM_PW, 7, CM_PWWRITE) 
+
+// Read Configuration Zone
+uint8_t cm_ReadConfigZone(uint8_t ucCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount);
+
+// Write Configuration Zone
+uint8_t cm_WriteConfigZone(uint8_t ucCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount, uint8_t ucAntiTearing);
+
+// Set User Zone
+uint8_t cm_SetUserZone(uint8_t ucZoneNumber, uint8_t ucAntiTearing);
+
+// Read User Zone
+uint8_t cm_ReadLargeZone(uint32_t uiCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount);
+
+// Read Small User Zone
+uint8_t cm_ReadSmallZone(uint8_t ucCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount);
+
+// Write User Zone
+char cm_WriteLargeZone(uint32_t uiCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount);
+
+// Write Small User Zone
+uint8_t cm_WriteSmallZone(uint8_t ucCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount);
+
+// Send Checksum
+uint8_t cm_SendChecksum(uint8_t * pucChkSum);
+
+// Read Checksum
+uint8_t cm_ReadChecksum(uint8_t * pucChkSum);
+
+// Read Fuse Byte
+uint8_t cm_ReadFuse(uint8_t * pucFuze);
+
+// Burn Fuse
+uint8_t cm_BurnFuse(uint8_t ucFuze);
+
+void cm_InitTwiPio(void);
+
+void cm_RestorPio(void);
+
+void cm_InitCmVar(unsigned char Num);
+
+//加密访问API接口函数:用于认证加密
+int cm_Auth_Encrp(void);
+
+// -------------------------------------------------------------------------------------------------
+// Configuration Structures
+// -------------------------------------------------------------------------------------------------
+
+// CryptoMemory Low Level Linkage
+// 
+typedef struct{
+    uint8_t (*Carddetect)(void);
+    void (*PowerOff)(void);
+    void (*PowerOn)(void);
+    uint8_t (*SendCommand)(uint8_t * pucCommandBuffer);
+    uint8_t (*ReceiveRet)(uint8_t * pucReceiveData, uint8_t ucLength);
+    uint8_t (*SendData)(uint8_t * pucSendData, uint8_t ucLength);
+    void (*RandomGen)(uint8_t * pucRandomData);
+    void (*WaitClock)(uint8_t ucLoop);
+    uint8_t (*SendCmdByte)(uint8_t ucCommand);
+} cm_low_level;
+
+// CryptoMemory Low Level Configuration
+// 
+// If any of the supplied CryptoMemory low level library functions are used, this structure must be
+// present in the user code. For a detailed description of the elements in the structure, please
+// see the "CryptoMemory Library User Manual".
+// 
+typedef struct{
+    uint8_t ucChipSelect;
+    uint8_t ucClockPort;
+    uint8_t ucClockPin;
+    uint8_t ucDataPort;
+    uint8_t ucDataPin;
+    uint8_t ucCardSensePort;
+    uint8_t ucCardSensePin; 
+    uint8_t ucCardSensePolarity; 
+    uint8_t ucPowerPort;
+    uint8_t ucPowerPin;
+    uint8_t ucPowerPolarity;
+    uint8_t ucDelayCount;
+    uint8_t ucStartTries;
+} cm_port_cfg;
+
+// -------------------------------------------------------------------------------------------------
+// Externals for Configuration Structures
+// -------------------------------------------------------------------------------------------------
+
+extern cm_low_level CM_LOW_LEVEL;
+extern cm_port_cfg  CM_PORT_CFG;
+
+// -------------------------------------------------------------------------------------------------
+// Other Externals
+// -------------------------------------------------------------------------------------------------
+
+extern uint8_t ucCM_Encrypt;
+extern uint8_t ucCM_Authenticate;
+extern uint8_t ucCM_UserZone;
+extern uint8_t ucCM_AntiTearing;
+extern uint8_t ucCM_InsBuff[4];
+
+uint8_t cm_Auth_Encrp_Init(uint8_t authMode,uint8_t pswMode,uint8_t encryptFlag);
+uint8_t test_cryptomem(void);
+uint8_t cm_Auth_Encrp_Write(uint8_t userZone,uint8_t startInZone,uint8_t* writeData,uint8_t writeLen);
+uint8_t cm_Auth_Encrp_Read(uint8_t userZone,uint8_t startInZone,uint8_t* readData,uint8_t readLen);
+uint8_t cm_Auth_Encrp_Personal(uint8_t pswMode,uint8_t authMode);
+// end of multiple inclusion protection
+#endif

+ 78 - 0
app/bmc/AuthChip/CM_NOPOWER.c

@@ -0,0 +1,78 @@
+// Functions control the logical power on/off for the chip
+
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include <unistd.h>
+#include <stdio.h>
+#include "linux/fcntl.h"
+#include "driver.h"
+#include <string.h>
+// Power On Chip  
+//
+// Returns 0 (SUCCESS) if no error
+//
+void cm_PowerOn(void)   
+{
+//    printf("---> cm_PowerOn\n");
+	// Reset chip data
+	cm_ResetCrypto();
+    ucCM_UserZone = ucCM_AntiTearing = 0;
+    
+    int ret;
+    crypto_t crypto_arg;
+    crypto_arg.loop = CM_PWRON_CLKS;
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return;
+    }
+
+    ret = ioctl(fd, CRYPTO_POWER_ON, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_PowerOn failed!\n");
+        close(fd);
+        return;
+    }
+    close(fd);
+
+
+ //    // Sequence for powering on secure memory according to ATMEL spec
+ //    CM_DATA_OUT;                              // SDA and SCL start as outputs
+	// CM_CLK_OUT;
+ //    CM_CLK_LO;                                // Clock should start LOW
+ //    CM_DATA_HI;                               // Data high during reset
+ //    cm_ClockCycles(CM_PWRON_CLKS);            // Give chip some clocks cycles to get started
+
+    // Chip should now be in sync mode and ready to operate
+}
+
+// Shut down secure memory
+//
+void cm_PowerOff(void)
+{
+    printf("---> cm_PowerOff\n");
+	// cm_Delay(1);
+	// CM_CLK_LO;
+	// cm_Delay(6);
+
+    int ret;
+    crypto_t crypto_arg;
+    int fd = open("/dev/crypto", O_RDWR);
+    if(fd <= 0)
+    {
+        printf("Open /dev/crypto error!\n");
+        return;
+    }
+
+    ret = ioctl(fd, CRYPTO_POWER_OFF, &crypto_arg);
+    if(ret != 0)
+    {
+        printf("cm_PowerOff failed!\n");
+        close(fd);
+        return;
+    }
+    close(fd);
+}

+ 53 - 0
app/bmc/AuthChip/CM_PASSWORD.c

@@ -0,0 +1,53 @@
+// Verify Password
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+#include <stdio.h>
+
+uint8_t ucCmdPassword[4] = {0xba, 0x00, 0x00, 0x03};
+uint8_t ucPSW[3];
+
+// Verify Password
+uint8_t cm_VerifyPassword(uint8_t * pucPassword, uint8_t ucSet, uint8_t ucRW)
+{
+	uint8_t i, j;
+    uint8_t ucReturn;
+	uint8_t ucAddr;
+	
+	// Build command and PAC address
+    ucAddr = CM_PSW + (ucSet<<3);
+	ucCmdPassword[1] = ucSet;// to choose which sets of passwords
+	if (ucRW != CM_PWWRITE) {
+	  	ucCmdPassword[1] |= 0x10;
+	  	ucAddr += 4;
+	}
+	  
+	// Deal with encryption if in authenticate mode
+	for (j = 0; j<3; j++) {
+	    // Encrypt the password
+	    if(ucCM_Authenticate) {
+    	    for(i = 0; i<5; i++) cm_GPAGen(pucPassword[j]);
+    		ucPSW[j] = Gpa_byte;
+	  	}
+	    // Else just copy it
+		else ucPSW[j] = pucPassword[j];
+    }
+	  
+	// Send the command
+	ucReturn = cm_WriteCommand(ucCmdPassword, ucPSW, 3);
+    // Wait for chip to process password
+    CM_LOW_LEVEL.WaitClock(30);	//3
+   
+    // Read Password attempts counter to determine if the password was accepted
+    if (ucReturn == SUCCESS) {
+        ucReturn = cm_ReadConfigZone(ucAddr, ucPSW, 1);
+	    if (ucPSW[0]!= 0xFF) ucReturn = FAILED;
+	}
+	if (ucCM_Authenticate && (ucReturn != SUCCESS)) cm_ResetCrypto();
+    // Done
+    return ucReturn;
+}

+ 34 - 0
app/bmc/AuthChip/CM_RDCFG.c

@@ -0,0 +1,34 @@
+// Read Configuration Zone
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Read Configuration Zone
+uint8_t cm_ReadConfigZone(uint8_t ucCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount)
+{
+    uint8_t ucReturn, ucEncrypt;
+
+    ucCM_InsBuff[0] = 0xb6;
+    ucCM_InsBuff[1] = 0x00;
+    ucCM_InsBuff[2] = ucCryptoAddr;
+    ucCM_InsBuff[3] = ucCount;
+    
+    // Three bytes of the command must be included in the polynominals
+    cm_GPAcmd2(ucCM_InsBuff);
+    
+    // Do the read
+    if ((ucReturn = cm_ReadCommand(ucCM_InsBuff, pucBuffer, ucCount)) != SUCCESS) return ucReturn;
+	
+    // Only password zone is ever encrypted
+    ucEncrypt = ((ucCryptoAddr>= CM_PSW) && ucCM_Encrypt);
+
+    // Include the data in the polynominals and decrypt if required
+    cm_GPAdecrypt(ucEncrypt, pucBuffer, ucCount); 
+
+    // Done
+    return SUCCESS;
+}

+ 29 - 0
app/bmc/AuthChip/CM_RDCKSUM.c

@@ -0,0 +1,29 @@
+// Read Checksum
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+uint8_t	ucCmdRdChk[4] = {0xb6, 0x02, 0x00, 0x02};
+
+// Read Checksum
+uint8_t cm_ReadChecksum(uint8_t * pucChkSum)
+{
+    uint8_t ucDCR[1];
+	uint8_t ucReturn;
+
+    // 20 0x00s (10 0x00s, ignore first byte, 5 0x00s, ignore second byte, 5 0x00s  
+    cm_GPAGenN(20);
+	  
+    // Read the checksum                  
+    if((ucReturn = cm_ReadCommand(ucCmdRdChk, pucChkSum, 2))!= SUCCESS) return ucReturn;
+	
+    // Check if unlimited reads allowed
+    if ((ucReturn = cm_ReadConfigZone(DCR_ADDR, ucDCR, 1)) != SUCCESS) return ucReturn;
+    if ((ucDCR[0]&DCR_UCR)) cm_ResetCrypto();
+	
+    return SUCCESS;
+}

+ 27 - 0
app/bmc/AuthChip/CM_RDFUZE.c

@@ -0,0 +1,27 @@
+// Read Fuze Byte
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+uint8_t	ucCmdRdFuze[4] = {0xb6, 0x01, 0x00, 0x01};
+
+// Read Fuse Byte
+uint8_t cm_ReadFuse(uint8_t * pucFuze)
+{
+	uint8_t ucReturn;
+	
+  // 5 0x00, A2 (0x00), 5 0x00, N (0x01)	
+	cm_GPAGenNF(11, 0x01);
+
+	if((ucReturn = cm_ReadCommand(ucCmdRdFuze,pucFuze,1)) != SUCCESS) return ucReturn;
+	
+	cm_GPAGen(*pucFuze);         // fuze byte
+  cm_GPAGenN(5);               // 5 0x00s
+  
+	return SUCCESS;
+	
+}

+ 33 - 0
app/bmc/AuthChip/CM_RDUSER.c

@@ -0,0 +1,33 @@
+// Read User Zone
+//
+// The Read Large User Zone function is used to read data from CryptoMemory devices
+// that have greater than 256 bytes in each user zone (AT88SC6416C, and larger)
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Read User Zone
+uint8_t cm_ReadLargeZone(uint32_t uiCryptoAddr, uint8_t* pucBuffer, uint8_t ucCount)
+{
+    uint8_t ucReturn;
+
+    ucCM_InsBuff[0] = 0xb2;
+    ucCM_InsBuff[1] = (uint8_t)(uiCryptoAddr>>8);
+    ucCM_InsBuff[2] = (uint8_t)uiCryptoAddr;
+    ucCM_InsBuff[3] = ucCount;
+
+    // Three bytes of the command must be included in the polynominals
+    cm_GPAcmd3(ucCM_InsBuff);
+    
+    // Read the data
+    if ((ucReturn = cm_ReadCommand(ucCM_InsBuff, pucBuffer, ucCount)) != SUCCESS) return ucReturn;
+    
+    // Include the data in the polynominals and decrypt if required
+    cm_GPAdecrypt(ucCM_Encrypt, pucBuffer, ucCount); 
+
+    return SUCCESS;
+}
+

+ 38 - 0
app/bmc/AuthChip/CM_READ.c

@@ -0,0 +1,38 @@
+// Mid Level Utility Function: cm_ReadCommand()
+//
+// Note: this module must be after all low level functions in the library and
+//       before all high level user function to assure that any reference to
+//       this function in this library are satistified.
+
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include <unistd.h>
+#include <stdio.h>
+#include "linux/fcntl.h"
+#include "driver.h"
+#include <string.h>
+
+uint8_t cm_ReadCommand(uint8_t * pucInsBuff, uint8_t * pucRetVal, uint8_t ucLen)
+{ 
+    uint8_t ucReturn;
+    
+    if(ucLen < 1)
+    {
+        printf("Invalid ucLen %d\n", ucLen);
+        return -1;
+    }
+
+    if ((ucReturn = CM_LOW_LEVEL.SendCommand(pucInsBuff)) != SUCCESS) return ucReturn;
+    ucReturn = CM_LOW_LEVEL.ReceiveRet(pucRetVal, ucLen);
+
+    // printf("---> cm_ReadCommand: %#02x %#02x %#02x %#02x - ", pucInsBuff[0], pucInsBuff[1], pucInsBuff[2], pucInsBuff[3]);
+    // int i;
+    // for (i = 0; i < ucLen; i++)
+    // {
+    // 	printf("%#02x ", pucRetVal[i]);
+    // }
+    // printf("\n");
+
+    return ucReturn;
+}

+ 13 - 0
app/bmc/AuthChip/CM_RESETPSW.c

@@ -0,0 +1,13 @@
+// Reset Password
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+
+// Reset Password
+uint8_t cm_ResetPassword(void)
+{
+	   return CM_LOW_LEVEL.SendCmdByte(0xba);
+}

+ 19 - 0
app/bmc/AuthChip/CM_RESETSEC.c

@@ -0,0 +1,19 @@
+// Deactivate Security
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Deactivate Security
+uint8_t cm_DeactiveSecurity(void)
+{
+	uint8_t ucReturn;
+	 
+	if ((ucReturn = CM_LOW_LEVEL.SendCmdByte(0xb8)) != SUCCESS) return ucReturn;
+	cm_ResetCrypto();
+	
+	return SUCCESS;
+}

+ 22 - 0
app/bmc/AuthChip/CM_RND.c

@@ -0,0 +1,22 @@
+// Low quality random number generator
+
+#include <stdlib.h>
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "hal_interface_api.h"
+
+void cm_RandGen(uint8_t * pucRanddat)
+{
+	uint32_t random;
+	random = stm32_generate_random32bit();
+	pucRanddat[0] = (uint8_t) random;
+	pucRanddat[1] = (uint8_t) random>>8;
+	pucRanddat[2] = (uint8_t) random>>16;
+	pucRanddat[3] = (uint8_t) random>>24;
+	random = stm32_generate_random32bit();
+	pucRanddat[4] = (uint8_t) random;
+	pucRanddat[5] = (uint8_t) random>>8;
+	pucRanddat[6] = (uint8_t) random>>16;
+	pucRanddat[7] = (uint8_t) random>>24;
+}

+ 122 - 0
app/bmc/AuthChip/CM_SECURE.c

@@ -0,0 +1,122 @@
+// Activate Security
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+#include <stdio.h>
+
+// Local function prototypes
+static uint8_t cm_AuthenEncrypt(uint8_t ucCmd1, uint8_t ucAddrCi, uint8_t * pucCi, uint8_t * pucG_Sk, uint8_t * pucRandom);
+
+// Global Data
+uint8_t ucCM_Ci[8], ucCM_G_Sk[8];
+uint8_t ucCM_Q_Ch[16], ucCM_Ci2[8];
+
+// Activate Security
+//
+// When called the function:
+// ?reads the current cryptogram (Ci) of the key set, 
+// ?computes the next cryptogram (Ci+1) based on the secret key pucKey (GCi) and the random number selected,
+// ?sends the (Ci+1) and the random number to the CryptoMemory?device, 
+// ?computes (Ci+2) and compares its computed value the new cryptogram of the key set.
+// ?If (Ci+2) matches the new cryptogram of the key set, authentication was successful.
+// In addition, if ucEncrypt is TRUE the function:
+// ?computes the new session key (Ci+3) and a challenge, 
+// ?sends the new session key and the challenge to the CryptoMemory?device, 
+// ?If the new session key and the challenge are correctly related, encryption is activated.
+//
+uint8_t cm_ActiveSecurity(uint8_t ucKeySet, uint8_t * pucKey, uint8_t * pucRandom, uint8_t ucEncrypt)
+{
+    uint8_t i;
+    uint8_t ucAddrCi;
+	uint8_t ucReturn;
+    // Read Ci for selected key set
+    ucAddrCi = CM_Ci + (ucKeySet<<4);              // Ci blocks on 16 byte boundries
+    if ((ucReturn = cm_ReadConfigZone(ucAddrCi, ucCM_Ci, 8)) != SUCCESS)
+    {
+        printf("---> cm_ActiveSecurity log1 ucReturn %d\n", ucReturn);
+    	 return ucReturn;
+    }
+    // Try to activate authentication
+    for (i = 0; i < 8; ++i) 
+        ucCM_G_Sk[i] = pucKey[i];
+
+    if ((ucReturn = cm_AuthenEncrypt(ucKeySet, ucAddrCi, ucCM_Ci, ucCM_G_Sk, pucRandom)) != SUCCESS) 
+    {
+        printf("---> cm_ActiveSecurity log2 ucReturn %d\n", ucReturn);
+    	return ucReturn;
+    }
+    
+    ucCM_Authenticate = TRUE;
+        
+    // If Encryption required, try to activate that too
+    if (ucEncrypt) {
+        if (pucRandom) pucRandom += 8;
+        if ((ucReturn = cm_AuthenEncrypt(ucKeySet+0x10, ucAddrCi, ucCM_Ci, ucCM_G_Sk, pucRandom)) != SUCCESS) 
+        {
+            printf("---> cm_ActiveSecurity log3 ucReturn %d\n", ucReturn);
+        	return ucReturn;
+        }
+        ucCM_Encrypt = TRUE;
+    }
+    // Done
+    return SUCCESS;
+}
+
+// Common code for both activating authentication and encryption
+static uint8_t cm_AuthenEncrypt(uint8_t ucCmd1, uint8_t ucAddrCi, uint8_t * pucCi, uint8_t * pucG_Sk, uint8_t * pucRandom)
+{
+    uint8_t i;
+	uint8_t ucReturn;
+    
+    // Generate chalange data
+    if (pucRandom) 
+    	for (i = 0; i < 8; ++i) ucCM_Q_Ch[i] = pucRandom[i];
+    else           
+    	CM_LOW_LEVEL.RandomGen(ucCM_Q_Ch);
+
+    for (i = 0; i < 8; ++i) 
+    	ucCM_Q_Ch[i] = pucRandom[i];
+    cm_AuthenEncryptCal(pucCi, pucG_Sk, ucCM_Q_Ch, &ucCM_Q_Ch[8]);
+    
+    // Send chalange
+    ucCM_InsBuff[0] = 0xb8;
+    ucCM_InsBuff[1] = ucCmd1;
+    ucCM_InsBuff[2] = 0x00;
+    ucCM_InsBuff[3] = 0x10;
+    if ((ucReturn = cm_WriteCommand(ucCM_InsBuff, ucCM_Q_Ch, 16)) != SUCCESS) 
+    {
+        printf("cm_AuthenEncrypt log1 ucReturn %d\n", ucReturn);
+    	return ucReturn;
+    }
+                    
+    // Give chips some clocks to do calculations
+    CM_LOW_LEVEL.WaitClock(30); //3
+                             
+    // Verify result
+    if ((ucReturn = cm_ReadConfigZone(ucAddrCi, ucCM_Ci2, 8)) != SUCCESS)
+    {
+        printf("cm_AuthenEncrypt log2 ucReturn %d\n", ucReturn);
+    	return ucReturn;
+    }
+
+    // for(i=0;i<8;i++)
+    // {
+    //     printf("i=%d, %#x : %#x\n", i, pucCi[i], ucCM_Ci2[i]);
+    // }
+    
+    for(i=0; i<8; i++) 
+    {
+        
+        if (pucCi[i]!=ucCM_Ci2[i]) 
+        {
+        	return FAILED;
+        }
+    }
+    
+    // Done
+    return SUCCESS;
+}

+ 70 - 0
app/bmc/AuthChip/CM_SELECT.c

@@ -0,0 +1,70 @@
+// Select Device
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// -------------------------------------------------------------------------------------------------
+// Data
+// -------------------------------------------------------------------------------------------------
+
+uint8_t ucCM_DevGpaRegisters[16][Gpa_Regs];
+uint8_t ucCM_DevEncrypt[16];
+uint8_t ucCM_DevAuthenticate[16];
+uint8_t ucCM_DevUserZone[16];
+uint8_t ucCM_DevAntiTearing[16];
+
+// -------------------------------------------------------------------------------------------------
+// Functions
+// -------------------------------------------------------------------------------------------------
+
+// Select Chip
+uint8_t cm_SelectChip(uint8_t ucChipNew)
+{
+	uint8_t ucChip, i;
+	  
+    if (ucChipNew == 0xFF) {
+    	// Clear All State
+    	for (ucChip = 0; ucChip < 16; ++ucChip) {
+    	    for (i = 0; i < 16; ++i) ucCM_DevGpaRegisters[ucChip][i] = 0;
+            ucCM_DevEncrypt[ucChip] = 0;
+            ucCM_DevAuthenticate[ucChip] = 0;
+            ucCM_DevUserZone[ucChip] = 0;
+            ucCM_DevAntiTearing[ucChip] = 0;
+        }
+    }
+    else {
+    	ucChip = CM_PORT_CFG.ucChipSelect;
+    	if (ucChip != ucChipNew) {
+		    // Set Chip Select
+            CM_PORT_CFG.ucChipSelect = ucChipNew;
+			
+			// Shift Addresses
+    	    ucChip = (ucChip>>4)&0xF0;
+    	    ucChipNew = (ucChipNew>>4)&0xF0;
+			
+    	    // Swap GPA Registers
+    	    for (i = 0; i < 16; ++i) {
+			    ucCM_DevGpaRegisters[ucChip][i] = ucGpaRegisters[i];
+				ucGpaRegisters[i] = ucCM_DevGpaRegisters[ucChipNew][i];
+			}
+			
+			//Save State 
+            ucCM_DevEncrypt[ucChip] = ucCM_Encrypt;
+            ucCM_DevAuthenticate[ucChip] = ucCM_Authenticate;
+            ucCM_DevUserZone[ucChip] = ucCM_UserZone;
+            ucCM_DevAntiTearing[ucChip] = ucCM_AntiTearing;
+			
+            // Restore Saved State
+    	    ucCM_Encrypt = ucCM_DevEncrypt[ucChipNew];
+            ucCM_Authenticate = ucCM_DevAuthenticate[ucChipNew];
+            ucCM_UserZone = ucCM_DevUserZone[ucChipNew];
+            ucCM_AntiTearing = ucCM_DevAntiTearing[ucChipNew];
+        }
+    }
+	
+	return SUCCESS;
+}    	

+ 30 - 0
app/bmc/AuthChip/CM_SETUSER.c

@@ -0,0 +1,30 @@
+// Set User Zone
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_GPA.h"
+
+// Set User Zone
+uint8_t cm_SetUserZone(uint8_t ucZoneNumber, uint8_t ucAntiTearing)
+{
+	uint8_t ucReturn;
+	
+	ucCM_InsBuff[0] = 0xb4;
+	if (ucAntiTearing) ucCM_InsBuff[1] = 0x0b;
+	else 	           ucCM_InsBuff[1] = 0x03;
+    ucCM_InsBuff[2] = ucZoneNumber;
+	ucCM_InsBuff[3] = 0x00;
+
+    // Only zone number is included in the polynomial
+	cm_GPAGen(ucZoneNumber);
+	
+	if ((ucReturn = CM_LOW_LEVEL.SendCommand(ucCM_InsBuff))!= SUCCESS) return ucReturn;
+	
+	// save zone number and anti-tearing state
+    ucCM_UserZone = ucZoneNumber;
+    ucCM_AntiTearing = ucAntiTearing;
+
+    // done	
+	return  SUCCESS;//CM_LOW_LEVEL.ReceiveRet(NULL,0);
+}

+ 36 - 0
app/bmc/AuthChip/CM_SRDUSER.c

@@ -0,0 +1,36 @@
+// Read Small User Zone
+//
+// The Read Small User Zone function is used to read data from CryptoMemory devices that
+// have 256 bytes or less in each user zone (AT88SC3216C, and smaller)
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Read Small User Zone
+uint8_t cm_ReadSmallZone(uint8_t ucCryptoAddr, uint8_t* pucBuffer, uint8_t ucCount)
+{
+	uint8_t ucReturn;
+
+    ucCM_InsBuff[0] = 0xb2;
+    ucCM_InsBuff[1] = 0;
+    ucCM_InsBuff[2] = ucCryptoAddr;
+    ucCM_InsBuff[3] = ucCount;
+
+    // Two bytes of the command must be included in the polynominals
+    cm_GPAcmd2(ucCM_InsBuff);
+    
+    // Read the data
+    if ((ucReturn = cm_ReadCommand(ucCM_InsBuff, pucBuffer, ucCount)) != SUCCESS) return ucReturn;
+	
+    // Include the data in the polynominals and decrypt it required
+    cm_GPAdecrypt(ucCM_Encrypt, pucBuffer, ucCount); 
+
+    // Done
+    return SUCCESS;
+}
+
+
+

+ 35 - 0
app/bmc/AuthChip/CM_SWRUSER.c

@@ -0,0 +1,35 @@
+// Write Small User Zone
+//
+// The Write Small User Zone function is used to write data to CryptoMemory devices that have
+// 256 bytes or less in each user zone (AT88SC3216C, and smaller)
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Write Small User Zone
+uint8_t cm_WriteSmallZone(uint8_t  ucCryptoAddr, uint8_t* pucBuffer, uint8_t ucCount)
+{
+	uint8_t ucReturn;
+	
+	ucCM_InsBuff[0] = 0xb0;
+    ucCM_InsBuff[1] = 0x00;
+    ucCM_InsBuff[2] = ucCryptoAddr;
+    ucCM_InsBuff[3] = ucCount;
+
+    // Two bytes of the command must be included in the polynominals
+    cm_GPAcmd2(ucCM_InsBuff);
+    
+    // Include the data in the polynominals and encrypt it required
+    cm_GPAencrypt(ucCM_Encrypt, pucBuffer, ucCount); 
+
+	// Write the data
+	ucReturn = cm_WriteCommand(ucCM_InsBuff, pucBuffer,ucCount);
+
+	// when anti-tearing, the host should send ACK should >= 20ms after write command
+	if (ucCM_AntiTearing) CM_LOW_LEVEL.WaitClock(100);	//10
+
+	return ucReturn;
+}

+ 701 - 0
app/bmc/AuthChip/CM_TEST.c

@@ -0,0 +1,701 @@
+#include <stdio.h>
+
+#define CM_LIB_GLOBALES
+#define EXTERNMACRO 2
+
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include <string.h>
+#include <stdio.h>
+
+uint8_t ucData[16], ucCi[8], ucSk[8];
+// Zone Data
+uint8_t ucCM_UserZone;
+uint8_t ucCM_AntiTearing;
+
+// Chip state
+uint8_t ucCM_Encrypt;
+uint8_t ucCM_Authenticate;
+
+// Global data
+uint8_t ucCM_InsBuff[4];
+
+
+uint8_t authenticationModeFlag = 0;
+uint8_t passwordModeFlag = 0;
+uint8_t encryptModeFlag = 0;
+
+uint8_t errorGlobalFlag = 0;
+
+//default : four user zone use Secret Seed G1 and password write/read 1(all use set 1)
+		 
+//Secret Seed : it's used by cm_ActiveSecurity
+uint8_t ucG[8] = {0x22,0x23,0x34,0x45,0x56,0x67,0x78,0x89};
+//passworkd for write : it's used by cm_VerifyPassword
+uint8_t psword_w[3] = {0x22,0x34,0x56};
+//passworkd for read : it's used by cm_VerifyPassword
+uint8_t psword_r[3] = {0x88,0x9a,0xbc};
+uint8_t psword_7[3] = {0xDD, 0x77, 0x99};
+
+uint8_t cm_Auth_Encrp_Personal(uint8_t pswMode,uint8_t authMode)
+{
+
+	uint8_t ucReturn;
+	uint8_t pwData[8] = {0};
+	uint8_t seedData[8] = {0};
+	
+	uint8_t fab_id = 0x06;
+	uint8_t cma_id = 0x04;
+	uint8_t per_id = 0x00;	
+	uint8_t fuseData;	
+	int i;
+	uint8_t configAll[240] = {0};
+
+	printf("---> cm_Auth_Encrp_Personal start...\n");
+	//read fuse
+	cm_ReadFuse(&fuseData);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_ReadFuse is error\n");		
+		errorGlobalFlag = 12;
+	}
+	if(fuseData == 0x00)
+	{
+		printf("FAB,CMA,PER------three fuse has burnned! Exit cm_Auth_Encrp_Personal!\n");
+		return 0;
+	}
+	printf("---> fuseData %#x\n", fuseData);
+
+	uint8_t pwwr7[3] = {0xDD, 0x42, 0x97};
+	ucReturn = cm_VerifySecureCode(pwwr7);
+	if (ucReturn != SUCCESS)
+	{
+		ucReturn = cm_VerifySecureCode(psword_7);
+		if (ucReturn != SUCCESS)
+		{
+			printf("cm_VerifySecureCode 1 is error\n");		
+			errorGlobalFlag = 15;
+
+			/************ Read all configs *******************/
+			memset(configAll, 0, 240);
+			ucReturn = cm_ReadConfigZone(0x00,configAll,240);
+			if (ucReturn != SUCCESS)
+			{
+				printf("cm_ReadConfigZone all is error\n");
+				errorGlobalFlag = 13;
+			}
+			else
+			{
+				printf("======== Configure Memory =========");
+				for(i=0;i<240;i++)
+				{
+					if(i%8 == 0) printf("\n%04x:  ", i);
+					printf("%02X ", configAll[i]);
+				}
+				printf("\n");
+			}
+			return -1;
+		}
+		printf("---> used psword_7: %#x %#x %#x\n", psword_7[0], psword_7[1], psword_7[2]);
+	}
+	
+	// ----------------------------------------------write card mfg code 0x50 30 30 31
+	usleep(100);
+	uint8_t cmc[4] = {0x50,0x30,0x30,0x31};
+
+	ucReturn = cm_WriteConfigZone(0x0C, cmc, 4, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x0C is error\n");	
+		errorGlobalFlag = 2;
+		return -1;
+	}
+
+	// ----------------------------------------------Write Identification Number = 00000000012345
+	usleep(100);
+	uint8_t idnum[7] = {0x00,0x00,0x00,0x00,0x01,0x23,0x45};
+	ucReturn = cm_WriteConfigZone(0x19, idnum, 7, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x19 is error\n");			
+		errorGlobalFlag = 3;
+		return -1;
+	}
+	
+	
+	
+	// ----------------------------------------------Write Issuer Code = STATION 035
+	usleep(100);
+	uint8_t issue[16] = {0x53,0x54,0x41,0x54,0x49,0x4F,0x4E,0x20,0x30,0x33,0x35,0x00,0x00,0x00,0x00,0x00};
+	ucReturn = cm_WriteConfigZone(0x40, issue, 16, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x40 is error\n");	
+		
+		errorGlobalFlag = 4;
+		return -1;
+	}
+	
+	//---------------------------------------------config all user zone use the same password/seed of the set 1 
+	// ---------------------------------------------Write Control for user zone 0
+	usleep(100);
+	ucData[0] = ((pswMode & 0x03) << 6) | ((authMode & 0x3) << 4) | 0x07; // AR[0-3] = 0101 0111 ---->
+							 //01 ----> after Authentication successful ,then write correct password
+							 //01 ----> the read and write need to Authentication
+							 //1  ----> the host access(read/write) user zone use encryption mode(set 0 lead to unlock config zone error,i dont know why?)
+							 //111----> the default data
+	ucData[1] = 0x51;//Authentication set 1, POM set 1, Key 1        //PR[0-3] = 0101 0001
+					 //01 ----> the secret seed select set 1(secret seed zone)
+					 //01 ----> the POK select set 1(secret seed zone)
+					 //0001 ----> the password select set 1(password zone)
+	ucReturn = cm_WriteConfigZone(0x20, ucData, 2, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x20 is error\n");	
+		
+		errorGlobalFlag = 5;
+		return -1;
+	}
+	
+	
+	// ---------------------------------------------Write Control for user zone 1
+	usleep(100);
+	ucReturn = cm_WriteConfigZone(0x22, ucData, 2, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x22 is error\n");	
+		
+		errorGlobalFlag = 6;
+		return -1;
+	}
+	
+	// ---------------------------------------------Write Control for user zone 2
+	usleep(100);
+	ucReturn = cm_WriteConfigZone(0x24, ucData, 2, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x24 is error\n");	
+		
+		errorGlobalFlag = 7;
+		return -1;
+	}
+	
+	
+	// ---------------------------------------------Write Control for user zone 3
+	usleep(100);
+	ucReturn = cm_WriteConfigZone(0x26, ucData, 2, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x26 is error\n");	
+		
+		errorGlobalFlag = 8;
+		return -1;
+	}
+	
+
+	//----------------------------------------------Set DCR to allow unlimited checksum reads
+	usleep(100);
+	ucData[0] = 0xff;//after finish personal chip , must recover to the default 
+//	ucData[0] = 0xbf;//set unlimited checksum reads, Unlimited Authentication Trials,Eight Trials Allowed during debug for avoid the chip lock dead (why config 0x8f is error)
+	ucReturn = cm_WriteConfigZone(0x18, ucData, 1, FALSE);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_WriteConfigZone 0x18 is error\n");
+	
+		errorGlobalFlag = 9;
+		return -1;
+	}
+	
+	
+	
+	//---------------------------------------------- Write Ci1
+	usleep(100);
+	ucCi[0] = 0xFF;
+	ucCi[1] = 0x01;
+	ucCi[2] = 0x02;
+	ucCi[3] = 0x03;
+	ucCi[4] = 0x04;
+	ucCi[5] = 0x05;
+	ucCi[6] = 0x06;
+	ucCi[7] = 0x07;
+	ucReturn = cm_WriteConfigZone(0x60, ucCi, 8, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x60 is error\n");
+		
+		errorGlobalFlag = 10;
+		return -1;
+	}
+	
+	
+	
+	// ------------------------------------------------Write G1
+	usleep(100);
+	// user must set and remember this secret for Secret Seed,then must be same whih cm_Auth_Encrp_rw before access to user zone for write or read .
+	seedData[0] = ucG[0];
+	seedData[1] = ucG[1];
+	seedData[2] = ucG[2];
+	seedData[3] = ucG[3];
+	seedData[4] = ucG[4];
+	seedData[5] = ucG[5];
+	seedData[6] = ucG[6];
+	seedData[7] = ucG[7];
+	ucReturn = cm_WriteConfigZone(0x98, seedData, 8, FALSE);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_WriteConfigZone 0x98 is error\n");
+		
+		errorGlobalFlag = 11;
+		return -1;
+	}
+	
+	
+	
+	//--------------------------------------------- Write PSW1 (both Write and Read)
+	usleep(100);
+	// user must set and remember this secret for password for write/read.then must be same whih cm_Auth_Encrp_rw before access to user zone for write or read .
+	pwData[0] = 0xFF;
+	pwData[1] = psword_w[0];
+	pwData[2] = psword_w[1];
+	pwData[3] = psword_w[2];
+	pwData[4] = 0xFF;
+	pwData[5] = psword_r[0];
+	pwData[6] = psword_r[1];
+	pwData[7] = psword_r[2];
+	ucReturn = cm_WriteConfigZone(0xB8, pwData, 8, FALSE);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_WriteConfigZone 0xB8 is error\n");
+		
+		errorGlobalFlag = 12;
+		return -1;
+	}
+
+	//--------------------------------------------- Write PSW7 (only Write)
+	usleep(100);
+	pwData[0] = 0xFF;
+	pwData[1] = psword_7[0];
+	pwData[2] = psword_7[1];
+	pwData[3] = psword_7[2];
+	ucReturn = cm_WriteConfigZone(0xE8, pwData, 4, FALSE);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_WriteConfigZone 0xE8 is error\n");
+		
+		errorGlobalFlag = 13;
+		return -1;
+	}
+	
+#if 1
+	usleep(1000);
+	ucReturn = cm_BurnFuse(fab_id);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_BurnFuse fab_id is error\n");
+		
+		errorGlobalFlag = 12;
+	}
+	
+	usleep(1000);
+	ucReturn = cm_BurnFuse(cma_id);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_BurnFuse cma_id is error\n");
+		
+		errorGlobalFlag = 12;
+	}
+	
+	usleep(1000);
+	ucReturn = cm_BurnFuse(per_id);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_BurnFuse per_id is error\n");
+		
+		errorGlobalFlag = 12;
+	}
+#endif	
+
+	usleep(1000);
+	//read fuse
+	cm_ReadFuse(&fuseData);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_ReadFuse is error\n");		
+		errorGlobalFlag = 12;
+	}
+	if(fuseData == 0x00)
+	{
+		printf("FAB,CMA,PER------three fuse are burnned successful\n");
+	}
+
+
+	
+	/************ Read all configs *******************/
+	memset(configAll, 0, 240);
+	ucReturn = cm_ReadConfigZone(0x00,configAll,240);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_ReadConfigZone all is error\n");
+		errorGlobalFlag = 13;
+	}
+	else
+	{
+		printf("======== Configure Memory =========");
+		for(i=0;i<240;i++)
+		{
+			if(i%8 == 0) printf("\n%04x:  ", i);
+			printf("%02X ", configAll[i]);
+		}
+		printf("\n");
+	}
+
+	if(errorGlobalFlag != 0)
+		return FAILED;
+	
+	printf("---> cm_Auth_Encrp_Personal successful!\n");
+	return SUCCESS;		
+}
+
+/*
+*FUNC: To init the chip of AT88SCxxx
+*
+*PARAM:
+*		authMode : 
+*							3 : close Authentication mode;
+*							2 : write Authentication mode;
+*							1 : normal Authentication mode;
+*							0 : dual access mode;
+*
+*		pswMode : 
+*							3 : close password mode;
+*							2 : write password mode;
+*							0/1 : read and write password mode;
+*
+*		encryptFlag :
+*							TRUE  : enable encrypt mode
+*							FALSE : disable encrypt mode
+ *
+ */
+uint8_t cm_Auth_Encrp_Init(uint8_t authMode,uint8_t pswMode,uint8_t encryptFlag)
+{     
+	uint8_t ucReturn;
+	uint8_t fuseData;
+	int i;
+	uint8_t ucData[4] = {0};
+	uint8_t configAll[240] = {0};
+#if 0
+	//init I2C pin
+	GPIO_InitTypeDef GPIO_InitStruct;
+	GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_5;
+	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
+	GPIO_InitStruct.Pull = GPIO_PULLUP;
+	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+	stm32_gpio_init(GPIOE, &GPIO_InitStruct);
+#endif
+	if(pswMode == 0x0 || pswMode == 0x1)
+		passwordModeFlag = 1;
+	else if(pswMode == 0x2)
+		passwordModeFlag = 2;
+	else
+		passwordModeFlag = 0;
+	
+	if(authMode == 0)
+		authenticationModeFlag = 0;
+	else if(authMode == 1)
+		authenticationModeFlag = 1;
+	else if(authMode == 2)
+		authenticationModeFlag = 2;
+	else if(authMode == 3)
+		authenticationModeFlag = 3;
+	
+	if(encryptFlag == TRUE)
+		encryptModeFlag = 1;
+	else
+		encryptModeFlag = 0;
+	
+	cm_PowerOn(); 				
+			
+	/**************** Check AT88SC0104C Present******************/
+	ucData[0] = 0x5A;
+	ucData[1] = 0xA5;
+	ucReturn = cm_WriteConfigZone(0x0A, ucData, 2, FALSE);
+	if (ucReturn != SUCCESS)
+	{
+		printf("cm_WriteConfigZone 0x0a is error\n");
+		errorGlobalFlag = 1;
+	}
+	
+	usleep(100);	//这个延时很重要,AT88SC0104C处理数据相当的慢。
+	// Read back data
+	ucData[0] = 0x00;
+	ucData[1] = 0x00;
+	ucReturn = cm_ReadConfigZone(0x0A, ucData, 2);
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_ReadConfigZone 0x0a is error\n");		
+		errorGlobalFlag = 1;
+	}
+	if ((ucData[0]!= 0x5A) || (ucData[1]!= 0xA5) )
+	{
+		printf("read back data is not same\n");
+		errorGlobalFlag = 1;
+	}
+	
+	if(errorGlobalFlag != 0)
+	{
+		printf("there is a error and the flag = %d,the poweroff\n",errorGlobalFlag);
+			
+		cm_PowerOff();
+		
+		return FAILED;
+	}
+
+	return ucReturn;
+}
+ 
+/*
+ *cm_WR: 
+ *				0 : read
+ *				1 : write
+ *userZone: 
+ *				select need to access the index of user zone in range of 0-3
+ *startInZone:
+ *				the start location in user zone for user operation of write/read,and the default data is 0
+ *pData:
+ *				the data buffer for store the write/read data
+ *dataLen:
+ *				the byte number of write/read
+ *
+*/
+uint8_t cm_Auth_Encrp_rw(uint8_t cm_WR,uint8_t userZone,uint8_t startInZone,uint8_t *pData,uint8_t dataLen)
+{  		
+	uint8_t ucReturn;
+	int i;
+	uint8_t userZoneTemp = userZone & 0x03;
+ 
+	uint8_t seedSet = 1;//which set of Secret Seed
+	uint8_t pwset = 1;//which set of password for write/read
+	
+	//if(authenticationModeFlag == 0 || authenticationModeFlag == 1 || authenticationModeFlag == 2 || authenticationModeFlag == 3)//all to authenticate
+	{
+		if(encryptModeFlag == 1)
+		{
+			ucReturn = cm_ActiveSecurity(seedSet, ucG, NULL, TRUE);
+		}
+		else
+		{
+			ucReturn = cm_ActiveSecurity(seedSet, ucG, NULL, FALSE);
+		}
+	}
+	
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_ActiveSecurity is error\n");		
+		return FAILED;
+	}
+
+	ucReturn = cm_SetUserZone(userZoneTemp, FALSE);
+	
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_SetUserZone is error\n");		
+		return FAILED;
+	}
+	
+	if(passwordModeFlag == 3)
+	{
+		if(cm_WR==0)
+		{
+			// Read back data
+			for (i = 0; i < dataLen; ++i) 
+				pData[i] = 0x00;  //clear pData
+			ucReturn = cm_ReadSmallZone(startInZone, pData, dataLen);
+			if (ucReturn != SUCCESS) 
+			{
+				printf("cm_ReadSmallZone is error\n");
+				
+				return FAILED;
+			}
+		}
+		else
+		{
+			// Write data to user zone
+			ucReturn = cm_WriteSmallZone(startInZone, pData, dataLen);
+			if (ucReturn != SUCCESS) 
+			{
+				printf("cm_WriteSmallZone is error\n");
+				
+				return FAILED;
+			}
+			// Send checksum
+			ucReturn = cm_SendChecksum(NULL);
+			if (ucReturn != SUCCESS) 
+			{
+				printf("cm_SendChecksum is error\n");
+				
+				return FAILED;
+			}
+		}
+	}
+	else  //(passwordModeFlag == 1 || passwordModeFlag == 2)
+	{  
+			ucCM_Authenticate = TRUE;
+		
+			if(cm_WR==0)
+			{
+				// Read back data, firstly verify the read password
+				ucReturn=cm_VerifyPassword(psword_r,pwset,CM_PWREAD);					
+				if (ucReturn != SUCCESS) 
+				{
+					printf("cm_VerifyPassword is error\n");
+					
+					return FAILED;
+				}
+				
+				for (i = 0; i < dataLen; ++i) 
+					pData[i] = 0x00;  //clear pData
+				
+				ucReturn = cm_ReadSmallZone(startInZone, pData, dataLen);
+				if (ucReturn != SUCCESS) 
+				{
+					printf("cm_ReadSmallZone is error\n");
+					
+					return FAILED;
+				}
+			
+				ucReturn =cm_ReadChecksum(NULL);
+				if (ucReturn != SUCCESS) 
+				{
+					printf("cm_ReadChecksum is error\n");
+					
+					return FAILED;
+				}
+			}
+		else
+		{
+			// Write data to user zone,firstly verify the write password
+			ucReturn=cm_VerifyPassword(psword_w,pwset,CM_PWWRITE);
+			if (ucReturn != SUCCESS) 
+			{
+				printf("cm_VerifyPassword is error\n");
+				
+				return FAILED;
+			}
+			
+			ucReturn = cm_WriteSmallZone(startInZone, pData, dataLen);
+			if (ucReturn != SUCCESS) 
+			{
+				printf("cm_WriteSmallZone is error\n");
+				
+				return FAILED;
+			}
+			
+			// Send checksum
+			ucReturn = cm_SendChecksum(NULL);
+			if (ucReturn != SUCCESS) 
+			{
+				printf("cm_SendChecksum is error\n");
+				
+				return FAILED;
+			}
+		 }
+	}
+		
+	ucReturn = cm_DeactiveSecurity();
+
+	if (ucReturn != SUCCESS) 
+	{
+		printf("cm_DeactiveSecurity is error\n");
+		
+		return FAILED;
+	}
+	
+  return SUCCESS;
+}
+
+
+
+uint8_t cm_Auth_Encrp_Read(uint8_t userZone,uint8_t startInZone,uint8_t* readData,uint8_t readLen)
+{
+	uint8_t returnData = 0;
+	
+	returnData = cm_Auth_Encrp_rw(0,userZone,startInZone,readData,readLen);
+	
+	if(returnData != SUCCESS)
+		return FAILED;
+	else
+		return SUCCESS;
+}
+
+
+uint8_t cm_Auth_Encrp_Write(uint8_t userZone,uint8_t startInZone,uint8_t* writeData,uint8_t writeLen)
+{
+	uint8_t returnData = 0;
+	
+	returnData = cm_Auth_Encrp_rw(1,userZone,startInZone,writeData,writeLen);
+	
+	if(returnData != SUCCESS)
+		return FAILED;
+	else
+		return SUCCESS;
+}
+
+
+
+uint8_t test_cryptomem(void)
+{
+	uint8_t readData[16] = {0};
+	uint8_t readLen = 16;
+	uint8_t writeData[16] = {0};
+	uint8_t writeLen = 16;
+	uint8_t i;
+	uint8_t returnData;
+	
+	uint8_t userZone = 1;//user need to access the index of user zone
+	uint8_t startInZone = 0;//the start location of x user zone for write/read
+
+	// returnData = cm_Auth_Encrp_Init(1,1,TRUE); 
+	// if(returnData != SUCCESS)
+	// {
+	// 	printf("cm_Auth_Encrp_Init is error\n");
+		
+	// 	return FAILED;
+	// }
+
+//	printf("Write: \n");
+	for(i=0;i<writeLen;i++) 
+	{
+		writeData[i] = '6' + i;
+//		printf("%#x ", writeData[i]);
+	}
+//	printf("\n");
+	
+	returnData = cm_Auth_Encrp_Write(userZone,startInZone,writeData,writeLen); 
+	if(returnData != SUCCESS)
+	{
+		printf("cm_Auth_Encrp_Read is error\n");
+		
+		return FAILED;
+	}
+	
+	usleep(100);
+	returnData = cm_Auth_Encrp_Read(userZone,startInZone,readData,readLen); 
+	if(returnData != SUCCESS)
+	{
+		printf("cm_Auth_Encrp_Read is error\n");		
+		return FAILED;
+	}
+
+	printf("Crypto Check ok!\n");
+	return SUCCESS;
+}
+
+
+
+
+
+
+
+
+

+ 10 - 0
app/bmc/AuthChip/CM_TRUE.c

@@ -0,0 +1,10 @@
+// Function return TRUE
+//
+
+#include "CM_LIB.h"
+
+uint8_t cm_TRUE(void)
+{
+	   return TRUE;
+}
+

+ 38 - 0
app/bmc/AuthChip/CM_WRCFG.c

@@ -0,0 +1,38 @@
+// Write Configuration Zone
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Write Configuration Zone
+uint8_t cm_WriteConfigZone(uint8_t ucCryptoAddr, uint8_t* pucBuffer, uint8_t ucCount, uint8_t ucAntiTearing)
+{
+//    printf("\n===> cm_WriteConfigZone start\n");
+    uint8_t ucReturn, ucEncrypt;
+	
+    ucCM_InsBuff[0] = 0xb4;
+    if(ucAntiTearing) ucCM_InsBuff[1] = 0x08;
+    else              ucCM_InsBuff[1] = 0x00;
+    ucCM_InsBuff[2] = ucCryptoAddr;
+    ucCM_InsBuff[3] = ucCount;
+
+    // Three bytes of the command must be included in the polynominals
+    cm_GPAcmd2(ucCM_InsBuff);
+    
+    // Only password zone is ever encrypted
+    ucEncrypt = ((ucCryptoAddr>= CM_PSW) && ucCM_Encrypt);
+
+    // Include the data in the polynominals and encrypt if required
+    cm_GPAencrypt(ucEncrypt, pucBuffer, ucCount); 
+
+    // Do the write
+    ucReturn = cm_WriteCommand(ucCM_InsBuff, pucBuffer,ucCount);
+
+    // when anti-tearing, the host should send ACK should >= 20ms after write command
+    if (ucAntiTearing) CM_LOW_LEVEL.WaitClock(100);  //10
+//    printf("===> cm_WriteConfigZone over\n");
+    return ucReturn;
+}

+ 33 - 0
app/bmc/AuthChip/CM_WRCKSUM.c

@@ -0,0 +1,33 @@
+// Write Checksum
+//
+
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+uint8_t	ucCmdWrChk[4] = {0xb4, 0x02, 0x00, 0x02};
+
+// Send Checksum
+uint8_t cm_SendChecksum(uint8_t* pucChkSum)
+{
+	uint8_t ucReturn;
+	uint8_t ucChkSum[2];
+
+    // Get Checksum if required
+	if(pucChkSum == NULL) cm_CalChecksum(ucChkSum);
+	else {
+	   ucChkSum[0] = *pucChkSum++; 
+	   ucChkSum[1] = *pucChkSum; 
+    } 
+	
+	// Send the command
+	ucReturn = cm_WriteCommand(ucCmdWrChk, ucChkSum, 2);
+
+    // Give the CyrptoMemory some processing time
+    CM_LOW_LEVEL.WaitClock(50);	//5
+	
+	// Done
+    return ucReturn;
+}

+ 33 - 0
app/bmc/AuthChip/CM_WRITE.c

@@ -0,0 +1,33 @@
+// Mid Level Utility Function: cm_WriteCommand()
+//
+// Note: this module must be after all low level functions in the library and
+//       before all high level user function to assure that any reference to
+//       this function in this library are satistified.
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include <unistd.h>
+#include <stdio.h>
+#include "linux/fcntl.h"
+#include "driver.h"
+#include <string.h>
+
+uint8_t cm_WriteCommand(uint8_t* pucInsBuff, uint8_t* pucSendVal, uint8_t ucLen)
+{ 
+    // int i;
+    // printf("---> cm_WriteCommand: %#02x %#02x %#02x %#02x - ", pucInsBuff[0], pucInsBuff[1], pucInsBuff[2], pucInsBuff[3]);
+    // for(i=0;i<ucLen;i++)
+    // 	printf("%#02x ", pucSendVal[i]);
+    // printf("\n");
+
+    uint8_t ucReturn;
+    if ((ucReturn = CM_LOW_LEVEL.SendCommand(pucInsBuff)) != SUCCESS) 
+	{
+		printf("---> cm_WriteCommand ucReturn %d\n", ucReturn);
+		return ucReturn;
+	}
+    ucReturn = CM_LOW_LEVEL.SendData(pucSendVal, ucLen);
+    //printf("---> cm_WriteCommand over!\n");
+    return ucReturn;
+}
+

+ 35 - 0
app/bmc/AuthChip/CM_WRUSER.c

@@ -0,0 +1,35 @@
+// Write User Zone
+//
+// The Write Large User Zone function is used to write data to CryptoMemory devices that have
+// greater than 256 bytes in each user zone (AT88SC6416C, and larger).
+ 
+// CryptoMemory Library Include Files
+#include "CM_LIB.h"
+#include "CM_I2C.h"
+#include "CM_I2C_L.h"
+#include "CM_GPA.h"
+
+// Write User Zone
+char cm_WriteLargeZone(uint32_t uiCryptoAddr, uint8_t* pucBuffer, uint8_t ucCount)
+{
+    uint8_t ucReturn;
+	
+    ucCM_InsBuff[0] = 0xb0;
+    ucCM_InsBuff[1] = (uint8_t)(uiCryptoAddr>>8);
+    ucCM_InsBuff[2] = (uint8_t)uiCryptoAddr;
+    ucCM_InsBuff[3] = ucCount;
+
+    // Three bytes of the command must be included in the polynominals
+    cm_GPAcmd3(ucCM_InsBuff);
+    
+    // Include the data in the polynominals and encrypt it required
+    cm_GPAencrypt(ucCM_Encrypt, pucBuffer, ucCount); 
+
+    ucReturn = cm_WriteCommand(ucCM_InsBuff, pucBuffer, ucCount);
+
+	// when anti-tearing, the host should send ACK should >= 20ms after write command
+	if (ucCM_AntiTearing) CM_LOW_LEVEL.WaitClock(100);  //10
+
+	// Done
+	return ucReturn;
+}

+ 154 - 0
app/bmc/BmcType.h

@@ -0,0 +1,154 @@
+#ifndef __BMC_TYPE_H__
+#define __BMC_TYPE_H__
+
+#include <stdint.h>
+#include <unistd.h>
+#include <pthread.h>
+#include "Session.h"
+#include "com_IPMI_ChassisDevice.h"
+#include "PMConfig.h"
+#include "SensorMonitor.h"
+#include "com_BmcType.h"
+#include "MsgHndlr.h"
+
+#pragma pack(1)
+
+/***************************************** IPMI ******************************************************/
+typedef struct
+{
+    pthread_key_t CurSessionID;
+    pthread_key_t CurPrivLevel;
+    pthread_key_t CurChannel;
+    pthread_key_t CurKCSIfcNum;
+    pthread_key_t CurSessionType;
+    pthread_key_t OwnerLUN;
+}TLS_T;
+
+typedef enum
+{
+  ORIGIN_UNSPECIFIED = 0,
+  ORIGIN_SENDMSG,
+  ORIGIN_CMDFWD,
+  ORIGIN_INT_REQ,
+  ORIGIN_NM,
+}BridgeOrigin;
+
+
+typedef struct
+{
+	char	FirstPowerOnStr[32];	//first power on the bmc 
+    uint8_t SendMsgTimeout;
+    uint8_t SessionTimeOut;
+    uint32_t ChassisTimerInterval;
+    	
+    uint8_t SerialIfcSupport ;
+    uint8_t SerialTerminalSupport;
+    uint8_t LANIfcSupport ;
+    uint8_t SYSIfcSupport;
+    uint8_t GrpExtnSupport ;
+    uint8_t UDSIfcSupport;
+
+	uint32_t FanControlInterval;
+
+ 	//IPMB
+ 	uint8_t 		PrimaryIPMBSupport ;
+    uint8_t 		SecondaryIPMBSupport ;
+	uint32_t 			PrimaryIPMBBus;
+    uint32_t 			SecondaryIPMBBus;
+    
+
+	//chassis config
+	uint8_t                        SysRestartCause;
+	uint8_t                        PowerRestorePolicy;
+	ChassisPowerState_T          ChassisPowerState;
+	ChassisCapabilities_T        ChassisCapabilities;
+	uint8_t						PowerCycleInterval;
+	uint8_t                        SysPartitionScan;
+	
+	uint8_t				RearmSetSensorThreshold;
+	int16_t				SELTimeUTCOffset;
+	
+	uint8_t		MaxSession;
+	uint32_t	LogOutTimeout;
+
+	SDR_T				SDRConfig;
+	SEL_T				SELConfig;
+
+	
+} IPMIConfig_T;
+
+
+typedef struct
+{
+    IPMIConfig_T 		IpmiConfig;
+	OemFRUData_T		FRU;
+	uint8_t*			pSDR;
+	uint8_t*			pSEL;		
+
+	//time
+    uint32_t 			CurTimerTick;							//uint: 1ms
+	uint32_t			CurTimerSecond;
+	uint32_t			BootValidMinutes;						//This work time
+	uint32_t			TotalBootValidMinutes;					//Total work time
+//	uint32_t			SELTimeSecond;							//seconds from 1970-1-1 00:00:00, UTC
+	
+	//chassis
+    uint8_t             SlotID;
+	uint8_t				ChassisID;
+	uint8_t             PrimaryIPMBAddr;	//8bit
+	uint8_t				SecondaryIPMBAddr;	//8bit
+	//lan configuration
+	LanInfo_T 	LanInfo[1];	//方便扩展多个网卡。
+
+	uint8_t				PowerGoodFlag;
+	uint8_t				FirstPowerOn;
+	uint8_t				SelfTestByte;
+	uint8_t				ChassisIdentifyForce;
+	uint8_t				ChassisIdentifyTimeout;
+	uint8_t				ChassisIdentify;
+	uint8_t				HealthLevel;
+	
+	SensorSharedMem_T	SensorSharedMem;
+	SENSOR_T 			SenConfig;
+	
+	//message handler
+	uint8_t    			SendMsgSeqNum;
+	
+	
+	
+	uint8_t				DeviceGUID[16];
+//	OEM_FLAGS_T			OemFlags;
+	
+//	SessionInfo_T		LanSession;
+	uint8_t 			SessionHandle;
+	SessionTblInfo_T 	SessionTblInfo;
+	uint8_t 			UDSSessionHandle;
+	UDSSessionTblInfo_T UDSSessionTblInfo;
+	uint8_t			 	TimerTaskTblSize;
+	TimerTaskTbl_T    	TimerTaskTbl[20];
+
+	//bool				loginOk;
+	//uint32_t			logOutCnt;
+	UserInfo_T			UserInfoTbl[MAX_USER_NUM];
+	UserInfo_T			*pUserInfo;
+	uint8_t				CurrentNoUser;
+	
+	uint8_t 			m_Lan_SetInProgress;
+
+	uint8_t 			FlashStatus;	//0: idle, 1: busy
+	
+	uint8_t				FwMajorVer;
+	uint8_t				FwMinorVer;
+
+	//global_flags
+	uint8_t 			BladeManageEn;
+	uint8_t 			isChMC;
+	uint8_t 			IndexInChassis;	//刀片插在机箱里的第几个槽,index从0开始。
+
+} BMCInfo_t;
+
+
+
+
+#pragma pack()
+#endif /* __BMC_TYPE_H__ */

+ 156 - 0
app/bmc/ChassisTimer/ChassisTimerTask.c

@@ -0,0 +1,156 @@
+/*
+* Brief:	Handle all chassis function in this file. 
+			Such as: Fan control, update power_good status, update chassis health status.
+* Author:	Jimbo_Zhang@outlook.com
+* Date:		2019-9-18
+*/
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/prctl.h>
+#include <semaphore.h>
+#include <pthread.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "main.h"
+#include "ChassisTimerTask.h"
+#include "ChassisDevice.h"
+#include "com_IPMI_Chassis.h"
+#include "com_IPMI_LANConfig.h"
+#include "com_IPMI_DeviceConfig.h"
+#include "SensorMonitor.h"
+#include "time.h"
+
+#include "com_IPMI_App.h"
+#include "hal_interface_api.h"
+
+void *IdentifyTask(void *param);
+//int gFd_ChassisPwrHndlrQue;
+
+void *ChassisTimerTask(void* pArg)
+{
+	MsgPkt_T	ReqPkt;
+	MsgPkt_T	ResPkt;
+	uint32_t	preChassisSeconds;
+	uint32_t	preFanSeconds;
+	uint32_t	preIdentifySeconds = 0;
+	
+	char  		cmdStr[100] = {0};
+	SetLanConfigReq_T  *pSetLanCfg;
+	int i;
+	prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
+
+	printf("ChassisTimerTask Started... \n");
+
+	// //create 
+ //    if(-1 != access(CHASSIS_PWR_HNDLR_Q, F_OK))
+ //    {
+ //        remove(CHASSIS_PWR_HNDLR_Q);
+ //    }
+ //    if(0 != mkfifo (CHASSIS_PWR_HNDLR_Q, 0777))
+ //    {
+ //        printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, CHASSIS_PWR_HNDLR_Q, strerror(errno));
+ //        return (void*)-1;
+ //    }
+ //    gFd_ChassisPwrHndlrQue = open (CHASSIS_PWR_HNDLR_Q, O_RDWR);
+ //    if(-1 == gFd_ChassisPwrHndlrQue)
+ //    {
+ //        printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, CHASSIS_PWR_HNDLR_Q, strerror(errno));
+ //        return (void*)-1;
+ //    }
+
+	preChassisSeconds	=	g_BMCInfo.CurTimerSecond;
+	preFanSeconds	=	g_BMCInfo.CurTimerSecond;
+
+	//sleep(5);
+	while(1)
+	{
+		//Chassis timer interval
+		if((g_BMCInfo.CurTimerSecond != preChassisSeconds) 
+			&&((g_BMCInfo.CurTimerSecond - preChassisSeconds) >= g_BMCInfo.IpmiConfig.ChassisTimerInterval))
+		{
+			//log("Chassis interval\r\n");
+			preChassisSeconds	=	g_BMCInfo.CurTimerSecond;
+			//TODO:
+			//g_BMCInfo.PowerGoodFlag = 1;
+			g_BMCInfo.IpmiConfig.ChassisPowerState.PowerState	=	g_BMCInfo.PowerGoodFlag;
+
+			// ReqPkt.NetFnLUN 	= 0x2e<<2;
+			// ReqPkt.Cmd 			= 0x01;
+			// ReqPkt.Size 		= 0;
+			// if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, 0x40, 6))
+			// {
+			// 	printf("---> Access 0x40 successful: ");
+			// }
+			// else
+			// {
+			// 	printf("---> Access 0x40 failed: ");
+			// }
+			// for(i=0;i<ResPkt.Size;i++)
+			// 	printf("%x ", ResPkt.Data[i]);
+			// printf("\n");
+		}
+		
+		// //Fan control
+		// if((g_BMCInfo.CurTimerSecond != preFanSeconds)
+		// 	&& (g_BMCInfo.CurTimerSecond % g_BMCInfo.IpmiConfig.FanControlInterval) == 0)
+		// {
+		// 	preFanSeconds	=	g_BMCInfo.CurTimerSecond;
+		// 	PDK_FanControl();
+		// }
+		
+		//Chassis Identify
+		if(g_BMCInfo.ChassisIdentify == TRUE)		//新开个线程实现,默认灯闪烁10s,参考IPMI协议
+		{
+			if((g_BMCInfo.ChassisIdentifyTimeout != 0) || (g_BMCInfo.ChassisIdentifyForce != 0))
+			{
+				if(0 != pthread_create(NULL,NULL,IdentifyTask,NULL))
+			    {
+			        printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
+			    }
+			}
+			g_BMCInfo.ChassisIdentify = FALSE;
+		}
+		
+		
+		sleep(1);
+	}
+}
+
+
+
+void *IdentifyTask(void *param)
+{
+	uint8_t		IdentifyTickCnt = 0;
+	GPIO_PinState OldPinState;
+	printf("Start Chassis Identify, Time %d, force %d\n", g_BMCInfo.ChassisIdentifyTimeout, g_BMCInfo.ChassisIdentifyForce);
+			
+	OldPinState = stm32_gpio_read(IDENTIFY_PORT, IDENTIFY_PIN);
+
+	while(g_BMCInfo.ChassisIdentifyForce || g_BMCInfo.ChassisIdentifyTimeout)
+	{
+		stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_SET);
+		usleep(250000);
+		stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
+		usleep(250000);
+		stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_SET);
+		usleep(250000);
+		stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
+		usleep(250000);
+		if(g_BMCInfo.ChassisIdentifyTimeout>0)
+		{
+			g_BMCInfo.ChassisIdentifyTimeout--;
+		}
+	}
+
+	//恢复LED灯的状态
+	stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, OldPinState);
+
+	printf("Chassis Identify finish.\n");
+			
+	pthread_exit(0);
+}

+ 14 - 0
app/bmc/ChassisTimer/ChassisTimerTask.h

@@ -0,0 +1,14 @@
+/*
+* Brief:	The header file of ChassisTimerTask.c
+* Author:	Jimbo_Zhang@outlook.com
+* Date:		2019-9-18
+*/
+
+#ifndef __CHASSIS_TIMER_TASK_H__
+#define __CHASSIS_TIMER_TASK_H__
+
+void *ChassisTimerTask(void* pArg);
+
+#endif /* __CHASSIS_TIMER_TASK_H__ */
+
+

+ 176 - 0
app/bmc/Makefile

@@ -0,0 +1,176 @@
+EXEC		= bmc_app
+
+CFLAGS		:= -Os -mcpu=cortex-m3 -mthumb
+LDFLAGS		:= -mcpu=cortex-m3 -mthumb -L$(INSTALL_ROOT)/A2F/root/usr/lib
+
+
+
+CC	= $(CROSS_COMPILE_APPS)gcc
+
+#source
+
+SRC	= ./main.c
+SRC += ./message.c
+SRC	+= ./Session.c
+SRC	+= ./Api.c
+SRC	+= ./sensor_driver.c
+SRC	+= ./sensor_sdr.c
+SRC	+= ./OemFRU.c
+SRC	+= ./Util.c
+
+SRC	+= ./SysTimer/TimerTask.c
+
+SRC	+= ./uds/UDSIfc.c
+SRC += ./lan/LANIfc.c
+SRC += ./lan/RMCP.c
+SRC += ./lan/RMCP+.c
+
+SRC += ./ipmb/IPMBIfc.c
+
+SRC += ./PendActionTask/PendActionTask.c
+
+SRC += ./encryption/MD2.c
+SRC += ./encryption/md2_dgst.c
+SRC += ./encryption/MD5.c
+SRC += ./encryption/MD5_128.c
+SRC += ./encryption/md5c.c
+SRC += ./encryption/AuthCode.c
+
+SRC += ./ChassisTimer/ChassisTimerTask.c
+
+SRC += ./msghndlr/MsgHndlrTask.c
+SRC += ./msghndlr/cmdselect.c
+SRC += ./msghndlr/PDKCmds.c
+SRC += ./msghndlr/App/App.c
+SRC += ./msghndlr/App/AppDevice/AppDevice.c
+SRC += ./msghndlr/App/AppDevice/WDT.c
+#SRC += ./msghndlr/App/IPMDevice/Firewall.c
+SRC += ./msghndlr/App/IPMDevice/IPMDevice.c
+
+SRC += ./msghndlr/Bridge/Bridge.c
+SRC += ./msghndlr/Chassis/Chassis.c
+SRC += ./msghndlr/Chassis/ChassisDevice.c
+SRC += ./msghndlr/OemSMMCmds/OemSMMCmds.c
+SRC += ./msghndlr/PICMG/PICMGDevice.c
+
+SRC += ./msghndlr/SensorEvent/SensorEvent.c
+SRC += ./msghndlr/SensorEvent/SensorDevice/Sensor.c
+SRC += ./msghndlr/SensorEvent/SensorDevice/SensorMonitor.c
+
+SRC += ./msghndlr/Storage/Storage.c
+SRC += ./msghndlr/Storage/FRUDevice/FRU.c
+SRC += ./msghndlr/Storage/SDRDevice/SDR.c
+SRC += ./msghndlr/Storage/SELDevice/SEL.c
+
+SRC += ./msghndlr/Transport/LANConfig.c
+SRC += ./msghndlr/Transport/DeviceConfig.c
+
+SRC += ./msghndlr/Storlead/Storlead.c
+
+SRC += ./AuthChip/CM_BURNFUZE.c
+SRC += ./AuthChip/CM_DATA.c
+SRC += ./AuthChip/CM_GPA.c
+SRC += ./AuthChip/CM_I2C.c
+SRC += ./AuthChip/CM_NOPOWER.c
+SRC += ./AuthChip/CM_PASSWORD.c
+SRC += ./AuthChip/CM_RDCFG.c
+SRC += ./AuthChip/CM_RDCKSUM.c
+SRC += ./AuthChip/CM_RDFUZE.c
+SRC += ./AuthChip/CM_RDUSER.c
+SRC += ./AuthChip/CM_READ.c
+SRC += ./AuthChip/CM_RESETPSW.c
+SRC += ./AuthChip/CM_RESETSEC.c
+SRC += ./AuthChip/CM_RND.c
+SRC += ./AuthChip/CM_SECURE.c
+SRC += ./AuthChip/CM_SELECT.c
+SRC += ./AuthChip/CM_SETUSER.c
+SRC += ./AuthChip/CM_SRDUSER.c
+SRC += ./AuthChip/CM_SWRUSER.c
+SRC += ./AuthChip/CM_TEST.c
+SRC += ./AuthChip/CM_TRUE.c
+SRC += ./AuthChip/CM_WRCFG.c
+SRC += ./AuthChip/CM_WRCKSUM.c
+SRC += ./AuthChip/CM_WRITE.c
+SRC += ./AuthChip/CM_WRUSER.c
+
+# SRC += ../driver/STM32F4xx_HAL_Driver/system_stm32f4xx.c
+# SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c
+# SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c
+# SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c
+# SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c
+# SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c
+# SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c
+
+# hal_api
+SRC += $(wildcard ../hal_api/*.c) 
+
+#incldue
+CFLAGS	+= -I$(INSTALL_ROOT)/A2F/root/usr/include
+CFLAGS	+= -I ../common_include
+CFLAGS	+= -I ../hal_api
+CFLAGS	+= -I ../driver
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc/Legacy
+
+CFLAGS	+= -I ./
+CFLAGS	+= -I ./uds
+CFLAGS	+= -I ./lan
+CFLAGS	+= -I ./fru
+CFLAGS	+= -I ./sdr
+CFLAGS	+= -I ./sel
+CFLAGS	+= -I ./ipmb
+
+CFLAGS	+= -I ./SysTimer
+
+CFLAGS	+= -I ./ChassisTimer
+CFLAGS	+= -I ./encryption
+CFLAGS	+= -I ./ipmb
+CFLAGS	+= -I ./lan
+CFLAGS	+= -I ./PendActionTask
+
+CFLAGS	+= -I ./msghndlr
+CFLAGS	+= -I ./msghndlr/App
+CFLAGS	+= -I ./msghndlr/App/AppDevice
+CFLAGS	+= -I ./msghndlr/App/IPMDevice
+CFLAGS	+= -I ./msghndlr/Bridge
+CFLAGS	+= -I ./msghndlr/Chassis
+CFLAGS	+= -I ./msghndlr/OemSMMCmds
+CFLAGS	+= -I ./msghndlr/PICMG
+CFLAGS	+= -I ./msghndlr/SensorEvent
+CFLAGS	+= -I ./msghndlr/SensorEvent/SensorDevice
+CFLAGS	+= -I ./msghndlr/Storage
+CFLAGS	+= -I ./msghndlr/Storage/FRUDevice
+CFLAGS	+= -I ./msghndlr/Storage/SDRDevice
+CFLAGS	+= -I ./msghndlr/Storage/SELDevice
+CFLAGS	+= -I ./msghndlr/Transport
+CFLAGS	+= -I ./msghndlr/Storlead
+
+CFLAGS 	+= -I ./AuthChip
+
+
+CFLAGS	+= -I ./encryption
+
+#CFLAGS	+= -I$(INSTALL_ROOT)/A2F/uclibc/include
+#library
+
+#sub-directory
+#SUBDIR 	= ./sensor
+
+
+
+
+
+$(EXEC): $(SRC)
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS) -lpthread -lm -lc
+
+
+
+#object
+OBJS	:= $(SRC:%.c=%.o)
+
+clean:
+	rm -f $(EXEC) $(OBJS)
+	rm -f *.gdb
+
+

+ 112 - 0
app/bmc/OemFRU.c

@@ -0,0 +1,112 @@
+/*
+* Brief:	Define default FRU data in here.
+*/
+
+#include "BmcType.h"
+#include "com_BmcType.h"
+#include "com_IPMI_FRU.h"
+
+
+/********************************** Flash *************************************/
+/*
+ * Common Header: 		offset = 0,		len = 8
+ * chassis info area	offset = 1,		len = 64
+ * Board info area:		offset = 9,		len = 96
+ * product info area:	offset = 21, 	len = 88
+ * ------------------------------------------------------------------
+ * 										total = 256 		
+ */
+const OemFRUData_T Default_FRUData = {
+		//common header
+		{
+			1,			//Format version
+			0,			//no internal use area 
+			1,			//chassis info area offset / 8 
+			9,			//board info area offset / 8
+			21,		//product info area offset / 8
+			0,			//MultiRecord area offset / 8
+			0x0,		//PAD
+			0xe0,		//checksum
+		},
+		
+		//chassis info area
+		{
+			1,			//version
+			FRU_CHASSIS_SIZE/8,		//length = 64/8
+			MainServerChassis,
+			//Data[58]
+			{
+					(0xc0 | 0x0a),	
+					'0', '0', '0', '0', '-', '0', '0', '0', '1', ' ',   		//Chassis Part Number
+					(0xc0 | 0x0a),	
+					'0', '0', '0', '0', '-', '0', '0', '0', '1', ' ',    		//Chassis Serial Number
+					(0xc0 | 0x0a),	
+					' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',    			//Extra info
+										
+			},
+			0xc1,	
+			0x0,		//Y
+			0x0,		//checksum
+		},
+		
+		//board info area
+		{
+			1,			//version
+			FRU_BOARD_SIZE/8,		//length = 96/8
+			English,
+			{34, 56, 78},			//Number of minutes from 0:00 hrs 1/1/96.	LSbyte first (little endian)
+			//Data[75]
+			{
+				(0xc0 | 0x0a),	
+				'S', 't', 'o', 'r', 'l', 'e', 'a', 'd', ' ', ' ',  		//board manufacturer
+				(0xc0 | 0x0d), 
+				'O', 'p', 't', 'i', 'c', 'a', 'l', ' ', 'F', 'i', 'b', 'e', 'r',   		//board product name
+				(0xc0 | 0x08),
+				'0', '0', '0', '1', ' ', ' ', ' ', ' ',	//board product serNum
+				(0xc0 | 0x08),
+				'0', '0', '0', '1', ' ', ' ', ' ', ' ',	//board product partNum
+				(0xc0 | 0x08),
+				' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',	//board fru file id
+				(0xc0 | 0x08),
+				' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',	//Extra info
+
+			},
+			{0,0,0,0},	//power on count
+			{0,0,0,0},	//Total work time
+			{0,0,0,0},	//This work time
+			0xc1,	
+			0x0,		//Y
+			0x0,		//checksum
+		},
+		
+		//product info area
+		{
+			1,			//version
+			FRU_PRODUCT_SIZE/8,		//length	=	88/8
+			English,	
+			//Data[82]
+			{
+				(0xc0 | 0x0a),
+				'S', 't', 'o', 'r',	'l', 'e', 'a', 'd', ' ', ' ', 	//manufacturer name
+				(0xc0 | 0x0e),
+				'S', 't', 'o', 'r', 'a', 'g', 'e', ' ', 'S', 'e', 'r', 'v', 'e', 'r',	//product name
+				(0xc0 | 0x08),
+				'0', '0', '0', '0', '0', '0', '0', '1',	//part number
+				(0xc0 | 0x08),
+				'1', '.', '0', '0', ' ', ' ', ' ', ' ',	//product version
+				(0xc0 | 0x08),
+				'0','0','0','0','0','0', '0', '1',	//product serNum
+				(0xc0 | 0x08), 	
+				' ',' ',' ',' ',' ',' ', ' ', ' ',	//Assert Tag
+				(0xc0 | 0x08), 		
+				' ',' ',' ',' ',' ',' ',' ',' ',	//FRU File ID
+				(0xc0 | 0x08), 		
+				' ',' ',' ',' ',' ',' ',' ',' ',	//Extra info
+			},
+			0xc1,	
+			0x0,		//Y
+			0x0,		//checksum
+		}
+};
+
+

+ 195 - 0
app/bmc/PendActionTask/PendActionTask.c

@@ -0,0 +1,195 @@
+#include "main.h"
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/prctl.h>
+#include <semaphore.h>
+#include <pthread.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "main.h"
+#include "ChassisTimerTask.h"
+#include "ChassisDevice.h"
+#include "com_IPMI_Chassis.h"
+#include "com_IPMI_LANConfig.h"
+#include "com_IPMI_DeviceConfig.h"
+#include "SensorMonitor.h"
+#include "time.h"
+#include "com_IPMI_Storlead.h"
+
+#include "com_IPMI_App.h"
+#include "hal_interface_api.h"
+#include "Api.h"
+
+int 		gPendActionIfc;
+
+void *PendActionTask(void *Param)
+{
+	MsgPkt_T	MsgPkt;
+	char  		cmdStr[100] = {0};
+	SetLanConfigReq_T  *pSetLanCfg;
+	prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
+
+	printf("PendActionTask Started... \n");
+
+	//create 
+    if(-1 != access(PEND_ACTION_HNDLR_Q, F_OK))
+    {
+        remove(PEND_ACTION_HNDLR_Q);
+    }
+    if(0 != mkfifo (PEND_ACTION_HNDLR_Q, 0777))
+    {
+        printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, PEND_ACTION_HNDLR_Q, strerror(errno));
+        return (void*)-1;
+    }
+    gPendActionIfc = open (PEND_ACTION_HNDLR_Q, O_RDWR);
+    if(-1 == gPendActionIfc)
+    {
+        printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, PEND_ACTION_HNDLR_Q, strerror(errno));
+        return (void*)-1;
+    }
+
+    while(1)
+    {
+		if(GetMsg(gPendActionIfc, &MsgPkt,  WAIT_INFINITE) == 0)
+		{
+			if(MsgPkt.Param == PARAM_CHASSIS)
+			{
+				//Chassis power control
+				if((NET_FN(MsgPkt.NetFnLUN) == NETFN_CHASSIS) && (MsgPkt.Cmd == CMD_CHASSIS_CONTROL))
+				{
+					switch(MsgPkt.Data[0])
+					{
+						case CHASSIS_POWER_DOWN:
+							PDK_PowerOffChassis();
+							break;
+						case CHASSIS_POWER_UP:
+							PDK_PowerOnChassis();
+							break;
+						case CHASSIS_POWER_CYCLE:
+							PDK_PowerCycleChassis();
+							break;
+						case CHASSIS_HARD_RESET:
+							PDK_ResetChassis();
+							break;
+						case CHASSIS_PULSE_DIAGNOSTIC_INTERRUPT:
+							PDK_DiagInterruptChassis();
+							break;
+						case CHASSIS_SOFT_SHUTDOWN:
+							PDK_SoftOffChassis();
+							break;
+						default:
+							printf("Invalid power control cmd\r\n");
+							break;
+					}
+				}
+			}
+			else if(MsgPkt.Param == PARAM_MC)
+			{
+				if(((MsgPkt.NetFnLUN>>2) == NETFN_APP) && (MsgPkt.Cmd == CMD_COLD_RESET)) 
+				{
+					sleep(1);	//wait ipmi request response finish.
+					pthread_mutex_lock(&Flash_Mutex);
+					stm32_reset_mcu();
+					pthread_mutex_unlock(&Flash_Mutex);
+				}
+				else if(((MsgPkt.NetFnLUN>>2) == NETFN_APP) && (MsgPkt.Cmd == CMD_WARM_RESET))
+				{
+					sleep(1);	//wait ipmi request response finish.
+					pthread_mutex_lock(&Flash_Mutex);
+					sprintf(cmdStr, "reboot");
+					system(cmdStr);
+					pthread_mutex_unlock(&Flash_Mutex);
+				} 
+			}
+			else if(MsgPkt.Param == PARAM_LAN)
+			{
+				pSetLanCfg = (SetLanConfigReq_T*)MsgPkt.Data;
+				printf("---> PARAM_LAN, NetFnLUN: %#x, cmd: %#x\n", MsgPkt.NetFnLUN, MsgPkt.Cmd);
+				printf("---> Data: %#x %#x %#x %#x %#x\n", MsgPkt.Data[0], MsgPkt.Data[1], MsgPkt.Data[2], MsgPkt.Data[3], MsgPkt.Data[4]);
+				if(((MsgPkt.NetFnLUN>>2) == NETFN_TRANSPORT) 
+					&& (MsgPkt.Cmd == CMD_SET_LAN_CONFIGURATION_PARAMETERS)
+					&& (pSetLanCfg->ChannelNum == LAN_RMCP_CHANNEL)) 
+				{
+					//Modify IP
+					if(pSetLanCfg->ParameterSelect == LAN_PARAM_IP_ADDRESS)
+					{
+						
+						sprintf(cmdStr, "ifconfig eth0 %d.%d.%d.%d up", 
+							pSetLanCfg->ConfigData.IPAddr[0], pSetLanCfg->ConfigData.IPAddr[1],
+							pSetLanCfg->ConfigData.IPAddr[2], pSetLanCfg->ConfigData.IPAddr[3]);
+						printf("Execute cmd: %s\n", cmdStr);
+						sleep(1);
+						system(cmdStr);
+					}
+					else if(pSetLanCfg->ParameterSelect == LAN_PARAM_MAC_ADDRESS)
+					{
+						sprintf(cmdStr, "ifconfig eth0 hw ether %02x:%02x:%02x:%02x:%02x:%02x", 
+							pSetLanCfg->ConfigData.MACAddr[0], pSetLanCfg->ConfigData.MACAddr[1],
+							pSetLanCfg->ConfigData.MACAddr[2], pSetLanCfg->ConfigData.MACAddr[3],
+							pSetLanCfg->ConfigData.MACAddr[4], pSetLanCfg->ConfigData.MACAddr[5]);
+						printf("Execute cmd: %s\n", cmdStr);
+						sleep(1);
+						system("ifconfig eth0 down");						
+						system(cmdStr);
+						system("ifconfig eth0 up");
+					}
+					else if(pSetLanCfg->ParameterSelect == LAN_PARAM_SUBNET_MASK)
+					{
+						sprintf(cmdStr, "ifconfig eth0 netmask %d.%d.%d.%d", 
+							pSetLanCfg->ConfigData.SubNetMask[0], pSetLanCfg->ConfigData.SubNetMask[1],
+							pSetLanCfg->ConfigData.SubNetMask[2], pSetLanCfg->ConfigData.SubNetMask[3]);
+						printf("Execute cmd: %s\n", cmdStr);
+						sleep(1);
+						system(cmdStr);
+					}
+					else if(pSetLanCfg->ParameterSelect == LAN_PARAM_DEFAULT_GATEWAY_IP)
+					{
+						sprintf(cmdStr, "route add default gw %d.%d.%d.%d", 
+							pSetLanCfg->ConfigData.DefaultGatewayIPAddr[0], pSetLanCfg->ConfigData.DefaultGatewayIPAddr[1],
+							pSetLanCfg->ConfigData.DefaultGatewayIPAddr[2], pSetLanCfg->ConfigData.DefaultGatewayIPAddr[3]);
+						printf("Execute cmd: %s\n", cmdStr);
+						sleep(1);
+						system(cmdStr);
+					}
+
+				}
+				else if(((MsgPkt.NetFnLUN>>2) == NETFN_STORLEAD) 
+					&& (MsgPkt.Cmd == CMD_SET_LAN_INFO))
+				{
+					LanInfo_T *pSetLanInfo = (LanInfo_T*)MsgPkt.Data;
+					sleep(1);
+					//down
+					sprintf(cmdStr, "ifconfig %s down", pSetLanInfo->EthName);
+					printf("%s\n", cmdStr);
+					system(cmdStr);
+					//set mac
+					sprintf(cmdStr, "ifconfig %s hw ether %02x:%02x:%02x:%02x:%02x:%02x", 
+						pSetLanInfo->EthName, pSetLanInfo->MACAddr[0], pSetLanInfo->MACAddr[1],
+						pSetLanInfo->MACAddr[2], pSetLanInfo->MACAddr[3], 
+						pSetLanInfo->MACAddr[4], pSetLanInfo->MACAddr[5]);
+					printf("%s\n", cmdStr);
+					system(cmdStr);
+					//ip, broadcast, netmask
+					sprintf(cmdStr, "ifconfig %s %d.%d.%d.%d broadcast %d.%d.%d.%d netmask %d.%d.%d.%d up",
+						pSetLanInfo->EthName, pSetLanInfo->IPAddr[0], pSetLanInfo->IPAddr[1],
+						pSetLanInfo->IPAddr[2], pSetLanInfo->IPAddr[3], pSetLanInfo->BroadCast[0],
+						pSetLanInfo->BroadCast[1], pSetLanInfo->BroadCast[2], pSetLanInfo->BroadCast[3],
+						pSetLanInfo->NetMask[0], pSetLanInfo->NetMask[1], pSetLanInfo->NetMask[2],
+						pSetLanInfo->NetMask[3]);
+					printf("%s\n", cmdStr);
+					system(cmdStr);
+					//default gw
+					sprintf(cmdStr, "route add default gw %d.%d.%d.%d", pSetLanInfo->DefaultGW[0],
+						pSetLanInfo->DefaultGW[1],pSetLanInfo->DefaultGW[2],pSetLanInfo->DefaultGW[3]);
+					printf("%s\n", cmdStr);
+					system(cmdStr);
+				} 
+			}
+		}
+	}
+}

+ 14 - 0
app/bmc/PendActionTask/PendActionTask.h

@@ -0,0 +1,14 @@
+#ifndef __PEND_ACTION_TASK_H__
+#define __PEND_ACTION_TASK_H__
+
+
+void *PendActionTask(void *Param);
+
+
+
+
+
+
+
+
+#endif /* __PEND_ACTION_TASK_H__ */

+ 1262 - 0
app/bmc/Session.c

@@ -0,0 +1,1262 @@
+///****************************************************************
+// ****************************************************************
+// **                                                            **
+// **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+// **                                                            **
+// **            All Rights Reserved.                            **
+// **                                                            **
+// **        6145-F, Northbelt Parkway, Norcross,                **
+// **                                                            **
+// **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+// **                                                            **
+// ****************************************************************
+// ****************************************************************/
+///*****************************************************************
+// *
+// * Session.c
+// * Session related functions
+// *
+// * Author: Govind Kothandapani <govindk@ami.com>
+// * 		 : Rama Bisa <ramab@ami.com>
+// *       : Basavaraj Astekar <basavaraja@ami.com>
+// *       : Bakka Ravinder Reddy <bakkar@ami.com>
+// *
+// *****************************************************************/
+//#define ENABLE_DEBUG_MACROS    0
+#include "com_IPMIDefs.h"
+//#include "MsgHndlr.h"
+#include "PMConfig.h"
+//#include "SharedMem.h"
+//#include "NVRAccess.h"
+#include "Session.h"
+//#include "Debug.h"
+////#include "SerialRegs.h"
+//#include "SensorEvent.h"
+#include "com_IPMI_Sensor.h"
+#include "Support.h"
+//#include "Ethaddr.h"
+#include "AppDevice.h"
+#include "MsgHndlr.h"
+#include <stdio.h>
+#include "main.h"
+#include <string.h>
+#include <time.h>
+#include "com_IPMI_SensorEvent.h"
+
+//#define TOTAL_INFINITE_CMDS  sizeof(m_InfiniteCmdsTbl)/sizeof(IPMICmdsFilterTbl_T)
+
+//static IPMICmdsFilterTbl_T m_InfiniteCmdsTbl [] =
+//{     /* NetFn */       /*  Command#   */
+//	{   NETFN_AMI,  CMD_AMI_YAFU_COMMON_NAK             },
+//	{   NETFN_AMI,  CMD_AMI_YAFU_GET_FLASH_INFO         },	
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_FIRMWARE_INFO	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_FMH_INFO	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_STATUS,	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_ACTIVATE_FLASH	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_ALLOCATE_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_FREE_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_READ_FLASH	            },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_WRITE_FLASH	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_ERASE_FLASH	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_PROTECT_FLASH	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_ERASE_COPY_FLASH	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_VERIFY_FLASH	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_READ_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_WRITE_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_COPY_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_COMPARE_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_CLEAR_MEMORY	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_BOOT_CONFIG	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_SET_BOOT_CONFIG	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_BOOT_VARS	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_DEACTIVATE_FLASH_MODE  },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_RESET_DEVICE	    },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_ECF_STATUS         },
+//	{   NETFN_AMI,	CMD_AMI_YAFU_GET_VERIFY_STATUS	    },
+//	{   NETFN_AMI,	CMD_AMI_GET_CHANNEL_NUM	            },
+//	{   NETFN_AMI,	CMD_AMI_GET_ETH_INDEX	            },
+//	{   NETFN_AMI,	CMD_AMI_START_TFTP_FW_UPDATE    },
+//	{   NETFN_AMI,	CMD_AMI_GET_TFTP_FW_PROGRESS_STATUS },
+//	{   NETFN_AMI,	CMD_AMI_SET_FW_CONFIGURATION    },
+//       {   NETFN_AMI,       CMD_AMI_GET_FW_CONFIGURATION    },
+//       {   NETFN_AMI,       CMD_AMI_SET_FW_PROTOCOL},
+//       {   NETFN_AMI,       CMD_AMI_GET_FW_PROTOCOL},
+//       {   NETFN_AMI,       CMD_AMI_YAFU_FIRMWARE_SELECT_FLASH},
+
+//};
+
+/*********************************************************************************************
+   Name	:	SessionTimeOutTask
+   Input	:	void
+   Output	:	void
+       This program  checks for session timeout
+*********************************************************************************************/
+void SessionTimerTask (void)
+{
+   	SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+   uint8_t				Index;
+//   char solsessionfile[MAXFILESIZE] = {0};
+   struct stat fp;
+
+//   printf("-> SessionTimerTask\n");
+   for (Index=0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+       {
+           continue;
+       }
+
+       // if(g_BMCInfo.IpmiConfig.SerialIfcSupport == 1)
+       // {
+       //     if (g_BMCInfo.SERIALch == pSessionTblInfo->SessionTbl[Index].Channel)
+       //     {
+       //         continue;
+       //         if (!(g_BMCInfo.SMConfig.SessionTermination & 0x02)) /* If Session Inactivity timeout disabled */
+       //         {
+       //             continue;
+       //         }
+       //         else if (0 == g_BMCInfo.SMConfig.SessionInactivity) /* Never Time Out */
+       //         {
+       //             continue;
+       //         }
+       //     }
+       // }
+
+      if (pSessionTblInfo->SessionTbl[Index].TimeOutValue > 0)
+      {
+         pSessionTblInfo->SessionTbl[Index].TimeOutValue--;
+         continue;
+      }
+       
+
+       printf ("\nSessionTimerTask: Session Time Out Occured\n");
+       printf ("SessionID = 0x%lX  Num of Sessions = %X\n", pSessionTblInfo->SessionTbl[Index].SessionID,
+                       pSessionTblInfo->Count);
+
+       // if(pBMCInfo->IpmiConfig.SerialIfcSupport == 1)
+       // {
+       //     if (pBMCInfo->SERIALch == pSessionTblInfo->SessionTbl[Index].Channel)
+       //     {
+       //         BMC_GET_SHARED_MEM (BMCInst)->SerialSessionActive = FALSE;
+       //     }
+       // }
+
+       /* Delete the Session from session table */
+       DeleteSession (&pSessionTblInfo->SessionTbl[Index]);
+   }
+}
+
+
+///*********************************************************************************************
+//    Name	:	getChannelInfo
+//    Input	:	ch	-	ChannelNumber
+//    Output	:	channelInformations
+//        This program  returns informations about the channel
+//*********************************************************************************************/
+// ChannelInfo_T* getChannelInfo (uint8_t ch )
+//{
+//    uint8_t Index;
+//    ChcfgInfo_T *pChannelInfo=NULL;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    if(IsLANChannel(ch, BMCInst))
+//    {
+//        if(pBMCInfo->IpmiConfig.LANIfcSupport != 1)
+//        {
+//            return NULL;
+//        }
+//    }else
+//    {
+//        if( PRIMARY_IPMB_CHANNEL == ch && pBMCInfo->IpmiConfig.PrimaryIPMBSupport != 1 )
+//        {
+//            return NULL;
+//        }
+//        else if (pBMCInfo->IpmiConfig.SecondaryIPMBSupport != 1 && (pBMCInfo->SecondaryIPMBCh != CH_NOT_USED && ch == pBMCInfo->SecondaryIPMBCh))
+//        {
+//            return NULL;
+//        }
+//        else if (pBMCInfo->IpmiConfig.SerialIfcSupport != 1 && (pBMCInfo->SERIALch != CH_NOT_USED && ch == pBMCInfo->SERIALch))
+//        {
+//            return NULL;
+//        }
+//        else if (pBMCInfo->IpmiConfig.ICMBIfcSupport != 1 && (pBMCInfo->ICMBCh != CH_NOT_USED && ch == pBMCInfo->ICMBCh))
+//        {
+//            return NULL;
+//        }
+//        else if (pBMCInfo->IpmiConfig.SMBUSIfcSupport !=1 && (pBMCInfo->SMBUSCh != CH_NOT_USED && ch == pBMCInfo->SMBUSCh))
+//        {
+//            return NULL;
+//        }
+//        else if (pBMCInfo->IpmiConfig.USBIfcSupport != 1 && (ch == USB_CHANNEL))
+//        {
+//            return NULL;
+//        }
+//        else if (pBMCInfo->IpmiConfig.SMMIfcSupport != 1 && (pBMCInfo->SMMCh != CH_NOT_USED && ch == pBMCInfo->SMMCh))
+//        {
+//            return NULL;
+//        }
+//        else if(pBMCInfo->IpmiConfig.SYSIfcSupport !=1 && ch == SYS_IFC_CHANNEL)
+//        {
+//            return NULL;
+//        }
+//    }
+
+//    for(Index=0;Index<MAX_NUM_CHANNELS;Index++)
+//    {
+//        if(pBMCInfo->ChConfig[Index].ChType != 0xff)
+//        {
+//            pChannelInfo = &pBMCInfo->ChConfig[Index];
+//            //printf("Channel numb is %x %x \n",pChannelInfo->ChannelInfo.ChannelNumber,ch);
+//            if(pChannelInfo->ChannelInfo.ChannelNumber == ch)
+//            {
+//                return (ChannelInfo_T *)&pBMCInfo->ChConfig[Index].ChannelInfo;
+//            }
+//        }
+//    }
+
+//    return NULL;
+//}
+
+// int UpdateUserInfoTable(void)
+// {
+//     uint8_t buf[1000];
+//     uint8_t UserNameLen = 0;
+//     uint8_t PassWordLen = 0;
+//     uint8_t *pUserName;
+//     uint8_t *pPassword;
+//     uint8_t *pStr;
+//     uint8_t usercnt = 0;
+//     uint32_t len = 0;
+//     uint8_t     namesize = 0;
+//     FILE *fp = NULL;
+
+
+//     printf("\n\nUpdateUserInfoTable\n");
+
+//     fp = fopen(AUTH_FILE_PATH, "r");
+//     if(fp == NULL)
+//     {
+//         printf("Open %s fail!\n", AUTH_FILE_PATH);
+//         return -1;
+//     }
+
+//     while(fgets(buf, 1000, fp) != NULL){
+//         pStr = buf;
+
+//         //remove blank
+//         while(*pStr == ' ')
+//         {
+//             pStr++;
+//         }
+
+//         if(strncmp(pStr, "user name=", 10) == 0)
+//         {
+//             pStr+=10;
+//             //get name
+//             pUserName = pStr;
+//             UserNameLen = 0;
+//             while(*pStr != ' ')
+//             {
+//                 UserNameLen++;
+//                 pStr++;
+//             }
+
+//             memset(g_BMCInfo.UserInfoTbl[usercnt].UserName, 0, MAX_USERNAME_LEN);
+//             memcpy(g_BMCInfo.UserInfoTbl[usercnt].UserName, pUserName, UserNameLen);
+            
+//             //remove blank
+//             while(*pStr == ' ')
+//             {
+//                 pStr++;
+//             }
+//             if(strncmp(pStr, "password=", 9) == 0)
+//             {
+//                 pStr += 9;
+//                 //get password
+//                 pPassword = pStr;
+//                 PassWordLen = 0;
+//                 while(*pStr != ' ')
+//                 {
+//                     PassWordLen++;
+//                     pStr++;
+//                 }
+
+//                 memset(g_BMCInfo.UserInfoTbl[usercnt].UserPassword, 0, MAX_PASSWORD_LEN);
+//                 memcpy(g_BMCInfo.UserInfoTbl[usercnt].UserPassword, pPassword, PassWordLen);
+            
+//                 g_BMCInfo.UserInfoTbl[usercnt].UserId = usercnt;
+
+//                 if(usercnt < 10)
+//                     usercnt++;
+//                 else
+//                     break;
+//             }
+//             else
+//                 continue;
+//         }
+//         else
+//             continue;
+//     }
+
+//     g_BMCInfo.CurrentNoUser = usercnt;
+//     fclose(fp);
+
+//     return 0;
+// }
+/*********************************************************************************************
+    Name	:	CheckForDuplicateUsers
+    Input	:	UserName - Name of the User
+    Output	:	returns 0 for success and -1 for failure
+        This program  returns Informations about the user
+*********************************************************************************************/
+uint8_t CheckForDuplicateUsers ( uint8_t* UserName)
+{
+	int i = 0;
+    
+    for(i=0; i<MAX_USER_NUM; i++)
+    {
+        if(g_BMCInfo.UserInfoTbl[i].UserId != 0)
+        {
+            if ((0 == strcmp(g_BMCInfo.UserInfoTbl[i].UserName, UserName)) \
+              && (TRUE == g_BMCInfo.UserInfoTbl[i].UserStatus))
+                return FALSE;
+        }
+    }	
+    return TRUE;    
+}
+
+/*********************************************************************************************
+    Name	:	getUserIdInfo
+    Input	:	UserID - User ID
+    Output	:	User information
+        This program  returns Informations about the user
+*********************************************************************************************/
+UserInfo_T*	getUserIdInfo (uint8_t UserId)
+{
+    if (UserId == 0) { return NULL; }
+
+    if (UserId <= MAX_USER_NUM)
+    {
+        return &g_BMCInfo.UserInfoTbl[UserId-1];
+    }
+    else
+    {
+        return NULL;
+    }
+}
+
+/*********************************************************************************************
+    Name	:	getUserNameInfo
+    Input	:	UserName - User name
+    Output	:	User information
+        This program  returns Informations about the user
+*********************************************************************************************/
+UserInfo_T*	getUserNameInfo (uint8_t *UserName)
+{
+   int i = 0;
+
+   if (UserName[0] == 0) { return NULL; }
+   if( (UserName[0] >= '0') && (UserName[0] <= '9') ) {return NULL;}
+
+	for (i = 0; i < MAX_USERNAME_LEN; i++)
+	{
+		if(UserName[i] > 127)
+		{
+			return NULL;
+		}
+	}    
+	
+    for(i=0; i < MAX_USER_NUM; i++)
+    {
+        //if(g_BMCInfo.UserInfoTbl[i].UserId != 0)
+        {
+            if (0 == strcmp(g_BMCInfo.UserInfoTbl[i].UserName, UserName))
+            {
+                return &g_BMCInfo.UserInfoTbl[i];
+            }
+        }
+    }	
+
+	return NULL;
+}
+
+///*********************************************************************************************
+//    Name	:	getChUserPrivInfo
+//    Input	:	userName - user name
+//    			Role - requested role
+//                chIndex - channel's user index
+//                pChUserInfo - channel's user information
+//    Output	:	channel's matching user Information
+
+//This program returns information about the user for the given channel,
+//        & Index of the user in Channel User Array.
+//*********************************************************************************************/
+// ChannelUserInfo_T* getChUserPrivInfo ( char *userName,  uint8_t Role,  uint8_t* chIndex,  ChannelUserInfo_T *pChUserInfo, int BMCInst)
+//{
+//     UserInfo_T* pUserTable = (UserInfo_T *) GetNVRUsrCfgAddr (NVRH_USERCONFIG, BMCInst);
+//    int userIndex;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    /* search the table */
+//    for(userIndex = 0; userIndex < pBMCInfo->IpmiConfig.MaxUsers; userIndex++)
+//    {
+//        for(*chIndex = 0; *chIndex < pBMCInfo->IpmiConfig.MaxChUsers; (*chIndex)++)
+//        {
+//            if ((Role <= pChUserInfo[*chIndex].AccessLimit) &&
+//                (1 == pUserTable[userIndex].UserStatus) &&
+//                (pUserTable[userIndex].UserId == pChUserInfo[*chIndex].UserId))
+//                {
+//                    /* if userName is not NULL then it is username/privilege
+//                    lookup else it is name_only lookup */
+//                    if (0 != *userName)
+//                    {
+//                        if (0 != _fmemcmp(pUserTable[userIndex].UserName, userName, MAX_USERNAME_LEN))
+//                        {
+//                            continue;
+//                        }
+//                    }
+//                    return (pChUserInfo + *chIndex);
+//                }
+//        }
+//    }
+//    return NULL;
+//}
+
+///*********************************************************************************************
+//    Name	:	getChUserInfo
+//    Input	:	userName - user name
+//                chIndex - to return Index of user in channelUser Array
+//                pChUserInfo - channel's user information
+//    Output	:	channel's matching user Information
+
+//This program returns information about the user for the given channel,
+//        & Index of the user in Channel User Array.
+//*********************************************************************************************/
+// ChannelUserInfo_T* getChUserInfo ( char *userName,   uint8_t* chIndex,  ChannelUserInfo_T *pChUserInfo )
+//{
+//     UserInfo_T* pUserTable = (UserInfo_T *) GetNVRUsrCfgAddr (NVRH_USERCONFIG, BMCInst);
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//    int userIndex;
+
+//    /* search the table */
+//    for(userIndex = 0; userIndex < pBMCInfo->IpmiConfig.MaxUsers; userIndex++)
+//    {
+//        for(*chIndex = 0; *chIndex < pBMCInfo->IpmiConfig.MaxChUsers; (*chIndex)++)
+//        {
+//            if ((0 == _fmemcmp(pUserTable[userIndex].UserName, userName, MAX_USERNAME_LEN)) &&
+//                /* Commented to return the pointer for disabled user */ 
+//                /* (1 == pUserTable[userIndex].UserStatus) && */
+//                (pUserTable[userIndex].UserId == pChUserInfo[*chIndex].UserId))
+//            return (pChUserInfo + *chIndex);
+//        }
+//    }
+//    return NULL;
+//}
+
+///*********************************************************************************************
+//    Name	:	getChUserIdInfo
+//    Input	:	userId - User ID
+//                Index - to return Index of user in channelUser Array.
+//                pChUserInfo - channel's user information
+//    Output	:	channel's matching user Information
+
+//This program returns information about the user for the given channel,
+//                & Index of the user inChannel User Array.
+
+//*********************************************************************************************/
+// ChannelUserInfo_T* getChUserIdInfo (uint8_t userId,  uint8_t *Index,  ChannelUserInfo_T*	pChUserInfo, int BMCInst)
+//{
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    if (userId == 0) { return NULL; }
+
+//    for(*Index=0; *Index < pBMCInfo->IpmiConfig.MaxChUsers; (*Index)++)
+//    {
+//        if ((pChUserInfo->UserId == userId) && ((pChUserInfo->ID == USER_ID )))
+//        {
+//            return pChUserInfo;
+//        }
+//        pChUserInfo++;
+//    }
+//    return NULL;
+//}
+
+///*********************************************************************************************
+//    Name	:	GetNVRChConfigs
+//    Input	:	pChannelInfo -Channel Information
+//                        Filename - Channel Name Information
+//    Output	:	Respective Channel's Information
+
+//This program returns information about the respective channel.
+
+//*********************************************************************************************/
+//ChannelInfo_T* GetNVRChConfigs(ChannelInfo_T *pChannelInfo, int BMCInst)
+//{
+//    int i=0;
+//    ChannelInfo_T *pNVRChInfo=NULL;
+
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//    for(i=0;i<MAX_NUM_CHANNELS;i++)
+//    {
+//        if( pBMCInfo->NVRChcfgInfo[i].ChType != 0xff)
+//        {
+//            pNVRChInfo = &pBMCInfo->NVRChcfgInfo[i].ChannelInfo;
+//            if(pChannelInfo->ChannelNumber == pNVRChInfo->ChannelNumber)
+//            {
+//                return (ChannelInfo_T *)&pBMCInfo->NVRChcfgInfo[i].ChannelInfo;
+//            }
+//        }
+//    }
+//    return NULL;
+//}
+
+///**
+//*@fn GetNVRChUserConfigs 
+//*@brief This function is invoked to get NVR User informations of the channel
+//*@param pChannelInfo - Channel Information
+//*@param Filename - Size of the SDR repository
+//*@return Returns Address of user information for the channel on success
+//*              Returns NULL on Failure
+//*/
+//ChannelUserInfo_T* GetNVRChUserConfigs(ChannelInfo_T *pChannelInfo, int BMCInst)
+//{
+//    int i=0;
+//    ChannelInfo_T *pNVRChInfo = NULL;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    for(i=0;i<MAX_NUM_CHANNELS;i++)
+//    {
+//        if(pBMCInfo->NVRChcfgInfo [i].ChType != 0xff)
+//        {
+//            pNVRChInfo = &pBMCInfo->NVRChcfgInfo[i].ChannelInfo;
+//            if(pChannelInfo->ChannelNumber == pNVRChInfo->ChannelNumber)
+//            {
+//                return (ChannelUserInfo_T *)&pBMCInfo->NVRChcfgInfo[i].ChannelInfo.ChannelUserInfo[0];
+//            }
+//        }
+//    }
+//    return NULL;
+//}
+
+
+
+/*********************************************************************************************
+    Name	:	getSessionInfo
+    Input	:	Arg - Tells the type of data passed in Session
+                Session - Either one of these: session ID, session handle, session index or
+                channel number
+    Output	:	Session Information
+
+This program  returns the session information.
+*********************************************************************************************/
+SessionInfo_T* getSessionInfo (uint8_t Arg,  void *Session)
+{
+   uint8_t				Index;
+   uint8_t				ActiveSesIndex = 0;
+   SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+       {
+           continue;
+       }
+       if (TRUE == pSessionTblInfo->SessionTbl[Index].Activated)
+       {
+           ActiveSesIndex++;
+       }
+
+       switch (Arg)
+       {
+       case SESSION_ID_INFO:
+           if(pSessionTblInfo->SessionTbl[Index].SessionID == *((uint32_t *)Session) )
+           {
+               return &pSessionTblInfo->SessionTbl[Index];
+           }
+           break;
+
+       // case SESSION_REMOTE_INFO:
+       //     if(pSessionTblInfo->SessionTbl[Index].RemConSessionID == *((uint32_t *)Session) )
+       //     {
+       //         return &pSessionTblInfo->SessionTbl[Index];
+       //     }
+       //     break;
+
+       case SESSION_HANDLE_INFO:
+           if (pSessionTblInfo->SessionTbl[Index].SessionHandle == *(( uint8_t*)Session) && pSessionTblInfo->SessionTbl[Index].Activated)
+           {
+           	//printf("---> SessionHandle = %#x\n",pSessionTblInfo->SessionTbl[Index].SessionHandle);
+               return &pSessionTblInfo->SessionTbl[Index];
+           }
+           break;
+
+       case SESSION_INDEX_INFO:
+           if (ActiveSesIndex == *(( uint8_t*)Session))
+           {
+               return &pSessionTblInfo->SessionTbl[Index];
+           }
+           break;
+
+       case SESSION_CHANNEL_INFO:
+           if (pSessionTblInfo->SessionTbl[Index].Channel == *(( uint8_t*)Session))
+           {
+               return &pSessionTblInfo->SessionTbl[Index];
+           }
+           break;
+
+       default:
+           return NULL;
+       }
+   }
+   return NULL;
+}
+
+///*********************************************************************************************
+//    Name	: AddChUser
+//    Input	: ChannelUserInfo
+//    Output	: Pointer to the free entry from the channel's user table.
+//This program returns the free entry from the channel's user table.
+//*********************************************************************************************/
+// ChannelUserInfo_T* AddChUser ( ChannelUserInfo_T* pChUserInfo,  uint8_t*	Index, int BMCInst)
+//{
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    *Index =0;
+//    while (*Index <pBMCInfo->IpmiConfig.MaxChUsers)
+//    {
+//        if(FALSE == pChUserInfo->IPMIMessaging )
+//        {
+//            if(pChUserInfo->ID != USER_ID )
+//                return pChUserInfo;
+//        }
+//        (*Index)++;
+//        pChUserInfo++;
+//    }
+//    return NULL;
+//}
+
+
+/*---------------------------------------
+* GetSelTimeStamp
+*---------------------------------------*/
+uint32_t
+GetTimeStamp(void)
+{
+   return (time(NULL));
+}
+
+/*********************************************************************************************
+   Name	:	GetNumOfActiveSessions
+   Input	:	Nothing
+   Output	:	Number of active Sessions
+
+This program returns the number of active session(s) from the session table
+*********************************************************************************************/
+uint8_t GetNumOfActiveSessions (void)
+{
+   uint8_t				Index, Count = 0;
+   SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+       {
+           continue;
+       }
+       if (pSessionTblInfo->SessionTbl[Index].Activated)
+           Count++;
+   }
+
+   return Count;
+}
+
+/*********************************************************************************************
+   Name	:	GetNumOfUsedSessions
+   Input	:	Nothing
+   Output	:	Number of used Sessions
+
+This program returns the number of used session(s) from the session table
+*********************************************************************************************/
+uint8_t GetNumOfUsedSessions (void)
+{
+   uint8_t				Index, Count = 0;
+   	SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+       {
+           continue;
+       }
+           Count++;
+   }
+
+   return Count;
+}
+
+
+/*********************************************************************************************
+   Name	:	CleanSession
+   Input	:	Nothing
+   Output	:	None
+
+This program delete the oldest session filled but not activate
+*********************************************************************************************/
+uint8_t  CleanSession(void)
+{
+   uint8_t			Index;
+   OldSessionInfo_T     OldSession;
+   SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+
+   OldSession.Time=0xFFFFFFFF;
+   OldSession.Index= 0xFF;
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (TRUE == pSessionTblInfo->SessionTbl[Index].Activated)
+       {
+           continue;
+       }
+
+       if(pSessionTblInfo->SessionTbl[Index].Time <OldSession.Time )
+       {
+           OldSession.Time=pSessionTblInfo->SessionTbl[Index].Time;
+           OldSession.Index=Index;
+       }
+   }
+
+   if(OldSession.Index !=0xFF)
+   {
+       pSessionTblInfo->SessionTbl[OldSession.Index].Used = FALSE;
+       pSessionTblInfo->Count--;
+       pSessionTblInfo->SessionTbl[OldSession.Index].Time=0xffffffff;
+   }else
+   {
+       return FALSE;
+   }
+
+   return TRUE;
+}
+
+
+/*********************************************************************************************
+   Name	:	DeleteSession
+   Input	:	pSessionInfo - session information
+   Output	:	Nothing
+
+This program deletes the session from the session table
+*********************************************************************************************/
+void DeleteSession( SessionInfo_T*	pSessionInfo)
+{
+   uint8_t			Index;		 
+   	SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+   	UserInfo_T*		 pUserInfo;
+      ChannelInfo_T *      pChannelInfo;
+
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+       {
+           continue;
+       }
+
+       if (0 == memcmp (&pSessionTblInfo->SessionTbl[Index], pSessionInfo , sizeof(SessionInfo_T)))
+       {
+           /* We have decrement  the Active session only .If session is activated */
+           if(TRUE ==pSessionTblInfo->SessionTbl[Index].Activated)
+           {
+               // if(!pSessionTblInfo->SessionTbl[Index].IsLoopBack)
+               // {
+               //     pChannelInfo= getChannelInfo(pSessionInfo->Channel);
+               //     if(NULL == pChannelInfo)
+               //     {
+               //         TDBG("Failed to get channel info while Deleting Session for Channel: %d\n",pSessionInfo->Channel);
+               //         return;
+               //     }
+
+               //     if(pChannelInfo!=NULL)
+               //     pChannelInfo->ActiveSession--;
+               //     pUserInfo = getUserIdInfo (pSessionInfo->UserId);
+               //     if (pUserInfo != NULL) { pUserInfo->CurrentSession--; }
+               // }
+               pSessionTblInfo->SessionTbl[Index].Activated=FALSE;
+               pSessionTblInfo->SessionTbl[Index].EventFlag = 0;
+           }
+
+           pSessionTblInfo->SessionTbl[Index].Used = FALSE;
+           pSessionTblInfo->Count--;
+           pSessionTblInfo->SessionTbl[Index].Time=0xFFFFFFFF;
+
+           //printf("DeleteSession: SessionID = %lX	Num Session %X\t%x\n",
+           //pSessionInfo->SessionID, pSessionTblInfo->Count,Index);
+           return;
+       }
+   }
+
+   return;
+}
+
+/*********************************************************************************************
+   Name	:	AddSession
+   Input	:	pSessionInfo - session information
+   Output	:	Nothing
+
+This program adds the session to the session table
+*********************************************************************************************/
+void AddSession ( SessionInfo_T* pSessionInfo)
+{
+   uint8_t Index;
+   	SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+       if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+       {
+           memcpy (&pSessionTblInfo->SessionTbl[Index], ( uint8_t*)pSessionInfo, sizeof (SessionInfo_T));
+           pSessionTblInfo->SessionTbl[Index].Used = TRUE;
+           pSessionTblInfo->Count++;
+           pSessionTblInfo->SessionTbl[Index].Time= GetTimeStamp ();
+           pSessionTblInfo->SessionTbl[Index].TimeOutValue=g_BMCInfo.IpmiConfig.SessionTimeOut;
+//           printf ("AddSession: SessionID   = %lX  Num Session %X\t%x\n",pSessionInfo->SessionID, pSessionTblInfo->Count,Index);
+           break;
+       }
+   }
+
+}
+
+// /*********************************************************************************************
+//    Name	:	getPayloadActiveInst
+//    Input	:	PayloadType
+//    Output	:	Activated Instance information of a given payload type.
+
+// This program returns the information about the activated instances of a given payload type.
+// *********************************************************************************************/
+// uint16_t getPayloadActiveInst (uint8_t PayloadType)
+// {
+//    uint8_t   PayloadIx;
+//    uint8_t   Index;
+//    uint16_t	ActivatedInst = 0;
+//    	SessionTblInfo_T*	pSessionTblInfo = &g_BMCInfo.SessionTblInfo;
+
+
+//    for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+//    {
+//        if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+//        {
+//            continue;
+//        }
+//        if (FALSE == pSessionTblInfo->SessionTbl[Index].Activated)
+//        {
+//            continue;
+//        }
+
+//        for (PayloadIx = 0; PayloadIx < MAX_PYLDS_SUPPORT; PayloadIx++)
+//        {
+//            if (pSessionTblInfo->SessionTbl[Index].SessPyldInfo [PayloadIx].Type == PayloadType)
+//            {
+//                ActivatedInst |= pSessionTblInfo->SessionTbl[Index].SessPyldInfo [PayloadIx].ActivatedInst;
+//            }
+//        }
+//    }
+
+//    return ActivatedInst;
+// }
+
+///*********************************************************************************************
+//    Name	:	getPayloadInstInfo
+//    Input	:	Payloadtype, PayloadInst
+//    Output	:	sessionID
+
+//This program  returns the session ID of the session that was activated under the given payload 
+//type and payload instance.
+//*********************************************************************************************/
+// uint32_t getPayloadInstInfo (uint8_t PayloadType, uint16_t PayloadInst, int BMCInst)
+//{
+//    uint8_t   PayloadIx;
+//    uint8_t   Index;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//    	SessionTblInfo_T*	pSessionTblInfo = &pBMCInfo->SessionTblInfo;
+
+
+//    for (Index = 0; Index < pBMCInfo->IpmiConfig.MaxSession; Index++)
+//    {
+//        if (FALSE == pSessionTblInfo->SessionTbl[Index].Used)
+//        {
+//            continue;
+//        }
+//        if (FALSE == pSessionTblInfo->SessionTbl[Index].Activated)
+//        {
+//            continue;
+//        }
+
+//        for (PayloadIx = 0; PayloadIx < MAX_PYLDS_SUPPORT; PayloadIx++)
+//        {
+//            if ((pSessionTblInfo->SessionTbl[Index].SessPyldInfo [PayloadIx].Type == PayloadType)
+//                && (pSessionTblInfo->SessionTbl[Index].SessPyldInfo [PayloadIx].ActivatedInst & (1 << (PayloadInst - 1))))
+//            {
+//                return pSessionTblInfo->SessionTbl[Index].SessionID;
+//            }
+//        }
+//    }
+
+//    return 0;
+//}
+
+static
+MsgPkt_T m_MsgPkt = {
+   PARAM_IFC,
+   0,                  /* Channel number not needed    */
+   0,                /* Source queue not needed      */
+   CMD_PLATFORM_EVENT, /* Cmd                          */
+   (NETFN_SENSOR << 2),/* Net Function                 */
+   PRIV_LOCAL,         /* Privilage                    */
+   0,                  /* Session ID not needed        */
+//   0,
+   WAIT_INFINITE,
+   0,
+   {0},                /* IP Addr not needed           */
+   0,                  /* UDPPort not needed           */
+   0,                  /* Socket  not needed           */
+   sizeof(SELEventRecord_T) + sizeof (IPMIMsgHdr_T) + 1,
+   {
+       0x20,               /* Generator ID             */
+       IPMI_EVM_REVISION,  /* IPMI Version             */
+       SENSOR_TYPE_SECUIRTY_VIOLATION,/*SensorType     */
+       SECUIRTY_VIOLATION_SENSOR_NUMBER,
+       SENSOR_SPECIFIC_READ_TYPE,
+       PW_VIOLATION_OFFSET,
+       0xff,
+       0xff
+   },
+};
+
+/*--------------------------------------------------------------------------*
+* PasswordViolation														*
+*--------------------------------------------------------------------------*/
+void
+PasswordViolation (void)
+{
+   /* Log the AC fail event to SEL	& send an alert */
+   /* Post to Message Hndlr Queue	*/
+   PostMsg ( gFd_MsgHndlrIfc, &m_MsgPkt);
+
+   return;
+}
+
+
+
+/*********************************************************************************************
+   Name	:	UDSSessionTimeOutTask
+   Input	:	void
+   Output	:	void
+       This program  checks for UDS session timeout
+*********************************************************************************************/
+void UDSSessionTimerTask (void)
+{
+   uint8_t Index=0;
+   UDSSessionTblInfo_T *pUDSSessionTblInfo = &g_BMCInfo.UDSSessionTblInfo;
+
+//   printf("-> UDSSessionTimerTask\n");
+   for(Index=0;Index<g_BMCInfo.IpmiConfig.MaxSession;Index++)
+  {
+       if(FALSE == pUDSSessionTblInfo->UDSSessionTbl[Index].Activated)
+       {
+          /* Continue until we find the Next Slot which is being used to reduce the timeout */
+           continue;
+       }
+
+       if(pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue > 0)
+       {
+          /* Reduce the Session Timeout Value if the session is not used */
+           pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue--;
+           continue;
+       }
+       
+      DeleteUDSSession(&pUDSSessionTblInfo->UDSSessionTbl[Index]);
+  }
+}
+
+
+
+/*********************************************************************************************
+   Name	:	GetUDSSessionInfo
+   Input	:	Session - session ID
+   Output	:	Session Information
+
+This program  returns the session information.
+*********************************************************************************************/
+UDSSessionTbl_T* GetUDSSessionInfo (uint8_t Type,void* Data )
+{
+   uint8_t Index;
+    UDSSessionTblInfo_T*	pUDSSessionTblInfo = &g_BMCInfo.UDSSessionTblInfo;
+
+
+   for(Index=0;Index<g_BMCInfo.IpmiConfig.MaxSession;Index++)
+   {
+
+       if(FALSE == pUDSSessionTblInfo->UDSSessionTbl[Index].Activated)
+       {
+           continue;
+       }
+
+       switch(Type)
+       {
+           case UDS_SESSION_ID_INFO:
+               if(*((uint32_t *)Data) == pUDSSessionTblInfo->UDSSessionTbl[Index].SessionID)
+               {
+                    return &pUDSSessionTblInfo->UDSSessionTbl[Index];
+               }
+               break;
+            case UDS_SESSION_HANDLE_INFO:
+               if(*((uint8_t *)Data) == pUDSSessionTblInfo->UDSSessionTbl[Index].LoggedInSessionHandle)
+               {
+                    return &pUDSSessionTblInfo->UDSSessionTbl[Index];
+               }
+               break;
+            case UDS_SESSION_INDEX_INFO:
+               if((*((uint8_t *)Data) < g_BMCInfo.IpmiConfig.MaxSession) && ((Index) == *((uint8_t *)Data )))
+               {
+                   return &pUDSSessionTblInfo->UDSSessionTbl[Index];
+               }
+               break;
+            case UDS_SOCKET_ID_INFO:
+               if(*((int *)Data) == pUDSSessionTblInfo->UDSSessionTbl[Index].UDSSocket)
+               {
+                    return &pUDSSessionTblInfo->UDSSessionTbl[Index];
+               }
+               break;
+
+           default:
+               break;
+       }
+   }
+
+   return NULL;
+}
+
+/*********************************************************************************************
+   Name	:	AddUDSSession
+   Input	:	pUDSSessionInfo - session information
+   Output	:	return 0 on success ,-1 on failure
+
+This program adds the session to the UDS session table
+*********************************************************************************************/
+int AddUDSSession ( UDSSessionTbl_T* pUDSSessionInfo)
+{
+
+   uint8_t Index;
+    UDSSessionTblInfo_T*	pUDSSessionTblInfo = &g_BMCInfo.UDSSessionTblInfo;
+
+   for (Index = 0; Index < g_BMCInfo.IpmiConfig.MaxSession; Index++)
+   {
+           if(TRUE == pUDSSessionTblInfo->UDSSessionTbl[Index].Activated)
+           {
+                /* Continue Inorder to get the next Free Slot in UDS Session Table */
+                continue;
+           }
+
+           /* Copy the Session Information to Global BMC Info UDS Session Table */
+           memcpy (&pUDSSessionTblInfo->UDSSessionTbl[Index], ( uint8_t*)pUDSSessionInfo, sizeof (UDSSessionTbl_T));
+           pUDSSessionTblInfo->SessionCount++;
+           pUDSSessionTblInfo->UDSSessionTbl[Index].LoggedInTime = GetTimeStamp ();
+           pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue = g_BMCInfo.IpmiConfig.SessionTimeOut;
+           break;
+   }
+
+   if(Index == g_BMCInfo.IpmiConfig.MaxSession)
+   {
+       printf("Add Session Failed for UDS\n");
+       return -1;
+   }
+
+   return 0;
+}
+
+/*********************************************************************************************
+   Name	:	DeleteUDSSession
+   Input	:	pUDSSessionInfo - session information
+   Output	:	return 0 on success,-1 on failure
+
+This program deletes the session from the UDS session table
+*********************************************************************************************/
+int DeleteUDSSession( UDSSessionTbl_T *pUDSSessionInfo )
+{
+   uint8_t Index;
+    UDSSessionTblInfo_T*	pUDSSessionTblInfo = &g_BMCInfo.UDSSessionTblInfo;
+
+   for(Index=0;Index<g_BMCInfo.IpmiConfig.MaxSession;Index++)
+   {
+       if(FALSE == pUDSSessionTblInfo->UDSSessionTbl[Index].Activated)
+       {
+           /* Continue to get the Next Occupied Session Slot in UDS Session Slot*/
+           continue;
+       }
+
+       if (0 == memcmp (&pUDSSessionTblInfo->UDSSessionTbl[Index], pUDSSessionInfo , sizeof(UDSSessionTbl_T)))
+       {
+            /* Resetting the UDS Session Table Slot as the session is no longer required */
+            pUDSSessionTblInfo->UDSSessionTbl[Index].Activated = FALSE;
+            pUDSSessionTblInfo->UDSSessionTbl[Index].LoggedInTime = 0xFFFFFFFF;
+            pUDSSessionTblInfo->UDSSessionTbl[Index].SessionTimeoutValue = 0;
+            pUDSSessionTblInfo->UDSSessionTbl[Index].LoggedInUserID =  0;
+            pUDSSessionTblInfo->UDSSessionTbl[Index].LoggedInChannel = 0xFF;
+            pUDSSessionTblInfo->UDSSessionTbl[Index].LoggedInPrivilege = 0xFF;
+            pUDSSessionTblInfo->SessionCount--;
+            break;
+       }
+   }
+
+   if(Index == g_BMCInfo.IpmiConfig.MaxSession)
+   {
+       printf("Delete Session Failed for UDS\n");
+       return -1;
+   }
+
+   return 0;
+}
+
+///*---------------------------------------------------
+// * @fn UpdateGetMsgTime
+// * @brief Updates the Current Uptime and timeout value
+// *        for an IPMI Message
+// * 
+// * @param pReq       : IPMI Message Packet
+// * @param ResTimeOut : Timeout Macro string
+// * @param BMCInst    : BMC Instance
+// * 
+// * @return none
+// *----------------------------------------------------*/
+//void UpdateGetMsgTime (MsgPkt_T* pReq,IfcType_T IfcType, int BMCInst)
+//{
+//    pReq->ReqTime    = 0;
+//    pReq->ResTimeOut = WAIT_INFINITE;
+
+//    if( g_corefeatures.ipmi_res_timeout == ENABLED )
+//    {
+//        int i;
+//        struct sysinfo sys_info;
+//        
+//        for( i = 0; i < TOTAL_INFINITE_CMDS; i++)
+//        {
+//            if( NET_FN(pReq->NetFnLUN) == m_InfiniteCmdsTbl[i].NetFn && pReq->Cmd == m_InfiniteCmdsTbl[i].Cmd )
+//            {
+//                return;
+//            }
+//        }
+//        
+//        if(g_PDKCmdsHandle[PDKCMDS_PDKISINFINITECOMMAND]  != NULL)
+//        {
+//            if( ((BOOL(*)(uint8_t,uint8_t))g_PDKCmdsHandle[PDKCMDS_PDKISINFINITECOMMAND])(NET_FN(pReq->NetFnLUN), pReq->Cmd))
+//            {
+//                return;
+//            }
+//        }
+//        
+//        /* Request UpTime */
+//        if(!sysinfo(&sys_info))
+//        {
+//            pReq->ReqTime    = sys_info.uptime;
+//            if(IfcType == IPMB_IFC)
+//            {
+//                pReq->ResTimeOut = g_coremacros.ipmb_res_timeout;
+//            }
+//            else if(IfcType == LAN_IFC)
+//            {
+//                pReq->ResTimeOut = g_coremacros.lan_res_timeout;
+//            }
+//            else if(IfcType == KCS_IFC)
+//            {
+//                pReq->ResTimeOut = g_coremacros.kcs_res_timeout;
+//            }
+//            else if(IfcType == SERIAL_IFC)
+//            {
+//                pReq->ResTimeOut = g_coremacros.serial_res_timeout;
+//            }
+//        }
+//    }
+//}
+
+///*---------------------------------------------------
+// * @fn IsMsgTimedOut
+// * @brief Checks if the time taken to process 
+// *        the IPMI Command expires
+// * 
+// * @param pReq     : IPMI Message Packet
+// * 
+// * @return 1 if timed out
+// *         0 if error or timeout not set 
+// *----------------------------------------------------*/
+//BOOL IsMsgTimedOut (MsgPkt_T* pReq)
+//{
+//    struct sysinfo sys_info;
+//    
+//    if( pReq->ReqTime && (!sysinfo(&sys_info)) )
+//    {
+//        return ( (sys_info.uptime - pReq->ReqTime) > pReq->ResTimeOut) ? TRUE : FALSE;
+//    }
+//    
+//    return FALSE;
+//}
+
+///*-----------------------------------------------------
+// * @fn IsResponseMatch
+// * @brief Checks if the Response Message corresponds to 
+// *        the Request Message
+// * 
+// * @param pReq    : IPMI Request Message Packet
+// * @param pRes    : IPMI Response Message Packet
+// * 
+// * @return  1 if match
+// *          0 if mismatch
+// *----------------------------------------------------*/
+//BOOL IsResponseMatch (MsgPkt_T* pReq, MsgPkt_T* pRes)
+//{
+
+//    if( ( ((((IPMIMsgHdr_T*)pRes->Data)->RqSeqLUN) >> 2) != ((((IPMIMsgHdr_T*)pReq->Data)->RqSeqLUN) >> 2) ) && 
+//        ( (pReq->NetFnLUN & 0x4) && (NO_RESPONSE != pRes->Param) ) )
+//    {
+//        return FALSE;
+//    }
+//  
+//    return TRUE;
+//}
+
+/*-------------------------------------------------------
+ * @fn FillIPMIResFailure
+ * @brief Frames the Response packet when the time taken 
+ *        to process an IPMI Command expires
+ * 
+ * @param pReq    : IPMI Request Message Packet
+ * @param pRes    : IPMI Response Message Packet
+ *        BMCInst : BMC Instance Number
+ * 
+ * @return  none
+ *------------------------------------------------------*/
+void FillIPMIResFailure ( MsgPkt_T* pReq,  MsgPkt_T* pRes)
+{  
+    /* Set the Cmd and Net function in response packet */
+    pRes->Cmd      = pReq->Cmd;
+    pRes->NetFnLUN = pReq->NetFnLUN & 0xFC;
+    
+    /* Normal IPMI Command response */
+    pRes->Param = PARAM_NORMAL_RESPONSE;
+  
+ 
+	pRes->Size  = sizeof (IPMIMsgHdr_T) + sizeof (uint8_t);
+	pRes->Data[sizeof (IPMIMsgHdr_T)] = CC_TIMEOUT;
+	
+	/* Check for Request Message */
+	if (0 == (pReq->NetFnLUN & 0x04))
+	{
+		/* Swap the header and copy in response */
+		SwapIPMIMsgHdr (( IPMIMsgHdr_T*)pReq->Data, ( IPMIMsgHdr_T*)pRes->Data);
+		
+		/* Calculate Checksum 2 */
+		pRes->Data[pRes->Size] = CalculateCheckSum2 (pRes->Data, pRes->Size);
+		pRes->Size++;
+	}
+}
+
+

+ 250 - 0
app/bmc/Session.h

@@ -0,0 +1,250 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * Session.h
+ *
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ * 		 : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#ifndef SESSION_H
+#define SESSION_H
+#include "com_BmcType.h"
+#include "com_IPMI_LANIfc.h"
+#include "com_IPMI_RMCP+.h"
+#include "com_IPMI_AppDevice.h"
+#include "com_IPMIDefs.h"
+#include "com_Message.h"
+#include "PMConfig.h"
+#pragma pack( 1 )
+
+/* Macros */
+#define		SESSION_ID_INFO							1
+#define		SESSION_HANDLE_INFO						2
+#define		SESSION_INDEX_INFO						3
+#define		SESSION_CHANNEL_INFO					4
+#define		MGD_SYS_SESSION_ID_INFO					5
+#define		SESSION_PAYLOAD_INFO					6
+#define		SESSION_REMOTE_INFO					7
+#define		MAX_INST_SUPPORTED						2
+#define		SESSIONLESS_CHANNEL						0x00
+#define		SINGLE_SESSION_CHANNEL					0x01
+#define		MULTI_SESSION_CHANNEL					0x02
+#define		SESSION_BASED_CHANNEL					0x03
+#define		HASH_DATA_LENGTH						16
+#define		NULL_USER_ID							1
+
+#define UDS_SESSION_COUNT_INFO                      0x00
+#define UDS_SESSION_ID_INFO                         0x01
+#define UDS_SESSION_HANDLE_INFO                     0x02
+#define UDS_SESSION_INDEX_INFO                      0x03
+#define UDS_SOCKET_ID_INFO                          0x04
+#define UDS_SESSION_PID_INFO                        0x05
+#define UDS_ACTIVE_SESSION_INDEX_LIST               0x06
+
+/* UDS Session Table Info */
+typedef struct
+{
+   uint32_t SessionID;
+   uint32_t LoggedInTime;
+   uint32_t SessionTimeoutValue;
+   int UDSSocket;
+   uint8_t LoggedInUsername[MAX_USERNAME_LEN];
+   uint8_t LoggedInPassword[MAX_PASSWORD_LEN];
+   uint8_t LoggedInUserID;
+   uint8_t Activated;
+   uint8_t LoggedInSessionHandle;
+   uint8_t UDSChannelNum;
+   uint8_t LoggedInChannel;
+   uint8_t LoggedInPrivilege;
+   uint8_t AuthenticationMechanism;
+   uint32_t ProcessID;
+   uint32_t ThreadID;
+   uint8_t IPAddr [IP6_ADDR_LEN];
+}  UDSSessionTbl_T;
+
+typedef struct
+{
+    uint16_t SessionCount;
+    UDSSessionTbl_T *UDSSessionTbl;
+}  UDSSessionTblInfo_T;
+
+/* SessPayloadInfo_T */
+typedef struct
+{
+    uint8_t    Type;
+    uint8_t    OemPldIANA [3];
+    uint8_t    OemPldID [2];
+    uint8_t    Version;
+    uint16_t    PortNum;
+    uint16_t    ActivatedInst;
+    uint8_t    AuxConfig [4];
+
+}    SessPayloadInfo_T;
+
+
+/*	structure to  keep track the information about a session.	*/
+/* SessionInfo_T */
+typedef struct
+{
+    uint8_t			Used; /* Flag to indicate the slot used or not */
+    uint32_t		SessionID;
+    uint8_t			Activated;
+    uint8_t			Channel;
+    uint8_t			AuthType;
+    uint8_t			Privilege;
+    uint8_t			MaxPrivilege;
+    uint32_t			InboundSeq;
+    uint32_t			OutboundSeq;
+    uint32_t			TimeOutValue;
+    uint8_t			Password[MAX_PASSWORD_LEN];
+    uint8_t			UserId;
+    uint8_t			SessionHandle;
+//     uint8_t			ChallengeString[CHALLENGE_STR_LEN];
+    LANRMCPPkt_T	LANRMCPPkt;
+    int			hSocket;
+//     BOOL			SerialModemMode;
+    uint32_t 			Time;
+// #if (IPMI20_SUPPORT == 1)
+//     uint8_t				Lookup;
+//     uint32_t				RemConSessionID;
+//     uint8_t				RemConRandomNo [16];
+//     uint8_t				MgdSysRandomNo [16];
+//     uint8_t				AuthAlgorithm;
+//     uint8_t				IntegrityAlgorithm;
+//     uint8_t				ConfidentialityAlgorithm;
+//     uint8_t				Key1 [MAX_HASH_KEY_SIZE];
+//     uint8_t				Key2 [MAX_HASH_KEY_SIZE];
+//     SessPayloadInfo_T	SessPyldInfo [MAX_PYLDS_SUPPORT];
+// #endif
+//     uint32_t                   InitialInboundSeq;
+//     uint32_t                   InboundTrac[SIXTEEN_COUNT_WINDOW_LEN];
+    uint16_t                   InboundRecv;
+    uint8_t 			IsLoopBack;
+    uint8_t       Linkstat;
+    uint8_t 			EventFlag;
+    uint8_t                       UserName[MAX_USERNAME_LEN];
+} SessionInfo_T;
+
+/* SessionTblInfo_T */
+typedef	struct
+{
+    uint16_t			Count;
+    SessionInfo_T	*SessionTbl;
+}    SessionTblInfo_T;
+
+
+typedef struct
+{
+    uint32_t Time;
+    uint8_t  Index;
+}   OldSessionInfo_T;
+
+typedef enum
+{
+    KCS_IFC = 0x00,
+    IPMB_IFC,
+    LAN_IFC,
+    SERIAL_IFC,
+}IfcType_T;
+
+#pragma pack( )
+
+// /*--------------------------
+//  * Extern Declarations
+//  *--------------------------*/
+extern		 void				SessionTimerTask (void);
+// extern  ChannelInfo_T*  getChannelInfo (uint8_t ch );
+// extern _FAR_ ChannelUserInfo_T* getChUserIdInfo (uint8_t userId, _NEAR_ uint8_t *index, _FAR_ ChannelUserInfo_T* pChUserInfo, int BMCInst);
+extern SessionInfo_T*		getSessionInfo (uint8_t Arg, void *Session);
+// extern _FAR_ ChannelUserInfo_T* getChUserPrivInfo (_NEAR_ char *userName, _NEAR_ uint8_t Role, _NEAR_ uint8_t* chIndex, _FAR_ ChannelUserInfo_T *pChUserInfo, int BMCInst);
+// extern _FAR_ ChannelUserInfo_T*	getChUserInfo (_NEAR_ char *userName, _NEAR_ uint8_t* chIndex, _FAR_ ChannelUserInfo_T *pChUserInfo, int BMCInst);
+extern UserInfo_T*		getUserIdInfo (uint8_t userId);
+extern  UserInfo_T* getUserNameInfo (uint8_t *UserName);
+extern uint8_t	CheckForDuplicateUsers (uint8_t* UserName);
+// extern _FAR_ ChannelUserInfo_T*	AddChUser (_FAR_ ChannelUserInfo_T*	pChUserInfo, _NEAR_ uint8_t*	Index );
+// extern _FAR_ ChannelInfo_T* GetNVRChConfigs(ChannelInfo_T *pChannelInfo, int BMCInst);
+// extern _FAR_ ChannelUserInfo_T* GetNVRChUserConfigs(ChannelInfo_T *pChannelInfo );
+// extern uint8_t disableUser (uint8_t UserId, int BMCInst);
+extern uint8_t GetNumOfActiveSessions (void);
+extern uint8_t GetNumOfUsedSessions (void);
+extern void  DeleteSession (SessionInfo_T*	pSessionInfo );
+extern void  AddSession (SessionInfo_T* pSessionInfo );
+extern uint8_t CleanSession(void);
+// extern _FAR_ uint16_t	getPayloadActiveInst (uint8_t PayloadType, int BMCInst);
+// extern _FAR_ uint32_t	getPayloadInstInfo (uint8_t PayloadType, uint16_t PayloadInst );
+extern void	PasswordViolation (void);
+extern void UDSSessionTimerTask (void);
+extern int AddUDSSession (UDSSessionTbl_T* pUDSSessionInfo);
+extern int DeleteUDSSession(UDSSessionTbl_T*  pUDSSessionInfo );
+extern UDSSessionTbl_T* GetUDSSessionInfo (uint8_t Type,void *Data );
+// /*---------------------------------------------------
+//  * @fn UpdateGetMsgTime
+//  * @brief Updates the Current Uptime and timeout value
+//  *        for an IPMI Message
+//  * 
+//  * @param pReq       : IPMI Message Packet
+//  * @param ResTimeOut : Timeout Macro string
+//  * @param BMCInst    : BMC Instance
+//  * 
+//  * @return none
+//  *----------------------------------------------------*/
+
+// extern void UpdateGetMsgTime (MsgPkt_T* pReq,IfcType_T IfcType, int BMCInst);
+
+// /*---------------------------------------------------
+//  * @fn IsMsgTimedOut
+//  * @brief Checks if the time taken to process 
+//  *        the IPMI Command expires
+//  * 
+//  * @param pReq     : IPMI Message Packet
+//  * 
+//  * @return 1 if timed out
+//  *         0 if error or timeout not set 
+//  *----------------------------------------------------*/
+
+// extern BOOL IsMsgTimedOut (MsgPkt_T* pReq);
+
+// /*-----------------------------------------------------
+//  * @fn IsResponseMatch
+//  * @brief Checks if the Response Message corresponds to 
+//  *        the Request Message
+//  * 
+//  * @param pReq    : IPMI Request Message Packet
+//  * @param pRes    : IPMI Response Message Packet
+//  * 
+//  * @return  1 if match
+//  *          0 if mismatch
+//  *----------------------------------------------------*/
+
+// extern BOOL IsResponseMatch (MsgPkt_T* pReq, MsgPkt_T* pRes);
+
+/*-------------------------------------------------------
+ * @fn FillIPMIResFailure
+ * @brief Frames the Response packet when the time taken 
+ *        to process an IPMI Command expires
+ * 
+ * @param pReq    : Request Message Packet
+ *        pRes    : Response Message Packet
+ *        BMCInst : BMC Instance Number
+ * 
+ * @return  none
+ *------------------------------------------------------*/
+extern void FillIPMIResFailure ( MsgPkt_T* pReq, MsgPkt_T* pRes);
+
+#endif	/* SESSION_H */

+ 101 - 0
app/bmc/SysTimer/TimerTask.c

@@ -0,0 +1,101 @@
+/*
+* Brief:	Micellaneous Ticks increment every 1 second.
+			Record system power on times.
+* Author:	Jimbo_Zhang@outlook.com
+* Date:		2019-9-16
+*/
+
+#include "TimerTask.h"
+#include "time.h"
+#include <stdint.h>
+#include "main.h"
+#include <signal.h>
+
+static void ProcessTimerReq (void);
+
+//g_BMCInfo.CurTimerTick increment in port.c/xPortSysTickHandler().
+// void *TimerTask( void *pvParameters )
+// {	
+// 	uint32_t preTimerTick = g_BMCInfo.CurTimerTick;
+// 	printf("TimerTask start...\n");
+// 	while(1)
+// 	{
+// 		preTimerTick = g_BMCInfo.CurTimerTick;
+// 		g_BMCInfo.SELTimeSecond++;
+	
+// 		if(g_BMCInfo.SensorSharedMem.SensorTick < 0xffffffff)	
+// 			g_BMCInfo.SensorSharedMem.SensorTick++;
+		
+// 		if(g_BMCInfo.SenConfig.PowerOnTick < 0xffffffff)
+// 			g_BMCInfo.SenConfig.PowerOnTick++;
+		
+// 		if(g_BMCInfo.SenConfig.SysResetTick < 0xffffffff)
+// 			g_BMCInfo.SenConfig.SysResetTick++;
+		
+// 		g_BMCInfo.CurTimerSecond++;
+// 		if(g_BMCInfo.PowerGoodFlag && (g_BMCInfo.CurTimerSecond%60 == 0))	// 1minute
+// 		{
+// 			g_BMCInfo.BootValidMinutes++;
+// 			g_BMCInfo.TotalBootValidMinutes++;
+// 		}
+
+// 		ProcessTimerReq();
+
+// 		sleep(1);
+// 	}
+// }
+
+void TimerTask( int signo )	//signal handler
+{	
+	//printf("TimerTask start...\n");
+	switch(signo)
+	{
+	case SIGALRM:
+		//preTimerTick = g_BMCInfo.CurTimerTick;
+		//g_BMCInfo.SELTimeSecond++;
+	
+		if(g_BMCInfo.SensorSharedMem.SensorTick < 0xffffffff)	
+			g_BMCInfo.SensorSharedMem.SensorTick++;
+		
+		if(g_BMCInfo.SenConfig.PowerOnTick < 0xffffffff)
+			g_BMCInfo.SenConfig.PowerOnTick++;
+		
+		if(g_BMCInfo.SenConfig.SysResetTick < 0xffffffff)
+			g_BMCInfo.SenConfig.SysResetTick++;
+		
+		g_BMCInfo.CurTimerSecond++;
+		if(g_BMCInfo.PowerGoodFlag && (g_BMCInfo.CurTimerSecond%60 == 0))	// 1minute
+		{
+			g_BMCInfo.BootValidMinutes++;
+			g_BMCInfo.TotalBootValidMinutes++;
+		}
+
+		ProcessTimerReq();
+		break;
+	}
+}
+
+
+
+/**
+*@fn ProcessTimerReq
+*@brief Executes Timer task function for every one second
+*@return none
+*/
+static void ProcessTimerReq (void)
+{
+	int i;
+	for (i = 0; i < g_BMCInfo.TimerTaskTblSize; i++)
+	{
+		if (0 == (g_BMCInfo.CurTimerTick % g_BMCInfo.TimerTaskTbl [i].NumSecs))
+		{
+			g_BMCInfo.TimerTaskTbl [i].TimerFn ();
+		}
+	}
+	return;
+}
+
+
+
+
+

+ 7 - 0
app/bmc/SysTimer/TimerTask.h

@@ -0,0 +1,7 @@
+#ifndef __TIMER_TASK_H__
+#define __TIMER_TASK_H__
+
+//void *TimerTask( void *pvParameters );
+void TimerTask( int signo );
+
+#endif

+ 249 - 0
app/bmc/Util.c

@@ -0,0 +1,249 @@
+
+#include "Util.h"
+#include <sys/sysinfo.h> 
+
+
+/*----------------------------------------
+ * GetBits
+ *----------------------------------------*/
+uint8_t
+GetBits (uint8_t Val, uint8_t Mask)
+{
+    uint8_t ExtVal = 0;
+    while (0 != Mask)
+    {
+        if (0 != (Mask & 0x80))
+        {
+            ExtVal <<= 1;
+            if (0 != (Val & 0x80)) { ExtVal += 0x01; }
+        }
+
+        Val <<= 1;
+        Mask <<= 1;
+    }
+
+    return ExtVal;
+}
+
+/*------------------------------------------
+ * SetBits
+ *------------------------------------------*/
+uint8_t
+SetBits (uint8_t Mask, uint8_t Val)
+{
+    uint8_t FinVal = 0;
+    uint8_t i;
+
+    for (i = 0; i < 8; i++)
+    {
+        FinVal >>= 1;
+        if (0 != (Mask & 0x01))
+        {
+            if (0 != (Val & 0x01)) { FinVal |= 0x80; }
+                Val >>= 1;
+        }
+        Mask   >>= 1;
+    }
+
+    return FinVal;
+}
+
+/*------------------------------------------
+ * CalculateCheckSum
+ *------------------------------------------*/
+uint8_t
+CalculateCheckSum (uint8_t* Data, uint16_t Len)
+{
+    uint8_t   Sum;
+    uint16_t  i;
+
+    Sum = 0;
+    for (i = 0; i < Len; i++)
+    {
+        Sum += Data [i];
+    }
+    return (0x100 - Sum);
+}
+
+/*
+* @fn TimeUpdate
+* @return Returns the system uptime
+*/
+uint32_t TimeUpdate()
+{
+    struct sysinfo time;
+    sysinfo(&time);
+    return time.uptime;
+}
+
+// /**
+// *@fn GetSysCtlvalue
+// *@brief This function retrieves the values from Sysctl
+// *@param TagName -Tagname form which value has to be retrieved
+// *@param SysVal - Where the value is stored
+// *@return Returns 0 on success
+// *            Returns 1 on failure
+// */
+// int GetJiffySysCtlvalue (const char *TagName, long long *SysVal)
+// {
+//     unsigned long RetVal;
+//     FILE* SysFile = fopen (TagName, "r");
+//     unsigned long Hertz = sysconf(_SC_CLK_TCK);
+
+//     if ((!SysFile) || (!SysVal))
+//         return 1;
+
+//     fscanf (SysFile, "%lu", &RetVal);
+//     fclose (SysFile);
+
+//     *SysVal = (RetVal*1000)/Hertz;
+//     return 0;
+// }
+
+
+/*
+    index = 0,1,2,3,4,5
+*/
+uint8_t mac2hex(const char *strMac, uint8_t index)
+{
+    int i = 0;
+    char    *pStr = (char *)strMac;
+    char    *pTmp = NULL;
+    uint8_t macByte = 0;;
+    char    tmp[3] = {0};
+
+    if(index > 5)
+    {
+        printf("Invalid index %d\n", index);
+        return -1;
+    }
+
+    //find
+    while(pStr)
+    {
+        if(i == index)
+            break;
+
+        if(*pStr == ':')
+            i++;
+        
+        pStr++;
+    }
+
+    if(*(pStr+1) == ':')
+    {
+        tmp[0] = *pStr;
+        tmp[1] = '\0';
+        tmp[2] = '\0';
+    }
+    else
+    {
+        tmp[0] = *pStr;
+        tmp[1] = *(pStr+1);
+        tmp[2] = '\0';
+    }
+
+    i=0;
+    macByte = 0;
+    while(tmp[i])
+    {
+        macByte = macByte<<4;
+        if((tmp[i]>='0') && (tmp[i]<='9'))
+            macByte += (tmp[i]-'0');
+        else if((tmp[i]>='a') && (tmp[i]<='f'))
+            macByte += (tmp[i]-'a') + 10;
+        else if((tmp[i]>='A') && (tmp[i]<='F'))
+            macByte += (tmp[i]-'A') + 10;
+
+        i++;
+    }
+
+    return macByte;     
+}
+
+/*
+    index = 0,1,2,3
+*/
+uint8_t ip2dec(const char *strIp, uint8_t index)
+{
+    int i = 0;
+    char    *pStr = (char *)strIp;
+    uint8_t ipByte = 0;;
+    char    tmp[4] = {0};
+
+    if(index > 3)
+    {
+        printf("Invalid index %d\n", index);
+        return -1;
+    }
+
+    //find
+    while(pStr)
+    {
+        if(i == index)
+            break;
+
+        if(*pStr == '.')
+            i++;
+        
+        pStr++;
+    }
+
+    if(*(pStr+1) == '.')
+    {
+        tmp[0] = *pStr;
+        tmp[1] = '\0';
+        tmp[2] = '\0';
+        tmp[3] = '\0';
+    }
+    else if(*(pStr+2) == '.')
+    {
+        tmp[0] = *pStr;
+        tmp[1] = *(pStr+1);
+        tmp[2] = '\0';
+        tmp[3] = '\0';
+    }
+    else
+    {
+        tmp[0] = *pStr;
+        tmp[1] = *(pStr+1);
+        tmp[2] = *(pStr+2);
+        tmp[3] = '\0';
+    }
+
+    ipByte = atoi(tmp);
+
+    return ipByte;     
+}
+
+
+int FlushUserInfo(void)
+{
+    //TODO:
+    return 0;
+}
+
+int FlushFRU(void)
+{
+    //TODO:
+    return 0;
+}
+
+int FlushSDR(void)
+{
+    //TODO:
+    return 0;
+}
+
+int FlushIpmiConfig(void)
+{
+    //TODO:
+    return 0;
+}
+
+int FlushSEL(void)
+{
+    //TODO:
+    return 0;
+}
+

+ 82 - 0
app/bmc/Util.h

@@ -0,0 +1,82 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * util.h
+ * Utility functions.
+ *
+ * Author: Govind Kothandapani <govindk@ami.com> 
+ * 
+ *****************************************************************/
+#ifndef UTIL_H
+#define UTIL_H
+
+#include "com_IPMIDefs.h"
+#include <stdio.h>
+
+/**
+ * Returns the maximum of two values
+**/
+#define UTIL_MAX(val1, val2) \
+    ((val1 > val2) ? val1 : val2)
+
+/**
+ * Returns the minimum of two values
+**/
+#define UTIL_MIN(val1, val2) \
+    ((val1 < val2) ? val1 : val2)
+
+/**
+ * @brief Extracts the contents of the bits corresponding to the mask.
+**/
+ uint8_t GetBits (uint8_t Val, uint8_t Mask);
+
+/**
+ * @brief Sets the bits corresponding to the mask according to the value.
+**/
+ uint8_t SetBits (uint8_t Mask, uint8_t Val);
+
+/**
+ * @brief Find the checksum
+**/
+ uint8_t CalculateCheckSum (uint8_t* Data, uint16_t Len);
+
+// *
+// *@ brief Retrieves the value from sysctl
+
+// int GetJiffySysCtlvalue (const char *TagName, long long *SysVal);
+
+
+/*
+    index = 0,1,2,3,4,5
+*/
+uint8_t mac2hex(const char *strMac, uint8_t index);
+/*
+    index = 0,1,2,3
+*/
+uint8_t ip2dec(const char *strIp, uint8_t index);
+
+int FlushUserInfo(void);
+int FlushFRU(void);
+int FlushSDR(void);
+int FlushIpmiConfig(void);
+int FlushSEL(void);
+
+
+
+
+
+
+
+#endif	/* UTIL_H */

BIN
app/bmc/bmc_app


+ 91 - 0
app/bmc/encryption/AuthCode.c

@@ -0,0 +1,91 @@
+/******************************************************************
+ ******************************************************************
+ ***                                                             **
+ ***    (C)Copyright 2008-2009, American Megatrends Inc.         **
+ ***                                                             **
+ ***    All Rights Reserved.                                     **
+ ***                                                             **
+ ***    5555 , Oakbrook Pkwy, Norcross,                          **
+ ***                                                             **
+ ***    Georgia - 30093, USA. Phone-(770)-246-8600.              **
+ ***                                                             **
+ ******************************************************************
+ ******************************************************************
+ ******************************************************************
+ *
+ * AuthCode.c
+ * Authentication Code Caluculation
+ *
+ *  Author: Winston <winstonv@amiindia.co.in>
+ ******************************************************************/
+#include "RMCP.h"
+#include "MD.h"
+#include <string.h>
+#include <stdint.h>
+#include "com_IPMIDefs.h"
+#include "com_IPMI_RMCP.h"
+#include "com_IPMI_AppDevice.h"
+#include "Session.h"
+
+/**
+ * @fn ComputeAuthCode
+ * @brief Compute authentication code.
+ * @param pPassword     - User password.
+ * @param pSessionHdr   - Session header RMCP message.
+ * @param pIPMIMsg      - IPMI message payload.
+ * @param pAuthCode     - Authentication Code being generated.
+ * @param ChannelType   - Channel Type.
+**/
+void
+ComputeAuthCode ( uint8_t* pPassword,  SessionHdr_T* pSessionHdr,
+                  IPMIMsgHdr_T* pIPMIMsg,  uint8_t* pAuthCode,
+                 uint8_t ChannelType)
+{
+    if (AUTH_TYPE_PASSWORD == pSessionHdr->AuthType)
+    {
+        memcpy (pAuthCode, pPassword, IPMI15_MAX_PASSWORD_LEN);
+    }
+    else
+    {
+        uint8_t   AuthBuf [MAX_AUTH_PARAM_SIZE];
+        uint16_t  AuthBufLen = 0;
+        uint8_t   IPMIMsgLen = *(( uint8_t*) pIPMIMsg - 1);
+
+        /* Password */
+        memcpy (AuthBuf, pPassword, IPMI15_MAX_PASSWORD_LEN);
+        AuthBufLen += IPMI15_MAX_PASSWORD_LEN;
+        /* Session ID */
+        memcpy ((uint8_t*)(AuthBuf + AuthBufLen), (uint8_t*)(&pSessionHdr->SessionID), sizeof (uint32_t));
+        AuthBufLen += sizeof (uint32_t);
+        /* IPMI Response Message */
+        memcpy (AuthBuf + AuthBufLen, pIPMIMsg, IPMIMsgLen);
+        AuthBufLen += IPMIMsgLen;
+
+        if (ChannelType == MULTI_SESSION_CHANNEL)
+        {
+            /* Session Sequence Number */
+            memcpy ((uint8_t*)(AuthBuf + AuthBufLen), (uint8_t*)(&pSessionHdr->SessionSeqNum), sizeof (uint32_t));
+            AuthBufLen += sizeof (uint32_t);
+        }
+        /* Password */
+        memcpy (AuthBuf + AuthBufLen, pPassword, IPMI15_MAX_PASSWORD_LEN);
+        AuthBufLen += IPMI15_MAX_PASSWORD_LEN;
+
+        switch (pSessionHdr->AuthType)
+        {
+        case AUTH_TYPE_MD2 :
+            AuthCodeCalMD2 (AuthBuf, pAuthCode, AuthBufLen);
+            break;
+
+        case AUTH_TYPE_MD5 :
+            AuthCodeCalMD5 (AuthBuf, pAuthCode, AuthBufLen);
+            break;
+
+        default  :
+            printf ("RMCP.c : Invalid Authentication Type \r\n");
+        }
+    }
+}
+
+
+

+ 15 - 0
app/bmc/encryption/AuthCode.h

@@ -0,0 +1,15 @@
+#ifndef __AUTH_CODE_H__
+#define __AUTH_CODE_H__
+
+#include <stdint.h>
+#include "com_IPMIDefs.h"
+#include "com_IPMI_RMCP.h"
+
+
+void
+ComputeAuthCode ( uint8_t* pPassword,  SessionHdr_T* pSessionHdr,
+                  IPMIMsgHdr_T* pIPMIMsg,  uint8_t* pAuthCode,
+                 uint8_t ChannelType);
+
+
+#endif                

+ 68 - 0
app/bmc/encryption/MD.h

@@ -0,0 +1,68 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * MD.h
+ * Message Digest Functions
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ * 		 : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#ifndef MD_H
+#define MD_H
+#include <stdint.h>
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+
+#pragma pack( 1 )
+
+/* Authentication Type */
+#define		AUTH_TYPE_NONE							0
+#define		AUTH_TYPE_MD2							1
+#define		AUTH_TYPE_MD5							2
+#define		AUTH_TYPE_PASSWORD						4
+#define		AUTH_TYPE_OEM							5
+
+
+/* MD2Context_T */
+typedef struct 
+{
+    uint8_t		State[16];      /* state */
+    uint8_t		Checksum[16];   /* checksum */
+    uint8_t		Count;			/* number of bytes, modulo 16 */
+    uint8_t		Buffer[16];     /* input buffer */
+}    MD2Context_T;
+
+
+/* MD5Context_T */
+typedef struct 
+{
+    uint32_t	state[4];		/* state (ABCD) */
+    uint32_t	count[2];		/* number of bits, modulo 2^64 (lsb first) */
+    uint8_t		buffer[64];		/* input buffer */
+}    MD5Context_T;
+
+#pragma pack( )
+
+/*--------------------------
+ * Extern Declarations
+ *--------------------------*/
+extern void AuthCodeCalMD2 (  uint8_t* String,   uint8_t*	MD2Result, uint8_t StrLen);
+extern void AuthCodeCalMD5 (  uint8_t* Str,   uint8_t* MD5Result, uint16_t StrLen);
+
+#endif	/* MD_H */
+

+ 93 - 0
app/bmc/encryption/MD2.c

@@ -0,0 +1,93 @@
+/* MD2.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+#include "md2.h"
+
+
+#define MD2Context_T    MD2_CTX
+#define MD2Init         MD2_Init
+#define MD2Update       MD2_Update
+#define MD2Final        MD2_Final
+
+/*********************************************************************************************
+    Name    :   AuthCodeCalMD2
+    Input   : Test string and a buffer of 16 bytes to store the digest.
+    Output  : Encrypted message in the buffer.
+    Return  : NONE
+     This program digests a string and prints the result.
+*********************************************************************************************/
+extern void AuthCodeCalMD2 (   uint8_t*  String,     /*test string*/
+                               uint8_t*  MD2Result,  /*result of MD2 digest*/
+                                    uint8_t   StrLen      /*Length of input string */
+                            )
+{
+  MD2Context_T  MD2Context;
+  uint8_t         Digest[16];
+
+  MD2Init (&MD2Context);
+  MD2Update (&MD2Context, String, StrLen);
+  MD2Final (Digest, &MD2Context);
+  memcpy(MD2Result, Digest, 16);
+}

+ 70 - 0
app/bmc/encryption/MD5.c

@@ -0,0 +1,70 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.  
+                                                                    
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.  
+                                                                    
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.  
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+#include "md5.h"
+
+#define MD_CTX MD5_CTX
+#define MDInit MD5_Init
+#define MDUpdate MD5_Update
+#define MDFinal MD5_Final
+
+/*
+    INPUT  : Test string , buffer of 16 bytes to
+                store the digest,length of the string
+    OUTPUT	: Encrypted message in the buffer.
+    RETURN	: NONE
+    PROCESS	:Digests a string and prints the result.
+ */
+extern void AuthCodeCalMD5(
+          uint8_t  *string, 	/*test string */
+          uint8_t  *MD5Result,  /*result of MD5 digest*/
+          uint16_t LengthOfstring /*Length of input string */
+          )
+{
+    MD_CTX context;
+    uint8_t  digest[16];
+    MDInit (&context);
+    MDUpdate (&context, string, LengthOfstring);
+    MDFinal (digest, &context);
+    memcpy(MD5Result,digest,16);
+
+}
+unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
+{
+    MD5_CTX c;
+    static unsigned char m[16];
+
+    if (md == NULL) md=m;
+    MD5_Init(&c);
+    MD5_Update(&c,(unsigned char *)d,n);
+    MD5_Final(md,&c);
+//    OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
+    return(md);
+}

+ 63 - 0
app/bmc/encryption/MD5_128.c

@@ -0,0 +1,63 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ *****************************************************************
+ *
+ *   Md5_128.c   
+ *   This Code is taken from RFC 1321(RFC1321)
+ *
+ *
+ *****************************************************************/
+
+
+#include "md5.h"
+
+
+/******************************************************************************      
+*
+*	Name
+*		MD5_128
+*	
+*	Abstract: 	
+*  		Function to compute the digest using MD5.
+*
+*	Context/Scope:	
+*   	Called from anywhere.
+*
+*	Side Effects:
+*
+*	Return Value:
+*		None
+* 
+*	Assumptions:
+*	   None
+*
+******************************************************************************/
+void MD5_128(char*    k,     /* secret key */
+		 int      lk,    /* length of the key in bytes */
+		 char*    d,     /* data */
+		 int      ld,    /* length of data in bytes */
+		 char*    out,   /* output buffer, at least "t" bytes */
+		 int      t )
+{
+      MD5_CTX ctx;
+      MD5_Init(&ctx) ;
+
+      MD5_Update(&ctx, (unsigned char *) k, lk) ;
+      MD5_Update(&ctx, (unsigned char *) d, ld) ;
+	// Added this to match the MD5 for user password integrity
+      MD5_Update(&ctx, (unsigned char *) k, lk) ;
+
+      MD5_Final((unsigned char *) out,&ctx ) ;
+}
+
+

+ 23 - 0
app/bmc/encryption/MD5_128.h

@@ -0,0 +1,23 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ *****************************************************************
+ *
+ *   Md5_128.c   
+ *   This Code is taken from RFC 1321(RFC1321)
+ *
+ *
+ *****************************************************************/
+
+
+extern void MD5_128(char*    k,int      lk, char*    d,  int      ld, char*    out, int      t );
+

+ 88 - 0
app/bmc/encryption/md2.h

@@ -0,0 +1,88 @@
+/* crypto/md/md2.h */
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_MD2_H
+#define HEADER_MD2_H
+
+#define MD2_INT unsigned int
+
+#define MD2_DIGEST_LENGTH	16
+#define MD2_BLOCK       	16
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+typedef struct MD2state_st
+	{
+	unsigned int num;
+	unsigned char data[MD2_BLOCK];
+	MD2_INT cksm[MD2_BLOCK];
+	MD2_INT state[MD2_BLOCK];
+	} MD2_CTX;
+
+const char *MD2_options(void);
+int MD2_Init(MD2_CTX *c);
+int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len);
+int MD2_Final(unsigned char *md, MD2_CTX *c);
+unsigned char *MD2(const unsigned char *d, size_t n,unsigned char *md);
+#ifdef  __cplusplus
+}
+#endif
+
+#endif

+ 171 - 0
app/bmc/encryption/md2_dgst.c

@@ -0,0 +1,171 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+//#include <openssl/md2.h>
+//#include <openssl/opensslv.h>
+//#include <openssl/crypto.h>
+#include "md2.h"
+
+//const char *MD2_version="MD2" OPENSSL_VERSION_PTEXT;
+
+/* Implemented from RFC1319 The MD2 Message-Digest Algorithm
+ */
+
+#define UCHAR	unsigned char
+
+static void md2_block(MD2_CTX *c, const unsigned char *d);
+/* The magic S table - I have converted it to hex since it is
+ * basically just a random byte string. */
+static const MD2_INT S[256]={
+	0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
+	0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
+	0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C,
+	0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA,
+	0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16,
+	0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12,
+	0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49,
+	0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A,
+	0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F,
+	0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
+	0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27,
+	0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03,
+	0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1,
+	0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6,
+	0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6,
+	0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1,
+	0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20,
+	0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02,
+	0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6,
+	0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
+	0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A,
+	0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26,
+	0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09,
+	0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52,
+	0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA,
+	0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A,
+	0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D,
+	0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39,
+	0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4,
+	0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
+	0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A,
+	0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14,
+	};
+
+const char *MD2_options(void)
+	{
+	if (sizeof(MD2_INT) == 1)
+		return("md2(char)");
+	else
+		return("md2(int)");
+	}
+
+int MD2_Init(MD2_CTX *c)
+	{
+	c->num=0;
+	memset(c->state,0,sizeof c->state);
+	memset(c->cksm,0,sizeof c->cksm);
+	memset(c->data,0,sizeof c->data);
+	return 1;
+	}
+
+int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len)
+	{
+	register UCHAR *p;
+
+	if (len == 0) return 1;
+
+	p=c->data;
+	if (c->num != 0)
+		{
+		if ((c->num+len) >= MD2_BLOCK)
+			{
+			memcpy(&(p[c->num]),data,MD2_BLOCK-c->num);
+			md2_block(c,c->data);
+			data+=(MD2_BLOCK - c->num);
+			len-=(MD2_BLOCK - c->num);
+			c->num=0;
+			/* drop through and do the rest */
+			}
+		else
+			{
+			memcpy(&(p[c->num]),data,len);
+			/* data+=len; */
+			c->num+=(int)len;
+			return 1;
+			}
+		}
+	/* we now can process the input data in blocks of MD2_BLOCK
+	 * chars and save the leftovers to c->data. */
+	while (len >= MD2_BLOCK)
+		{
+		md2_block(c,data);
+		data+=MD2_BLOCK;
+		len-=MD2_BLOCK;
+		}
+	memcpy(p,data,len);
+	c->num=(int)len;
+	return 1;
+	}
+
+static void md2_block(MD2_CTX *c, const unsigned char *d)
+	{
+	register MD2_INT t,*sp1,*sp2;
+	register int i,j;
+	MD2_INT state[48];
+
+	sp1=c->state;
+	sp2=c->cksm;
+	j=sp2[MD2_BLOCK-1];
+	for (i=0; i<16; i++)
+		{
+		state[i]=sp1[i];
+		state[i+16]=t=d[i];
+		state[i+32]=(t^sp1[i]);
+		j=sp2[i]^=S[t^j];
+		}
+	t=0;
+	for (i=0; i<18; i++)
+		{
+		for (j=0; j<48; j+=8)
+			{
+			t= state[j+ 0]^=S[t];
+			t= state[j+ 1]^=S[t];
+			t= state[j+ 2]^=S[t];
+			t= state[j+ 3]^=S[t];
+			t= state[j+ 4]^=S[t];
+			t= state[j+ 5]^=S[t];
+			t= state[j+ 6]^=S[t];
+			t= state[j+ 7]^=S[t];
+			}
+		t=(t+i)&0xff;
+		}
+	memcpy(sp1,state,16*sizeof(MD2_INT));
+	//OPENSSL_cleanse(state,48*sizeof(MD2_INT));
+	}
+
+int MD2_Final(unsigned char *md, MD2_CTX *c)
+	{
+	int i,v;
+	register UCHAR *cp;
+	register MD2_INT *p1,*p2;
+
+	cp=c->data;
+	p1=c->state;
+	p2=c->cksm;
+	v=MD2_BLOCK-c->num;
+	for (i=c->num; i<MD2_BLOCK; i++)
+		cp[i]=(UCHAR)v;
+
+	md2_block(c,cp);
+
+	for (i=0; i<MD2_BLOCK; i++)
+		cp[i]=(UCHAR)p2[i];
+	md2_block(c,cp);
+
+	for (i=0; i<16; i++)
+		md[i]=(UCHAR)(p1[i]&0xff);
+	memset((char *)&c,0,sizeof(c));
+	return 1;
+	}
+

+ 59 - 0
app/bmc/encryption/md5.h

@@ -0,0 +1,59 @@
+/* MD5.H - header file for MD5C.C
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.  
+                                                                    
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.  
+                                                                    
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.  
+ */
+
+#ifndef _MD5_H_
+#define _MD5_H_ 1
+
+#include <stdint.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef UINT4
+#define UINT4 unsigned int
+#endif
+
+#ifndef POINTER
+#define POINTER unsigned char *
+#endif
+/* MD5 context. */
+typedef struct {
+  UINT4 state[4];                                   /* state (ABCD) */
+  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
+  unsigned char buffer[64];                         /* input buffer */
+} MD5_CTX;
+
+void MD5_Init (MD5_CTX *context);
+void MD5_Update (MD5_CTX * context, unsigned char * input, unsigned int inputLen);
+void MD5_Final (unsigned char digest[16], MD5_CTX *context);
+unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* _MD5_H_ */

+ 311 - 0
app/bmc/encryption/md5c.c

@@ -0,0 +1,311 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.  
+                                                                    
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.  
+                                                                    
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.  
+ */
+
+#include "md5.h"
+
+/* Constants for MD5Transform routine.
+ */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+static void MD5Transform (UINT4 state[4], unsigned char block[64]);
+static void Encode (unsigned char *output, UINT4 *input, unsigned int len);
+static void Decode (UINT4 *output, unsigned char *input, unsigned int len);
+static void MD5_memcpy (unsigned char *output, unsigned char *input, unsigned int len);
+static void MD5_memset (unsigned char *output, int value, unsigned int len);
+
+static unsigned char PADDING[64] = {
+  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions.
+ */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits.
+ */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+   Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+    (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+#define GG(a, b, c, d, x, s, ac) { \
+    (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+#define HH(a, b, c, d, x, s, ac) { \
+    (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+#define II(a, b, c, d, x, s, ac) { \
+    (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+ */
+void MD5_Init (MD5_CTX *context)
+{
+  context->count[0] = context->count[1] = 0;
+
+  /* Load magic initialization constants.
+   */
+  context->state[0] = 0x67452301;
+  context->state[1] = 0xefcdab89;
+  context->state[2] = 0x98badcfe;
+  context->state[3] = 0x10325476;
+}
+
+/* MD5 block update operation. Continues an MD5 message-digest
+     operation, processing another message block, and updating the
+     context.
+ */
+void MD5_Update (MD5_CTX * context, unsigned char * input, unsigned int inputLen)
+{
+  unsigned int i, index, partLen;
+
+  /* Compute number of bytes mod 64 */
+  index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+  /* Update number of bits */
+  if ((context->count[0] += ((UINT4)inputLen << 3))
+      < ((UINT4)inputLen << 3))
+    context->count[1]++;
+  context->count[1] += ((UINT4)inputLen >> 29);
+  
+  partLen = 64 - index;
+  
+  /* Transform as many times as possible.
+   */
+  if (inputLen >= partLen) {
+    MD5_memcpy
+      ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+    MD5Transform (context->state, context->buffer);
+  
+    for (i = partLen; i + 63 < inputLen; i += 64)
+      MD5Transform (context->state, &input[i]);
+    
+    index = 0;
+  }
+  else
+    i = 0;
+  
+  /* Buffer remaining input */
+  MD5_memcpy 
+    ((POINTER)&context->buffer[index], (POINTER)&input[i],
+     inputLen-i);
+}
+
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+     the message digest and zeroizing the context.
+ */
+void MD5_Final (unsigned char digest[16], MD5_CTX *context)
+{
+  unsigned char bits[8];
+  unsigned int index, padLen;
+
+  /* Save number of bits */
+  Encode (bits, context->count, 8);
+
+  /* Pad out to 56 mod 64.
+   */
+  index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+  padLen = (index < 56) ? (56 - index) : (120 - index);
+  MD5_Update (context, PADDING, padLen);
+  
+  /* Append length (before padding) */
+  MD5_Update (context, bits, 8);
+
+  /* Store state in digest */
+  Encode (digest, context->state, 16);
+  
+  /* Zeroize sensitive information.
+   */
+  MD5_memset ((POINTER)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block.
+ */
+static void MD5Transform (UINT4 state[4], unsigned char block[64])
+{
+  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+  
+  Decode (x, block, 64);
+
+  /* Round 1 */
+  FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+  FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+  FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+  FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+  FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+  FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+  FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+  FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+  FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+  FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+  FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+  FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+  FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+  FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+  FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+  FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+  /* Round 2 */
+  GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+  GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+  GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+  GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+  GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+  GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
+  GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+  GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+  GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+  GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+  GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+  GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+  GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+  GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+  GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+  GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+  /* Round 3 */
+  HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+  HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+  HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+  HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+  HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+  HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+  HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+  HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+  HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+  HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+  HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+  HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
+  HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+  HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+  HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+  HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+  /* Round 4 */
+  II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+  II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+  II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+  II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+  II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+  II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+  II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+  II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+  II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+  II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+  II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+  II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+  II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+  II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+  II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+  II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+  state[0] += a;
+  state[1] += b;
+  state[2] += c;
+  state[3] += d;
+  
+  /* Zeroize sensitive information.
+   */
+  MD5_memset ((POINTER)x, 0, sizeof (x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+     a multiple of 4.
+ */
+static void Encode (unsigned char *output, UINT4 *input, unsigned int len)
+{
+  unsigned int i, j;
+
+  for (i = 0, j = 0; j < len; i++, j += 4) {
+    output[j] = (unsigned char)(input[i] & 0xff);
+    output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+    output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+    output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+  }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+     a multiple of 4.
+ */
+static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
+{
+  unsigned int i, j;
+
+  for (i = 0, j = 0; j < len; i++, j += 4)
+    output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
+      (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+}
+
+/* Note: Replace "for loop" with standard memcpy if possible.
+ */
+static void MD5_memcpy (unsigned char *output, unsigned char *input, unsigned int len)
+{
+  unsigned int i;
+  
+  for (i = 0; i < len; i++)
+    output[i] = input[i];
+}
+
+/* Note: Replace "for loop" with standard memset if possible.
+ */
+static void MD5_memset (unsigned char *output, int value, unsigned int len)
+{
+  unsigned int i;
+  
+  for (i = 0; i < len; i++)
+    ((char *)output)[i] = (char)value;
+}

+ 270 - 0
app/bmc/encryption/sha1.c

@@ -0,0 +1,270 @@
+// /*
+//  ---------------------------------------------------------------------------
+//  Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
+//  All rights reserved.
+
+//  LICENSE TERMS
+
+//  The free distribution and use of this software in both source and binary
+//  form is allowed (with or without changes) provided that:
+
+//    1. distributions of this source code include the above copyright
+//       notice, this list of conditions and the following disclaimer;
+
+//    2. distributions in binary form include the above copyright
+//       notice, this list of conditions and the following disclaimer
+//       in the documentation and/or other associated materials;
+
+//    3. the copyright holder's name is not used to endorse products
+//       built using this software without specific written permission.
+
+//  ALTERNATIVELY, provided that this notice is retained in full, this product
+//  may be distributed under the terms of the GNU General Public License (GPL),
+//  in which case the provisions of the GPL apply INSTEAD OF those given above.
+
+//  DISCLAIMER
+
+//  This software is provided 'as is' with no explicit or implied warranties
+//  in respect of its properties, including, but not limited to, correctness
+//  and/or fitness for purpose.
+//  ---------------------------------------------------------------------------
+//  Issue Date: 24/01/2003
+
+//  This is a byte oriented version of SHA1 that operates on arrays of bytes
+//  stored in memory.
+// */
+// #include "com_BmcType.h"
+// #include "sha1.h"
+// #include "memory.h"
+// #include "Platform.h"
+// #include "coreTypes.h"
+// /*
+//     To obtain the highest speed on processors with 32-bit words, this code
+//     needs to determine the order in which bytes are packed into such words.
+//     The following block of code is an attempt to capture the most obvious
+//     ways in which various environemnts specify their endian definitions.
+//     It may well fail, in which case the definitions will need to be set by
+//     editing at the points marked **** EDIT HERE IF NECESSARY **** below.
+// */
+
+// #define SHA_LITTLE_ENDIAN	1
+// #define SHA_BIG_ENDIAN		2
+
+// #if IS_PLATFORM_X86() || IS_PLATFORM_ARM() || IS_PLATFORM_SH()
+// #define PLATFORM_BYTE_ORDER		SHA_LITTLE_ENDIAN	
+// #else
+// #define PLATFORM_BYTE_ORDER		SHA_BIG_ENDIAN	
+// #endif
+
+// #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n)))
+
+// #if (PLATFORM_BYTE_ORDER == SHA_BIG_ENDIAN)
+// #define swap_b32(x) (x)
+// #elif defined(bswap_32)
+// #define swap_b32(x) bswap_32(x)
+// #else
+// #define swap_b32(x) ((rotl32((x), 8) & 0x00ff00ff) | (rotl32((x), 24) & 0xff00ff00))
+// #endif
+
+// #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
+
+// /* reverse byte order in 32-bit words       */
+
+// #define ch(x,y,z)       (((x) & (y)) ^ (~(x) & (z)))
+// #define parity(x,y,z)   ((x) ^ (y) ^ (z))
+// #define maj(x,y,z)      (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+// /* A normal version as set out in the FIPS  */
+
+// #define rnd(f,k)    \
+//     t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
+//     e = d; d = c; c = rotl32(b, 30); b = t
+
+// #if (PLATFORM_BYTE_ORDER == SHA_LITTLE_ENDIAN)
+// static  uint32  mask[4] =
+//     {   0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff };
+// static  uint32  bits[4] =
+//     {   0x00000080, 0x00008000, 0x00800000, 0x80000000 };
+// #else
+// static  uint32  mask[4] =
+//     {   0x00000000, 0xff000000, 0xffff0000, 0xffffff00 };
+// static  uint32  bits[4] =
+//     {   0x80000000, 0x00800000, 0x00008000, 0x00000080 };
+// #endif
+
+
+// /*----------------------------------------
+//  * sha1_compile
+//  *----------------------------------------*/
+// void 
+// sha1_compile ( Sha1_Ctx_T* pctx)
+// {   
+// 	int i;
+// 	uint32    w [80], a, b, c, d, e, t;
+
+//     /* note that words are compiled from the buffer into 32-bit */
+//     /* words in big-endian order so an order reversal is needed */
+//     /* here on little endian machines                           */
+//     for (i = 0; i < SHA1_BLOCK_SIZE / 4; ++i)
+// 	{
+//         w [i] = swap_b32 (pctx->wbuf [i]);
+// 	}
+
+//     for (i = SHA1_BLOCK_SIZE / 4; i < 80; ++i)
+// 	{
+//         w[i] = rotl32(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
+// 	}
+
+//     a = pctx->hash [0];
+//     b = pctx->hash [1];
+//     c = pctx->hash [2];
+//     d = pctx->hash [3];
+//     e = pctx->hash [4];
+
+//     for (i = 0; i < 20; ++i)
+//     {
+//         rnd (ch, 0x5a827999);
+//     }
+
+//     for (i = 20; i < 40; ++i)
+//     {
+//         rnd (parity, 0x6ed9eba1);
+//     }
+
+//     for (i = 40; i < 60; ++i)
+//     {
+//         rnd (maj, 0x8f1bbcdc);
+//     }
+
+//     for (i = 60; i < 80; ++i)
+//     {
+//         rnd (parity, 0xca62c1d6);
+//     }
+
+//     pctx->hash [0] += a;
+//     pctx->hash [1] += b;
+//     pctx->hash [2] += c;
+//     pctx->hash [3] += d;
+//     pctx->hash [4] += e;
+// }
+
+// /*----------------------------------------
+//  * sha1_begin
+//  *----------------------------------------*/
+// void 
+// sha1_begin ( Sha1_Ctx_T* pctx)
+// {
+//     pctx->count [0] = pctx->count [1] = 0;
+//     pctx->hash [0]  = 0x67452301;
+//     pctx->hash [1]  = 0xefcdab89;
+//     pctx->hash [2]  = 0x98badcfe;
+//     pctx->hash [3]  = 0x10325476;
+//     pctx->hash [4]  = 0xc3d2e1f0;
+// }
+
+// /*----------------------------------------
+//  * sha1_hash
+//  *----------------------------------------*/
+// void 
+// sha1_hash ( INT8U* pdata, INT16U len,  Sha1_Ctx_T* pctx)
+// {
+// 	/* SHA1 hash data in an array of bytes into hash buffer and */
+// 	/* call the hash_compile function as required.              */
+// 	uint32 pos = (uint32)(pctx->count[0] & SHA1_MASK),
+//              space = SHA1_BLOCK_SIZE - pos;
+//      INT8U *sp = pdata;
+ 
+//     if ((pctx->count[0] += len) < len)  { ++(pctx->count[1]); }
+
+//     while (len >= space)     /* tranfer whole blocks if possible  */
+//     {
+//         memcpy ((( INT8U*)pctx->wbuf) + pos, sp, space);
+//         sp += space; len -= (INT16U)space; space = SHA1_BLOCK_SIZE; pos = 0;
+//         sha1_compile (pctx);
+
+//     }
+
+// 	//dispscont (pctx);
+
+//     /*lint -e{803} conceivable data overrun */
+//     /* there are two cases: the above while loop entered or not */
+//     /* entered. If not entered, 'space = SHA1_BLOCK_SIZE - pos' */
+//     /* and 'len < space' so that 'len + pos < SHA1_BLOCK_SIZE'. */
+//     /* If entered, 'pos = 0', 'space = SHA1_BLOCK_SIZE' and     */
+//     /* 'len < space' so that 'pos + len < SHA1_BLOCK_SIZE'. In  */
+//     /* both cases, therefore, the memory copy is in the buffer  */
+
+//     memcpy ((( INT8U*)pctx->wbuf) + pos, sp, len);
+
+// }
+
+
+// /*----------------------------------------
+//  * sha1_end
+//  *----------------------------------------*/
+// void 
+// sha1_end ( INT8U* phval,  Sha1_Ctx_T* pctx)
+// {
+// 	uint32    i = (uint32)(pctx->count [0] & SHA1_MASK);
+
+// 	/* SHA1 final padding and digest calculation  */
+
+//     /* mask out the rest of any partial 32-bit word and then set    */
+//     /* the next byte to 0x80. On big-endian machines any bytes in   */
+//     /* the buffer will be at the top end of 32 bit words, on little */
+//     /* endian machines they will be at the bottom. Hence the AND    */
+//     /* and OR masks above are reversed for little endian systems    */
+//     /* Note that we can always add the first padding byte at this   */
+//     /* point because the buffer always has at least one empty slot  */
+//     pctx->wbuf [(INT16U)(i >> 2)] = (pctx->wbuf [(INT16U)(i >> 2)] & mask [(INT16U)(i & 3)]) | bits [(INT16U)(i & 3)];
+
+
+//     /* we need 9 or more empty positions, one for the padding byte  */
+//     /* (above) and eight for the length count.  If there is not     */
+//     /* enough space pad and empty the buffer                        */
+//     if (i > SHA1_BLOCK_SIZE - 9)
+//     {
+//         if (i < 60) { pctx->wbuf [15] = 0; }
+//         sha1_compile (pctx);
+//         i = 0;
+//     }
+//     else    /* compute a word index for the empty buffer positions  */
+// 	{
+//         i = (i >> 2) + 1;
+// 	}
+
+// 	/* and zero pad all but last two positions        */
+//     while (i < 14)  {  pctx->wbuf[(INT16U)(i++)] = 0; }
+
+
+//     /* assemble the eight byte counter in in big-endian format      */
+//     pctx->wbuf [14] = swap_b32 ((pctx->count[1] << 3) | (pctx->count[0] >> 29));
+//     pctx->wbuf [15] = swap_b32 (pctx->count[0] << 3);
+
+//     sha1_compile (pctx);
+
+
+//     /* extract the hash value as bytes in case the hash buffer is   */
+//     /* misaligned for 32-bit words                                  */
+//     /*lint -e{504} unusual shift operation (unusually formed right argument) */
+//     for (i = 0; i < SHA1_DIGEST_SIZE; ++i)
+// 	{
+//         phval [(INT16U)(i)] = (INT8U)(pctx->hash [(INT16U)(i >> 2)] >> (8 * (~i & 3)));
+// 	}
+
+// }
+
+// /*----------------------------------------
+//  * sha1
+//  *----------------------------------------*/
+// void 
+// sha1 ( INT8U* phval,  INT8U* pdata, INT16U len)
+// {
+// 	Sha1_Ctx_T    cx;
+
+//     sha1_begin (&cx); 
+// 	sha1_hash (pdata, len, &cx); 
+// 	sha1_end (phval, &cx);
+// }
+
+

+ 73 - 0
app/bmc/encryption/sha1.h

@@ -0,0 +1,73 @@
+
+//  ---------------------------------------------------------------------------
+//  Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
+//  All rights reserved.
+
+//  LICENSE TERMS
+
+//  The free distribution and use of this software in both source and binary
+//  form is allowed (with or without changes) provided that:
+
+//    1. distributions of this source code include the above copyright
+//       notice, this list of conditions and the following disclaimer;
+
+//    2. distributions in binary form include the above copyright
+//       notice, this list of conditions and the following disclaimer
+//       in the documentation and/or other associated materials;
+
+//    3. the copyright holder's name is not used to endorse products
+//       built using this software without specific written permission.
+
+//  ALTERNATIVELY, provided that this notice is retained in full, this product
+//  may be distributed under the terms of the GNU General Public License (GPL),
+//  in which case the provisions of the GPL apply INSTEAD OF those given above.
+
+//  DISCLAIMER
+
+//  This software is provided 'as is' with no explicit or implied warranties
+//  in respect of its properties, including, but not limited to, correctness
+//  and/or fitness for purpose.
+//  ---------------------------------------------------------------------------
+//  Issue Date: 24/01/2003
+
+//  This file contains the definitions needed for SHA1
+
+
+// #ifndef _SHA1_H
+// #define _SHA1_H
+// #include "Types.h"
+// #include "coreTypes.h"
+
+
+// #define SHA1_BLOCK_SIZE  64
+// #define SHA1_DIGEST_SIZE 20
+
+// /* type to hold the SHA256 context  */
+
+// #ifdef __GNUC__
+// #define PACK __attribute__ ((packed))
+// #else
+// #define PACK
+// #pragma pack( 1 )
+// #endif
+
+// typedef struct
+// {
+// 	uint32 count [2];
+//     uint32 hash [5];
+//     uint32 wbuf [16];
+
+// } PACK Sha1_Ctx_T;
+
+// void sha1_compile ( Sha1_Ctx_T* pctx);
+// void sha1_begin ( Sha1_Ctx_T* pctx);
+// void sha1_hash ( INT8U* pdata, INT16U len, Sha1_Ctx_T* pctx);
+// void sha1_end ( INT8U* phval, Sha1_Ctx_T* pctx);
+// void sha1 ( INT8U* phval, INT8U* pdata, INT16U len);
+
+// #undef PACK
+// #ifndef __GNUC__
+// #pragma pack()
+// #endif
+
+// #endif

+ 824 - 0
app/bmc/encryption/sha2.c

@@ -0,0 +1,824 @@
+// /*
+//  * FIPS 180-2 SHA-224/256/384/512 implementation
+//  * Last update: 02/02/2007
+//  * Issue date:  04/30/2005
+//  *
+//  * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
+//  * All rights reserved.
+//  *
+//  * Redistribution and use in source and binary forms, with or without
+//  * modification, are permitted provided that the following conditions
+//  * are met:
+//  * 1. Redistributions of source code must retain the above copyright
+//  *    notice, this list of conditions and the following disclaimer.
+//  * 2. 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.
+//  * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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.
+//  */
+
+// #if 0
+// #define UNROLL_LOOPS /* Enable loops unrolling */
+// #endif
+
+// #include <string.h>
+
+// #include "sha2.h"
+
+// #define SHFR(x, n)    (x >> n)
+// #define ROTR(x, n)   ((x >> n) | (x << ((sizeof(x) << 3) - n)))
+// #define ROTL(x, n)   ((x << n) | (x >> ((sizeof(x) << 3) - n)))
+// #define CH(x, y, z)  ((x & y) ^ (~x & z))
+// #define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
+
+// #define SHA256_F1(x) (ROTR(x,  2) ^ ROTR(x, 13) ^ ROTR(x, 22))
+// #define SHA256_F2(x) (ROTR(x,  6) ^ ROTR(x, 11) ^ ROTR(x, 25))
+// #define SHA256_F3(x) (ROTR(x,  7) ^ ROTR(x, 18) ^ SHFR(x,  3))
+// #define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10))
+
+// #define SHA512_F1(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
+// #define SHA512_F2(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
+// #define SHA512_F3(x) (ROTR(x,  1) ^ ROTR(x,  8) ^ SHFR(x,  7))
+// #define SHA512_F4(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHFR(x,  6))
+
+// #define UNPACK32(x, str)                      \
+// {                                             \
+//     *((str) + 3) = (uint8) ((x)      );       \
+//     *((str) + 2) = (uint8) ((x) >>  8);       \
+//     *((str) + 1) = (uint8) ((x) >> 16);       \
+//     *((str) + 0) = (uint8) ((x) >> 24);       \
+// }
+
+// #define PACK32(str, x)                        \
+// {                                             \
+//     *(x) =   ((uint32) *((str) + 3)      )    \
+//            | ((uint32) *((str) + 2) <<  8)    \
+//            | ((uint32) *((str) + 1) << 16)    \
+//            | ((uint32) *((str) + 0) << 24);   \
+// }
+
+// #define UNPACK64(x, str)                      \
+// {                                             \
+//     *((str) + 7) = (uint8) ((x)      );       \
+//     *((str) + 6) = (uint8) ((x) >>  8);       \
+//     *((str) + 5) = (uint8) ((x) >> 16);       \
+//     *((str) + 4) = (uint8) ((x) >> 24);       \
+//     *((str) + 3) = (uint8) ((x) >> 32);       \
+//     *((str) + 2) = (uint8) ((x) >> 40);       \
+//     *((str) + 1) = (uint8) ((x) >> 48);       \
+//     *((str) + 0) = (uint8) ((x) >> 56);       \
+// }
+
+// #define PACK64(str, x)                        \
+// {                                             \
+//     *(x) =   ((uint64) *((str) + 7)      )    \
+//            | ((uint64) *((str) + 6) <<  8)    \
+//            | ((uint64) *((str) + 5) << 16)    \
+//            | ((uint64) *((str) + 4) << 24)    \
+//            | ((uint64) *((str) + 3) << 32)    \
+//            | ((uint64) *((str) + 2) << 40)    \
+//            | ((uint64) *((str) + 1) << 48)    \
+//            | ((uint64) *((str) + 0) << 56);   \
+// }
+
+// /* Macros used for loops unrolling */
+
+// #define SHA256_SCR(i)                         \
+// {                                             \
+//     w[i] =  SHA256_F4(w[i -  2]) + w[i -  7]  \
+//           + SHA256_F3(w[i - 15]) + w[i - 16]; \
+// }
+
+// #define SHA512_SCR(i)                         \
+// {                                             \
+//     w[i] =  SHA512_F4(w[i -  2]) + w[i -  7]  \
+//           + SHA512_F3(w[i - 15]) + w[i - 16]; \
+// }
+
+// #define SHA256_EXP(a, b, c, d, e, f, g, h, j)               \
+// {                                                           \
+//     t1 = wv[h] + SHA256_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \
+//          + sha256_k[j] + w[j];                              \
+//     t2 = SHA256_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]);       \
+//     wv[d] += t1;                                            \
+//     wv[h] = t1 + t2;                                        \
+// }
+
+// #define SHA512_EXP(a, b, c, d, e, f, g ,h, j)               \
+// {                                                           \
+//     t1 = wv[h] + SHA512_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \
+//          + sha512_k[j] + w[j];                              \
+//     t2 = SHA512_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]);       \
+//     wv[d] += t1;                                            \
+//     wv[h] = t1 + t2;                                        \
+// }
+
+// uint32 sha224_h0[8] =
+//             {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
+//              0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4};
+
+// uint32 sha256_h0[8] =
+//             {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
+//              0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
+
+// uint64 sha384_h0[8] =
+//             {0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL,
+//              0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL,
+//              0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL,
+//              0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL};
+
+// uint64 sha512_h0[8] =
+//             {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
+//              0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
+//              0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
+//              0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};
+
+// uint32 sha256_k[64] =
+//             {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+//              0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+//              0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+//              0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+//              0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+//              0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+//              0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+//              0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+//              0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+//              0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+//              0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+//              0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+//              0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+//              0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+//              0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+//              0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
+
+// uint64 sha512_k[80] =
+//             {0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
+//              0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
+//              0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
+//              0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
+//              0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
+//              0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
+//              0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
+//              0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
+//              0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
+//              0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
+//              0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
+//              0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
+//              0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
+//              0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
+//              0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
+//              0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
+//              0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
+//              0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
+//              0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
+//              0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
+//              0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
+//              0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
+//              0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
+//              0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
+//              0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
+//              0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
+//              0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
+//              0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
+//              0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
+//              0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
+//              0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
+//              0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
+//              0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
+//              0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
+//              0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
+//              0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
+//              0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
+//              0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
+//              0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
+//              0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL};
+
+// /* SHA-256 functions */
+
+// void sha256_transf(sha256_ctx *ctx, const unsigned char *message,
+//                    unsigned int block_nb)
+// {
+//     uint32 w[64];
+//     uint32 wv[8];
+//     uint32 t1, t2;
+//     const unsigned char *sub_block;
+//     int i;
+
+// #ifndef UNROLL_LOOPS
+//     int j;
+// #endif
+
+//     for (i = 0; i < (int) block_nb; i++) {
+//         sub_block = message + (i << 6);
+
+// #ifndef UNROLL_LOOPS
+//         for (j = 0; j < 16; j++) {
+//             PACK32(&sub_block[j << 2], &w[j]);
+//         }
+
+//         for (j = 16; j < 64; j++) {
+//             SHA256_SCR(j);
+//         }
+
+//         for (j = 0; j < 8; j++) {
+//             wv[j] = ctx->h[j];
+//         }
+
+//         for (j = 0; j < 64; j++) {
+//             t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6])
+//                 + sha256_k[j] + w[j];
+//             t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]);
+//             wv[7] = wv[6];
+//             wv[6] = wv[5];
+//             wv[5] = wv[4];
+//             wv[4] = wv[3] + t1;
+//             wv[3] = wv[2];
+//             wv[2] = wv[1];
+//             wv[1] = wv[0];
+//             wv[0] = t1 + t2;
+//         }
+
+//         for (j = 0; j < 8; j++) {
+//             ctx->h[j] += wv[j];
+//         }
+// #else
+//         PACK32(&sub_block[ 0], &w[ 0]); PACK32(&sub_block[ 4], &w[ 1]);
+//         PACK32(&sub_block[ 8], &w[ 2]); PACK32(&sub_block[12], &w[ 3]);
+//         PACK32(&sub_block[16], &w[ 4]); PACK32(&sub_block[20], &w[ 5]);
+//         PACK32(&sub_block[24], &w[ 6]); PACK32(&sub_block[28], &w[ 7]);
+//         PACK32(&sub_block[32], &w[ 8]); PACK32(&sub_block[36], &w[ 9]);
+//         PACK32(&sub_block[40], &w[10]); PACK32(&sub_block[44], &w[11]);
+//         PACK32(&sub_block[48], &w[12]); PACK32(&sub_block[52], &w[13]);
+//         PACK32(&sub_block[56], &w[14]); PACK32(&sub_block[60], &w[15]);
+
+//         SHA256_SCR(16); SHA256_SCR(17); SHA256_SCR(18); SHA256_SCR(19);
+//         SHA256_SCR(20); SHA256_SCR(21); SHA256_SCR(22); SHA256_SCR(23);
+//         SHA256_SCR(24); SHA256_SCR(25); SHA256_SCR(26); SHA256_SCR(27);
+//         SHA256_SCR(28); SHA256_SCR(29); SHA256_SCR(30); SHA256_SCR(31);
+//         SHA256_SCR(32); SHA256_SCR(33); SHA256_SCR(34); SHA256_SCR(35);
+//         SHA256_SCR(36); SHA256_SCR(37); SHA256_SCR(38); SHA256_SCR(39);
+//         SHA256_SCR(40); SHA256_SCR(41); SHA256_SCR(42); SHA256_SCR(43);
+//         SHA256_SCR(44); SHA256_SCR(45); SHA256_SCR(46); SHA256_SCR(47);
+//         SHA256_SCR(48); SHA256_SCR(49); SHA256_SCR(50); SHA256_SCR(51);
+//         SHA256_SCR(52); SHA256_SCR(53); SHA256_SCR(54); SHA256_SCR(55);
+//         SHA256_SCR(56); SHA256_SCR(57); SHA256_SCR(58); SHA256_SCR(59);
+//         SHA256_SCR(60); SHA256_SCR(61); SHA256_SCR(62); SHA256_SCR(63);
+
+//         wv[0] = ctx->h[0]; wv[1] = ctx->h[1];
+//         wv[2] = ctx->h[2]; wv[3] = ctx->h[3];
+//         wv[4] = ctx->h[4]; wv[5] = ctx->h[5];
+//         wv[6] = ctx->h[6]; wv[7] = ctx->h[7];
+
+//         SHA256_EXP(0,1,2,3,4,5,6,7, 0); SHA256_EXP(7,0,1,2,3,4,5,6, 1);
+//         SHA256_EXP(6,7,0,1,2,3,4,5, 2); SHA256_EXP(5,6,7,0,1,2,3,4, 3);
+//         SHA256_EXP(4,5,6,7,0,1,2,3, 4); SHA256_EXP(3,4,5,6,7,0,1,2, 5);
+//         SHA256_EXP(2,3,4,5,6,7,0,1, 6); SHA256_EXP(1,2,3,4,5,6,7,0, 7);
+//         SHA256_EXP(0,1,2,3,4,5,6,7, 8); SHA256_EXP(7,0,1,2,3,4,5,6, 9);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,10); SHA256_EXP(5,6,7,0,1,2,3,4,11);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,12); SHA256_EXP(3,4,5,6,7,0,1,2,13);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,14); SHA256_EXP(1,2,3,4,5,6,7,0,15);
+//         SHA256_EXP(0,1,2,3,4,5,6,7,16); SHA256_EXP(7,0,1,2,3,4,5,6,17);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,18); SHA256_EXP(5,6,7,0,1,2,3,4,19);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,20); SHA256_EXP(3,4,5,6,7,0,1,2,21);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,22); SHA256_EXP(1,2,3,4,5,6,7,0,23);
+//         SHA256_EXP(0,1,2,3,4,5,6,7,24); SHA256_EXP(7,0,1,2,3,4,5,6,25);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,26); SHA256_EXP(5,6,7,0,1,2,3,4,27);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,28); SHA256_EXP(3,4,5,6,7,0,1,2,29);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,30); SHA256_EXP(1,2,3,4,5,6,7,0,31);
+//         SHA256_EXP(0,1,2,3,4,5,6,7,32); SHA256_EXP(7,0,1,2,3,4,5,6,33);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,34); SHA256_EXP(5,6,7,0,1,2,3,4,35);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,36); SHA256_EXP(3,4,5,6,7,0,1,2,37);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,38); SHA256_EXP(1,2,3,4,5,6,7,0,39);
+//         SHA256_EXP(0,1,2,3,4,5,6,7,40); SHA256_EXP(7,0,1,2,3,4,5,6,41);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,42); SHA256_EXP(5,6,7,0,1,2,3,4,43);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,44); SHA256_EXP(3,4,5,6,7,0,1,2,45);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,46); SHA256_EXP(1,2,3,4,5,6,7,0,47);
+//         SHA256_EXP(0,1,2,3,4,5,6,7,48); SHA256_EXP(7,0,1,2,3,4,5,6,49);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,50); SHA256_EXP(5,6,7,0,1,2,3,4,51);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,52); SHA256_EXP(3,4,5,6,7,0,1,2,53);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,54); SHA256_EXP(1,2,3,4,5,6,7,0,55);
+//         SHA256_EXP(0,1,2,3,4,5,6,7,56); SHA256_EXP(7,0,1,2,3,4,5,6,57);
+//         SHA256_EXP(6,7,0,1,2,3,4,5,58); SHA256_EXP(5,6,7,0,1,2,3,4,59);
+//         SHA256_EXP(4,5,6,7,0,1,2,3,60); SHA256_EXP(3,4,5,6,7,0,1,2,61);
+//         SHA256_EXP(2,3,4,5,6,7,0,1,62); SHA256_EXP(1,2,3,4,5,6,7,0,63);
+
+//         ctx->h[0] += wv[0]; ctx->h[1] += wv[1];
+//         ctx->h[2] += wv[2]; ctx->h[3] += wv[3];
+//         ctx->h[4] += wv[4]; ctx->h[5] += wv[5];
+//         ctx->h[6] += wv[6]; ctx->h[7] += wv[7];
+// #endif /* !UNROLL_LOOPS */
+//     }
+// }
+
+// void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
+// {
+//     sha256_ctx ctx;
+
+//     sha256_init(&ctx);
+//     sha256_update(&ctx, message, len);
+//     sha256_final(&ctx, digest);
+// }
+
+// void sha256_init(sha256_ctx *ctx)
+// {
+// #ifndef UNROLL_LOOPS
+//     int i;
+//     for (i = 0; i < 8; i++) {
+//         ctx->h[i] = sha256_h0[i];
+//     }
+// #else
+//     ctx->h[0] = sha256_h0[0]; ctx->h[1] = sha256_h0[1];
+//     ctx->h[2] = sha256_h0[2]; ctx->h[3] = sha256_h0[3];
+//     ctx->h[4] = sha256_h0[4]; ctx->h[5] = sha256_h0[5];
+//     ctx->h[6] = sha256_h0[6]; ctx->h[7] = sha256_h0[7];
+// #endif /* !UNROLL_LOOPS */
+
+//     ctx->len = 0;
+//     ctx->tot_len = 0;
+// }
+
+// void sha256_update(sha256_ctx *ctx, const unsigned char *message,
+//                    unsigned int len)
+// {
+//     unsigned int block_nb;
+//     unsigned int new_len, rem_len, tmp_len;
+//     const unsigned char *shifted_message;
+
+//     tmp_len = SHA256_BLOCK_SIZE - ctx->len;
+//     rem_len = len < tmp_len ? len : tmp_len;
+
+//     memcpy(&ctx->block[ctx->len], message, rem_len);
+
+//     if (ctx->len + len < SHA256_BLOCK_SIZE) {
+//         ctx->len += len;
+//         return;
+//     }
+
+//     new_len = len - rem_len;
+//     block_nb = new_len / SHA256_BLOCK_SIZE;
+
+//     shifted_message = message + rem_len;
+
+//     sha256_transf(ctx, ctx->block, 1);
+//     sha256_transf(ctx, shifted_message, block_nb);
+
+//     rem_len = new_len % SHA256_BLOCK_SIZE;
+
+//     memcpy(ctx->block, &shifted_message[block_nb << 6],
+//            rem_len);
+
+//     ctx->len = rem_len;
+//     ctx->tot_len += (block_nb + 1) << 6;
+// }
+
+// void sha256_final(sha256_ctx *ctx, unsigned char *digest)
+// {
+//     unsigned int block_nb;
+//     unsigned int pm_len;
+//     unsigned int len_b;
+
+// #ifndef UNROLL_LOOPS
+//     int i;
+// #endif
+
+//     block_nb = (1 + ((SHA256_BLOCK_SIZE - 9)
+//                      < (ctx->len % SHA256_BLOCK_SIZE)));
+
+//     len_b = (ctx->tot_len + ctx->len) << 3;
+//     pm_len = block_nb << 6;
+
+//     memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
+//     ctx->block[ctx->len] = 0x80;
+//     UNPACK32(len_b, ctx->block + pm_len - 4);
+
+//     sha256_transf(ctx, ctx->block, block_nb);
+
+// #ifndef UNROLL_LOOPS
+//     for (i = 0 ; i < 8; i++) {
+//         UNPACK32(ctx->h[i], &digest[i << 2]);
+//     }
+// #else
+//    UNPACK32(ctx->h[0], &digest[ 0]);
+//    UNPACK32(ctx->h[1], &digest[ 4]);
+//    UNPACK32(ctx->h[2], &digest[ 8]);
+//    UNPACK32(ctx->h[3], &digest[12]);
+//    UNPACK32(ctx->h[4], &digest[16]);
+//    UNPACK32(ctx->h[5], &digest[20]);
+//    UNPACK32(ctx->h[6], &digest[24]);
+//    UNPACK32(ctx->h[7], &digest[28]);
+// #endif /* !UNROLL_LOOPS */
+// }
+
+// /* SHA-512 functions */
+
+// void sha512_transf(sha512_ctx *ctx, const unsigned char *message,
+//                    unsigned int block_nb)
+// {
+//     uint64 w[80];
+//     uint64 wv[8];
+//     uint64 t1, t2;
+//     const unsigned char *sub_block;
+//     int i, j;
+
+//     for (i = 0; i < (int) block_nb; i++) {
+//         sub_block = message + (i << 7);
+
+// #ifndef UNROLL_LOOPS
+//         for (j = 0; j < 16; j++) {
+//             PACK64(&sub_block[j << 3], &w[j]);
+//         }
+
+//         for (j = 16; j < 80; j++) {
+//             SHA512_SCR(j);
+//         }
+
+//         for (j = 0; j < 8; j++) {
+//             wv[j] = ctx->h[j];
+//         }
+
+//         for (j = 0; j < 80; j++) {
+//             t1 = wv[7] + SHA512_F2(wv[4]) + CH(wv[4], wv[5], wv[6])
+//                 + sha512_k[j] + w[j];
+//             t2 = SHA512_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]);
+//             wv[7] = wv[6];
+//             wv[6] = wv[5];
+//             wv[5] = wv[4];
+//             wv[4] = wv[3] + t1;
+//             wv[3] = wv[2];
+//             wv[2] = wv[1];
+//             wv[1] = wv[0];
+//             wv[0] = t1 + t2;
+//         }
+
+//         for (j = 0; j < 8; j++) {
+//             ctx->h[j] += wv[j];
+//         }
+// #else
+//         PACK64(&sub_block[  0], &w[ 0]); PACK64(&sub_block[  8], &w[ 1]);
+//         PACK64(&sub_block[ 16], &w[ 2]); PACK64(&sub_block[ 24], &w[ 3]);
+//         PACK64(&sub_block[ 32], &w[ 4]); PACK64(&sub_block[ 40], &w[ 5]);
+//         PACK64(&sub_block[ 48], &w[ 6]); PACK64(&sub_block[ 56], &w[ 7]);
+//         PACK64(&sub_block[ 64], &w[ 8]); PACK64(&sub_block[ 72], &w[ 9]);
+//         PACK64(&sub_block[ 80], &w[10]); PACK64(&sub_block[ 88], &w[11]);
+//         PACK64(&sub_block[ 96], &w[12]); PACK64(&sub_block[104], &w[13]);
+//         PACK64(&sub_block[112], &w[14]); PACK64(&sub_block[120], &w[15]);
+
+//         SHA512_SCR(16); SHA512_SCR(17); SHA512_SCR(18); SHA512_SCR(19);
+//         SHA512_SCR(20); SHA512_SCR(21); SHA512_SCR(22); SHA512_SCR(23);
+//         SHA512_SCR(24); SHA512_SCR(25); SHA512_SCR(26); SHA512_SCR(27);
+//         SHA512_SCR(28); SHA512_SCR(29); SHA512_SCR(30); SHA512_SCR(31);
+//         SHA512_SCR(32); SHA512_SCR(33); SHA512_SCR(34); SHA512_SCR(35);
+//         SHA512_SCR(36); SHA512_SCR(37); SHA512_SCR(38); SHA512_SCR(39);
+//         SHA512_SCR(40); SHA512_SCR(41); SHA512_SCR(42); SHA512_SCR(43);
+//         SHA512_SCR(44); SHA512_SCR(45); SHA512_SCR(46); SHA512_SCR(47);
+//         SHA512_SCR(48); SHA512_SCR(49); SHA512_SCR(50); SHA512_SCR(51);
+//         SHA512_SCR(52); SHA512_SCR(53); SHA512_SCR(54); SHA512_SCR(55);
+//         SHA512_SCR(56); SHA512_SCR(57); SHA512_SCR(58); SHA512_SCR(59);
+//         SHA512_SCR(60); SHA512_SCR(61); SHA512_SCR(62); SHA512_SCR(63);
+//         SHA512_SCR(64); SHA512_SCR(65); SHA512_SCR(66); SHA512_SCR(67);
+//         SHA512_SCR(68); SHA512_SCR(69); SHA512_SCR(70); SHA512_SCR(71);
+//         SHA512_SCR(72); SHA512_SCR(73); SHA512_SCR(74); SHA512_SCR(75);
+//         SHA512_SCR(76); SHA512_SCR(77); SHA512_SCR(78); SHA512_SCR(79);
+
+//         wv[0] = ctx->h[0]; wv[1] = ctx->h[1];
+//         wv[2] = ctx->h[2]; wv[3] = ctx->h[3];
+//         wv[4] = ctx->h[4]; wv[5] = ctx->h[5];
+//         wv[6] = ctx->h[6]; wv[7] = ctx->h[7];
+
+//         j = 0;
+
+//         do {
+//             SHA512_EXP(0,1,2,3,4,5,6,7,j); j++;
+//             SHA512_EXP(7,0,1,2,3,4,5,6,j); j++;
+//             SHA512_EXP(6,7,0,1,2,3,4,5,j); j++;
+//             SHA512_EXP(5,6,7,0,1,2,3,4,j); j++;
+//             SHA512_EXP(4,5,6,7,0,1,2,3,j); j++;
+//             SHA512_EXP(3,4,5,6,7,0,1,2,j); j++;
+//             SHA512_EXP(2,3,4,5,6,7,0,1,j); j++;
+//             SHA512_EXP(1,2,3,4,5,6,7,0,j); j++;
+//         } while (j < 80);
+
+//         ctx->h[0] += wv[0]; ctx->h[1] += wv[1];
+//         ctx->h[2] += wv[2]; ctx->h[3] += wv[3];
+//         ctx->h[4] += wv[4]; ctx->h[5] += wv[5];
+//         ctx->h[6] += wv[6]; ctx->h[7] += wv[7];
+// #endif /* !UNROLL_LOOPS */
+//     }
+// }
+
+// void sha512(const unsigned char *message, unsigned int len,
+//             unsigned char *digest)
+// {
+//     sha512_ctx ctx;
+
+//     sha512_init(&ctx);
+//     sha512_update(&ctx, message, len);
+//     sha512_final(&ctx, digest);
+// }
+
+// void sha512_init(sha512_ctx *ctx)
+// {
+// #ifndef UNROLL_LOOPS
+//     int i;
+//     for (i = 0; i < 8; i++) {
+//         ctx->h[i] = sha512_h0[i];
+//     }
+// #else
+//     ctx->h[0] = sha512_h0[0]; ctx->h[1] = sha512_h0[1];
+//     ctx->h[2] = sha512_h0[2]; ctx->h[3] = sha512_h0[3];
+//     ctx->h[4] = sha512_h0[4]; ctx->h[5] = sha512_h0[5];
+//     ctx->h[6] = sha512_h0[6]; ctx->h[7] = sha512_h0[7];
+// #endif /* !UNROLL_LOOPS */
+
+//     ctx->len = 0;
+//     ctx->tot_len = 0;
+// }
+
+// void sha512_update(sha512_ctx *ctx, const unsigned char *message,
+//                    unsigned int len)
+// {
+//     unsigned int block_nb;
+//     unsigned int new_len, rem_len, tmp_len;
+//     const unsigned char *shifted_message;
+
+//     tmp_len = SHA512_BLOCK_SIZE - ctx->len;
+//     rem_len = len < tmp_len ? len : tmp_len;
+
+//     memcpy(&ctx->block[ctx->len], message, rem_len);
+
+//     if (ctx->len + len < SHA512_BLOCK_SIZE) {
+//         ctx->len += len;
+//         return;
+//     }
+
+//     new_len = len - rem_len;
+//     block_nb = new_len / SHA512_BLOCK_SIZE;
+
+//     shifted_message = message + rem_len;
+
+//     sha512_transf(ctx, ctx->block, 1);
+//     sha512_transf(ctx, shifted_message, block_nb);
+
+//     rem_len = new_len % SHA512_BLOCK_SIZE;
+
+//     memcpy(ctx->block, &shifted_message[block_nb << 7],
+//            rem_len);
+
+//     ctx->len = rem_len;
+//     ctx->tot_len += (block_nb + 1) << 7;
+// }
+
+// void sha512_final(sha512_ctx *ctx, unsigned char *digest)
+// {
+//     unsigned int block_nb;
+//     unsigned int pm_len;
+//     unsigned int len_b;
+
+// #ifndef UNROLL_LOOPS
+//     int i;
+// #endif
+
+//     block_nb = 1 + ((SHA512_BLOCK_SIZE - 17)
+//                      < (ctx->len % SHA512_BLOCK_SIZE));
+
+//     len_b = (ctx->tot_len + ctx->len) << 3;
+//     pm_len = block_nb << 7;
+
+//     memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
+//     ctx->block[ctx->len] = 0x80;
+//     UNPACK32(len_b, ctx->block + pm_len - 4);
+
+//     sha512_transf(ctx, ctx->block, block_nb);
+
+// #ifndef UNROLL_LOOPS
+//     for (i = 0 ; i < 8; i++) {
+//         UNPACK64(ctx->h[i], &digest[i << 3]);
+//     }
+// #else
+//     UNPACK64(ctx->h[0], &digest[ 0]);
+//     UNPACK64(ctx->h[1], &digest[ 8]);
+//     UNPACK64(ctx->h[2], &digest[16]);
+//     UNPACK64(ctx->h[3], &digest[24]);
+//     UNPACK64(ctx->h[4], &digest[32]);
+//     UNPACK64(ctx->h[5], &digest[40]);
+//     UNPACK64(ctx->h[6], &digest[48]);
+//     UNPACK64(ctx->h[7], &digest[56]);
+// #endif /* !UNROLL_LOOPS */
+// }
+
+// /* SHA-384 functions */
+
+// void sha384(const unsigned char *message, unsigned int len,
+//             unsigned char *digest)
+// {
+//     sha384_ctx ctx;
+
+//     sha384_init(&ctx);
+//     sha384_update(&ctx, message, len);
+//     sha384_final(&ctx, digest);
+// }
+
+// void sha384_init(sha384_ctx *ctx)
+// {
+// #ifndef UNROLL_LOOPS
+//     int i;
+//     for (i = 0; i < 8; i++) {
+//         ctx->h[i] = sha384_h0[i];
+//     }
+// #else
+//     ctx->h[0] = sha384_h0[0]; ctx->h[1] = sha384_h0[1];
+//     ctx->h[2] = sha384_h0[2]; ctx->h[3] = sha384_h0[3];
+//     ctx->h[4] = sha384_h0[4]; ctx->h[5] = sha384_h0[5];
+//     ctx->h[6] = sha384_h0[6]; ctx->h[7] = sha384_h0[7];
+// #endif /* !UNROLL_LOOPS */
+
+//     ctx->len = 0;
+//     ctx->tot_len = 0;
+// }
+
+// void sha384_update(sha384_ctx *ctx, const unsigned char *message,
+//                    unsigned int len)
+// {
+//     unsigned int block_nb;
+//     unsigned int new_len, rem_len, tmp_len;
+//     const unsigned char *shifted_message;
+
+//     tmp_len = SHA384_BLOCK_SIZE - ctx->len;
+//     rem_len = len < tmp_len ? len : tmp_len;
+
+//     memcpy(&ctx->block[ctx->len], message, rem_len);
+
+//     if (ctx->len + len < SHA384_BLOCK_SIZE) {
+//         ctx->len += len;
+//         return;
+//     }
+
+//     new_len = len - rem_len;
+//     block_nb = new_len / SHA384_BLOCK_SIZE;
+
+//     shifted_message = message + rem_len;
+
+//     sha512_transf(ctx, ctx->block, 1);
+//     sha512_transf(ctx, shifted_message, block_nb);
+
+//     rem_len = new_len % SHA384_BLOCK_SIZE;
+
+//     memcpy(ctx->block, &shifted_message[block_nb << 7],
+//            rem_len);
+
+//     ctx->len = rem_len;
+//     ctx->tot_len += (block_nb + 1) << 7;
+// }
+
+// void sha384_final(sha384_ctx *ctx, unsigned char *digest)
+// {
+//     unsigned int block_nb;
+//     unsigned int pm_len;
+//     unsigned int len_b;
+
+// #ifndef UNROLL_LOOPS
+//     int i;
+// #endif
+
+//     block_nb = (1 + ((SHA384_BLOCK_SIZE - 17)
+//                      < (ctx->len % SHA384_BLOCK_SIZE)));
+
+//     len_b = (ctx->tot_len + ctx->len) << 3;
+//     pm_len = block_nb << 7;
+
+//     memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
+//     ctx->block[ctx->len] = 0x80;
+//     UNPACK32(len_b, ctx->block + pm_len - 4);
+
+//     sha512_transf(ctx, ctx->block, block_nb);
+
+// #ifndef UNROLL_LOOPS
+//     for (i = 0 ; i < 6; i++) {
+//         UNPACK64(ctx->h[i], &digest[i << 3]);
+//     }
+// #else
+//     UNPACK64(ctx->h[0], &digest[ 0]);
+//     UNPACK64(ctx->h[1], &digest[ 8]);
+//     UNPACK64(ctx->h[2], &digest[16]);
+//     UNPACK64(ctx->h[3], &digest[24]);
+//     UNPACK64(ctx->h[4], &digest[32]);
+//     UNPACK64(ctx->h[5], &digest[40]);
+// #endif /* !UNROLL_LOOPS */
+// }
+
+// /* SHA-224 functions */
+
+// void sha224(const unsigned char *message, unsigned int len,
+//             unsigned char *digest)
+// {
+//     sha224_ctx ctx;
+
+//     sha224_init(&ctx);
+//     sha224_update(&ctx, message, len);
+//     sha224_final(&ctx, digest);
+// }
+
+// void sha224_init(sha224_ctx *ctx)
+// {
+// #ifndef UNROLL_LOOPS
+//     int i;
+//     for (i = 0; i < 8; i++) {
+//         ctx->h[i] = sha224_h0[i];
+//     }
+// #else
+//     ctx->h[0] = sha224_h0[0]; ctx->h[1] = sha224_h0[1];
+//     ctx->h[2] = sha224_h0[2]; ctx->h[3] = sha224_h0[3];
+//     ctx->h[4] = sha224_h0[4]; ctx->h[5] = sha224_h0[5];
+//     ctx->h[6] = sha224_h0[6]; ctx->h[7] = sha224_h0[7];
+// #endif /* !UNROLL_LOOPS */
+
+//     ctx->len = 0;
+//     ctx->tot_len = 0;
+// }
+
+// void sha224_update(sha224_ctx *ctx, const unsigned char *message,
+//                    unsigned int len)
+// {
+//     unsigned int block_nb;
+//     unsigned int new_len, rem_len, tmp_len;
+//     const unsigned char *shifted_message;
+
+//     tmp_len = SHA224_BLOCK_SIZE - ctx->len;
+//     rem_len = len < tmp_len ? len : tmp_len;
+
+//     memcpy(&ctx->block[ctx->len], message, rem_len);
+
+//     if (ctx->len + len < SHA224_BLOCK_SIZE) {
+//         ctx->len += len;
+//         return;
+//     }
+
+//     new_len = len - rem_len;
+//     block_nb = new_len / SHA224_BLOCK_SIZE;
+
+//     shifted_message = message + rem_len;
+
+//     sha256_transf(ctx, ctx->block, 1);
+//     sha256_transf(ctx, shifted_message, block_nb);
+
+//     rem_len = new_len % SHA224_BLOCK_SIZE;
+
+//     memcpy(ctx->block, &shifted_message[block_nb << 6],
+//            rem_len);
+
+//     ctx->len = rem_len;
+//     ctx->tot_len += (block_nb + 1) << 6;
+// }
+
+// void sha224_final(sha224_ctx *ctx, unsigned char *digest)
+// {
+//     unsigned int block_nb;
+//     unsigned int pm_len;
+//     unsigned int len_b;
+
+// #ifndef UNROLL_LOOPS
+//     int i;
+// #endif
+
+//     block_nb = (1 + ((SHA224_BLOCK_SIZE - 9)
+//                      < (ctx->len % SHA224_BLOCK_SIZE)));
+
+//     len_b = (ctx->tot_len + ctx->len) << 3;
+//     pm_len = block_nb << 6;
+
+//     memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
+//     ctx->block[ctx->len] = 0x80;
+//     UNPACK32(len_b, ctx->block + pm_len - 4);
+
+//     sha256_transf(ctx, ctx->block, block_nb);
+
+// #ifndef UNROLL_LOOPS
+//     for (i = 0 ; i < 7; i++) {
+//         UNPACK32(ctx->h[i], &digest[i << 2]);
+//     }
+// #else
+//    UNPACK32(ctx->h[0], &digest[ 0]);
+//    UNPACK32(ctx->h[1], &digest[ 4]);
+//    UNPACK32(ctx->h[2], &digest[ 8]);
+//    UNPACK32(ctx->h[3], &digest[12]);
+//    UNPACK32(ctx->h[4], &digest[16]);
+//    UNPACK32(ctx->h[5], &digest[20]);
+//    UNPACK32(ctx->h[6], &digest[24]);
+// #endif /* !UNROLL_LOOPS */
+// }
+
+

+ 108 - 0
app/bmc/encryption/sha2.h

@@ -0,0 +1,108 @@
+// /*
+//  * FIPS 180-2 SHA-224/256/384/512 implementation
+//  * Last update: 02/02/2007
+//  * Issue date:  04/30/2005
+//  *
+//  * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
+//  * All rights reserved.
+//  *
+//  * Redistribution and use in source and binary forms, with or without
+//  * modification, are permitted provided that the following conditions
+//  * are met:
+//  * 1. Redistributions of source code must retain the above copyright
+//  *    notice, this list of conditions and the following disclaimer.
+//  * 2. 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.
+//  * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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.
+//  */
+
+// #ifndef SHA2_H
+// #define SHA2_H
+
+// #define SHA224_DIGEST_SIZE ( 224 / 8)
+// #define SHA256_DIGEST_SIZE ( 256 / 8)
+// #define SHA384_DIGEST_SIZE ( 384 / 8)
+// #define SHA512_DIGEST_SIZE ( 512 / 8)
+
+// #define SHA256_BLOCK_SIZE  ( 512 / 8)
+// #define SHA512_BLOCK_SIZE  (1024 / 8)
+// #define SHA384_BLOCK_SIZE  SHA512_BLOCK_SIZE
+// #define SHA224_BLOCK_SIZE  SHA256_BLOCK_SIZE
+
+// #ifndef SHA2_TYPES
+// #define SHA2_TYPES
+// typedef unsigned char uint8;
+// typedef unsigned long uint32;
+// typedef unsigned long long uint64;
+// #endif
+
+// #ifdef __cplusplus
+// extern "C" {
+// #endif
+
+// typedef struct {
+//     unsigned int tot_len;
+//     unsigned int len;
+//     unsigned char block[2 * SHA256_BLOCK_SIZE];
+//     uint32 h[8];
+// } sha256_ctx;
+
+// typedef struct {
+//     unsigned int tot_len;
+//     unsigned int len;
+//     unsigned char block[2 * SHA512_BLOCK_SIZE];
+//     uint64 h[8];
+// } sha512_ctx;
+
+// typedef sha512_ctx sha384_ctx;
+// typedef sha256_ctx sha224_ctx;
+
+// void sha224_init(sha224_ctx *ctx);
+// void sha224_update(sha224_ctx *ctx, const unsigned char *message,
+//                    unsigned int len);
+// void sha224_final(sha224_ctx *ctx, unsigned char *digest);
+// void sha224(const unsigned char *message, unsigned int len,
+//             unsigned char *digest);
+
+// void sha256_init(sha256_ctx * ctx);
+// void sha256_update(sha256_ctx *ctx, const unsigned char *message,
+//                    unsigned int len);
+// void sha256_final(sha256_ctx *ctx, unsigned char *digest);
+// void sha256(const unsigned char *message, unsigned int len,
+//             unsigned char *digest);
+
+// void sha384_init(sha384_ctx *ctx);
+// void sha384_update(sha384_ctx *ctx, const unsigned char *message,
+//                    unsigned int len);
+// void sha384_final(sha384_ctx *ctx, unsigned char *digest);
+// void sha384(const unsigned char *message, unsigned int len,
+//             unsigned char *digest);
+
+// void sha512_init(sha512_ctx *ctx);
+// void sha512_update(sha512_ctx *ctx, const unsigned char *message,
+//                    unsigned int len);
+// void sha512_final(sha512_ctx *ctx, unsigned char *digest);
+// void sha512(const unsigned char *message, unsigned int len,
+//             unsigned char *digest);
+
+// #ifdef __cplusplus
+// }
+// #endif
+
+// #endif /* !SHA2_H */
+

+ 501 - 0
app/bmc/ipmb/IPMBIfc.c

@@ -0,0 +1,501 @@
+/*
+*	Brief:	Implement IPMB send and receive function in this file, include primary IPMB and secondary IPMB.
+*	Author:	Jimbo_Zhang@outlook.com
+*	Date:	2019-9-9
+*/
+
+/* Standard includes. */
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+
+#include "com_IPMI_LANIfc.h"
+#include "com_IPMI_RMCP.h"
+#include "RMCP.h"
+#include "LANIfc.h"
+#include "com_IPMIDefs.h"
+#include "RMCP.h"
+#include "MD.h"
+#include <netdb.h>        /* getaddrinfo(3) et al.                       */
+#include <netinet/in.h>   /* sockaddr_in & sockaddr_in6 definition.      */
+#include  <net/if.h>
+#include <sys/prctl.h>
+#include "main.h"
+#include "Session.h"
+#include "com_IPMI_SDR.h"
+#include "com_IPMI_Storage.h"
+#include "SDR.h"
+#include <sys/syscall.h> /*此头必须带上*/
+
+pid_t gettid()
+{
+        return syscall(SYS_gettid); /*这才是内涵*/
+}
+
+
+//static int sendIPMBPkt(uint32_t ipmb_bus, uint8_t* i2c_send_buf, uint8_t size);
+static uint8_t ValidateIPMBChkSums ( uint8_t* Data, uint8_t Size);
+static void ProcessIPMBReq ( MsgPkt_T* pReq);
+uint8_t IsResponseMatch (MsgPkt_T* pReq, MsgPkt_T* pRes);
+static void* RecvIPMBPkt (void *pArg);
+
+int gFd_PrimaryIpmbIfcQ, gFd_PrimaryIpmbResQ;
+int gFd_SecondaryIpmbIfcQ, gFd_SecondaryIpmbResQ;
+int gFd_Primary,  gFd_Secondary;
+pthread_mutex_t primary_mutex, secondary_mutex;
+/*!
+    \brief      IPMB Task. Generating primary_IPMB task and secondary_IPMB task in this task.
+    \param:		0: primary ipmb, 1: secondary ipmb
+    \retval     none
+*/
+void *IPMBIfcTask(void *Param)
+{
+//	int i;
+	MsgPkt_T RcvMsgPkt;
+    uint8_t dev_name[10] = {0};
+    uint8_t IPMB_IFC_Q[32] = {0};
+    uint8_t IPMB_RES_Q[32] = {0};
+    uint8_t OwnerAddr;
+    int 	fd_IpmbDev;
+    int 	fd_IpmbIfcQ, fd_IpmbResQ;
+    uint8_t ipmbSelect = *(uint8_t*)Param;
+    int RetVal;
+    pthread_mutex_t *pMutex;
+    
+    //printf("ipmbSelect: %d\n", ipmbSelect);
+    //Primary IPMB
+    if((ipmbSelect == 0) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
+    {
+		printf("Primary IPMBIfcTask start...\n");
+		strcpy(IPMB_IFC_Q, PRIMARY_IPMB_IFC_Q);	
+		strcpy(IPMB_RES_Q, PRIMARY_IPMB_RES_Q);	
+		sprintf(dev_name, "/dev/i2c%d", g_BMCInfo.IpmiConfig.PrimaryIPMBBus);
+		OwnerAddr	=	g_BMCInfo.PrimaryIPMBAddr;
+        pMutex = &primary_mutex;
+	}
+	//Secondary IPMB
+	else if((ipmbSelect == 1) && g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
+	{
+		printf("Secondary IPMBIfcTask start...\n");
+		strcpy(IPMB_IFC_Q, SECONDARY_IPMB_IFC_Q);	
+		strcpy(IPMB_RES_Q, SECONDARY_IPMB_RES_Q);
+		sprintf(dev_name, "/dev/i2c%d", g_BMCInfo.IpmiConfig.SecondaryIPMBBus);
+		OwnerAddr	=	g_BMCInfo.SecondaryIPMBAddr;
+        pMutex = &secondary_mutex;
+	}
+	else
+	{
+		printf("Invalid param! %d\n", ipmbSelect);
+		return (void *)-1;
+	}
+
+	//create IPMB_IFC_Q
+    if(-1 != access(IPMB_IFC_Q, F_OK))
+    {
+        remove(IPMB_IFC_Q);
+    }
+    if(0 != mkfifo (IPMB_IFC_Q, 0777))
+    {
+        printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, IPMB_IFC_Q, strerror(errno));
+        return (void*)-1;
+    }
+    fd_IpmbIfcQ = open (IPMB_IFC_Q, O_RDWR);
+    if(-1 == fd_IpmbIfcQ)
+    {
+        printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, IPMB_IFC_Q, strerror(errno));
+        return (void*)-1;
+    }
+
+	//create IPMB_RES_Q
+    if(-1 != access(IPMB_RES_Q, F_OK))
+    {
+        remove(IPMB_RES_Q);
+    }
+    if(0 != mkfifo (IPMB_RES_Q, 0777))
+    {
+        printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, IPMB_RES_Q, strerror(errno));
+        return (void*)-1;
+    }
+    fd_IpmbResQ = open (IPMB_RES_Q, O_RDWR);
+    if(-1 == fd_IpmbResQ)
+    {
+        printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, IPMB_RES_Q, strerror(errno));
+        return (void*)-1;
+    }
+
+    fd_IpmbDev = open (dev_name, O_RDWR);
+    if(-1 == fd_IpmbDev)
+    {
+        printf("%s: Open IPMB failed! %s\n", __FUNCTION__, strerror(errno));
+        return (void*)-1;
+    }
+    //set IPMB address
+    if(0 != stm32_i2c_set_addr(fd_IpmbDev, OwnerAddr))
+    	printf("Set ipmb address fail.\n");
+
+	if(ipmbSelect == 0)
+    {
+    	gFd_PrimaryIpmbIfcQ = fd_IpmbIfcQ;
+    	gFd_PrimaryIpmbResQ = fd_IpmbResQ;
+    	gFd_Primary 	=	fd_IpmbDev;
+    }
+    else if(ipmbSelect == 1)
+    {
+    	gFd_SecondaryIpmbIfcQ = fd_IpmbIfcQ;
+    	gFd_SecondaryIpmbResQ = fd_IpmbResQ;
+    	gFd_Secondary 	=	fd_IpmbDev;
+    }
+
+    pthread_mutex_init(pMutex, NULL);
+
+    /*Create a thread to recv IPMB Pkt */
+	gThreadIndex++;	
+    if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,RecvIPMBPkt,Param))
+    {
+        printf("%s: Create RecvIPMBPkt thread failed! %s\n", __FUNCTION__, strerror(errno));
+        return (void *)-1; 
+    }
+
+	while(1)
+	{		
+		while(GetMsg(fd_IpmbIfcQ, &RcvMsgPkt, WAIT_INFINITE) != 0);
+		
+        switch(RcvMsgPkt.Param)
+		{
+			case PARAM_REQUEST:
+                //printf("---> IPMBIfcTask/PARAM_REQUEST\n");
+				ProcessIPMBReq (&RcvMsgPkt);
+				break;
+			case PARAM_BRIDGE:
+                //printf("---> IPMBIfcTask/PARAM_BRIDGE, channel: %d\n", RcvMsgPkt.Channel);
+                
+                /* Send the response */
+                if(RcvMsgPkt.Channel == PRIMARY_IPMB_CHANNEL)
+                {
+                    RetVal = stm32_i2c_master_write(gFd_Primary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size-1);
+                    printf("PriTx: ");
+                }
+                else if(RcvMsgPkt.Channel == SECONDARY_IPMB_CHANNEL)
+                {
+                    RetVal = stm32_i2c_master_write(gFd_Secondary, RcvMsgPkt.Data[0], &RcvMsgPkt.Data[1], RcvMsgPkt.Size-1);
+                    printf("SecTx: ");
+                }
+                else
+                {
+                    printf("IPMBIfc.c: IPMB channel error. %#x\r\n", RcvMsgPkt.Channel);
+                }
+
+                int i;
+                for(i=0;i<RcvMsgPkt.Size;i++)
+                    printf("%#x ", RcvMsgPkt.Data[i]);
+                printf("\n");
+
+                if (RetVal < 0)
+                {
+                    printf ("IPMBIfc.c : Unable to send a IPMI Bridge Message\n");
+                    RespondSendMessage (&RcvMsgPkt, STATUS_FAIL);
+                }
+                else
+                {
+                    RespondSendMessage (&RcvMsgPkt, STATUS_OK);
+                }
+                
+                break;
+            default:
+				printf("Unknow message param %#x\r\n", RcvMsgPkt.Param);
+				break;
+		}
+		
+	}
+}
+
+
+
+/**
+ * @brief Process the request posted by IPMB driver.
+ * @param pReq - Request message pointer.
+**/
+static void
+ProcessIPMBReq ( MsgPkt_T* pReq)
+{
+    MsgPkt_T             	ResPkt;
+    uint8_t              	ReqLen;
+    IPMIMsgHdr_T* 			pIPMIMsgReq = (IPMIMsgHdr_T*) pReq->Data;
+   
+    int RetVal = 0;
+    ReqLen = pReq->Size;
+	
+    /* Validate Checksums */
+    if (TRUE != ValidateIPMBChkSums ((uint8_t*)pIPMIMsgReq, ReqLen))
+    {
+        printf ("IPMBIfc.c : IPMB Checksum validation failed\r\n");
+        return;
+    }
+
+    pReq->Param			= PARAM_IFC;
+    pReq->Cmd			= pIPMIMsgReq->Cmd;
+    pReq->NetFnLUN		= pIPMIMsgReq->NetFnLUN;
+
+    if(pReq->Channel == PRIMARY_IPMB_CHANNEL)
+    	pReq->SrcQ 			= gFd_PrimaryIpmbResQ;
+    else
+    	pReq->SrcQ 			= gFd_SecondaryIpmbResQ;
+	
+    if(0 == ValidateMsgHdr(pReq))
+    {
+        /* Post the message to message handler Task */
+        if (0 != PostMsg (gFd_MsgHndlrIfc, pReq))
+        {
+            printf("IPMB post message to MsgHndlrTask fail!\n");;
+        }
+    }
+    else
+    {
+         //printf("Bridge response to Originator\n");
+         return;
+    }
+    /* Post the message to message handler Task */
+    //PostMsg (gFd_MsgHndlrIfc, pReq);
+       
+    if(pReq->ResTimeOut < 1)	pReq->ResTimeOut = 10;
+    do
+    {
+    	if(pReq->Channel == PRIMARY_IPMB_CHANNEL)
+        {
+      		RetVal = GetMsg (gFd_PrimaryIpmbResQ, &ResPkt, pReq->ResTimeOut);  
+            if((pReq->Cmd == CMD_GET_SDR) && (pReq->NetFnLUN == (NETFN_STORAGE<<2)) && (pReq->Data[4] == 5))
+            {
+                ResPkt.Data[3] = g_BMCInfo.PrimaryIPMBAddr;
+            }
+        }
+      	else
+        {
+      		RetVal = GetMsg (gFd_SecondaryIpmbResQ, &ResPkt, pReq->ResTimeOut);  
+            //为传感器的owner ID打的补丁 
+            if((pReq->Cmd == CMD_GET_SDR) && (pReq->NetFnLUN == (NETFN_STORAGE<<2)) && (pReq->Data[4] == 5))
+            {
+                ResPkt.Data[3] = g_BMCInfo.SecondaryIPMBAddr;
+            }
+        }
+
+    }while(!RetVal && !IsResponseMatch(pReq, &ResPkt) );
+	
+	if (0 != RetVal)
+    {
+		printf("Warning: Process IPMB request fail, return timeout.\r\n");
+		ResPkt.Param	=	PARAM_NORMAL_RESPONSE;
+		ResPkt.Size		=	sizeof(IPMIMsgHdr_T)+2;
+		
+		SwapIPMIMsgHdr(((IPMIMsgHdr_T*)pReq->Data), ((IPMIMsgHdr_T*)ResPkt.Data));
+		ResPkt.Data[sizeof(IPMIMsgHdr_T)]	=	CC_TIMEOUT;
+		ResPkt.Data[sizeof(IPMIMsgHdr_T)+1]	=	CalculateCheckSum2(ResPkt.Data, sizeof(IPMIMsgHdr_T)+1);
+    }   
+
+    /* If its not normal IPMI Response just return */
+    if (PARAM_NO_RESPONSE == ResPkt.Param)
+    {
+        printf ("IPMBIfc.c : IPMB request packet dropped, not processed\n");
+        return;
+    }
+
+   
+    /* Send the response */
+	if(pReq->Channel == PRIMARY_IPMB_CHANNEL)
+	{
+        pthread_mutex_lock(&primary_mutex);
+		RetVal = stm32_i2c_master_write(gFd_Primary, ResPkt.Data[0], &ResPkt.Data[1], ResPkt.Size-1);
+        pthread_mutex_unlock(&primary_mutex);
+        printf("PriTx: ");
+	}
+	else if(pReq->Channel == SECONDARY_IPMB_CHANNEL)
+	{
+        pthread_mutex_lock(&secondary_mutex);
+		RetVal = stm32_i2c_master_write(gFd_Secondary, ResPkt.Data[0], &ResPkt.Data[1], ResPkt.Size-1);
+        pthread_mutex_unlock(&secondary_mutex);
+        printf("SecTx: ");
+	}
+	else
+	{
+		printf("IPMBIfc.c: IPMB channel error. %#x\r\n", pReq->Channel);
+	}
+
+    int i;
+    for(i=0;i<ResPkt.Size;i++)
+        printf("%#x ", ResPkt.Data[i]);
+    printf("\n");
+	
+    if (0 != RetVal)
+    {
+        printf ("IPMBIfc.c : Unable to send a IPMI Response\n");
+    }
+    return;
+}
+
+/**
+ * @brief Validate IPMB Checksums.
+ * @param Data - Buffer to be validated.
+ * @param Size - Size of the buffer.
+ * @return TRUE if valid, FALSE if error.
+**/
+static uint8_t ValidateIPMBChkSums ( uint8_t* Data, uint8_t Size)
+{
+    uint8_t i;
+    uint8_t chksum;
+
+    /* Check IPMB message min size */
+    if (Size < MIN_IPMB_MSG_LENGTH)
+    {
+        printf("IPMBIfc.c: Invalid IPMB Message Length\r\n");
+        return FALSE;
+    }
+
+    /* Validate the checksum1 */
+    chksum = 0;
+    for (i = 0; i < 3; i++)
+    {
+        chksum += *(Data + i);
+    }
+
+    if (chksum != 0)
+    {
+       
+		printf ("IPMBIfc.c: Invalid checksum 1, size = %d\n",Size);
+		for(i = 0; i < Size;i++)
+			printf("%x ",Data[i]);
+		printf("\n");
+        return FALSE;
+    }
+    /* Validate the checksum2 */
+    chksum = 0;
+    for (i = 3; i < Size; i++)
+    {
+        chksum += *(Data + i);
+    }
+
+    if (chksum != 0)
+    {
+       
+		printf("IPMBIfc.c: Invalid checksum 2, size = %d\n",Size);
+		for(i = 0; i < Size;i++)
+			printf("%x ",Data[i]);
+		printf("\n");
+        
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+
+/*-----------------------------------------------------
+ * @fn IsResponseMatch
+ * @brief Checks if the Response Message corresponds to 
+ *        the Request Message
+ * 
+ * @param pReq    : IPMI Request Message Packet
+ * @param pRes    : IPMI Response Message Packet
+ * 
+ * @return  1 if match
+ *          0 if mismatch
+ *----------------------------------------------------*/
+uint8_t IsResponseMatch (MsgPkt_T* pReq, MsgPkt_T* pRes)
+{
+
+    if( ( ((((IPMIMsgHdr_T*)pRes->Data)->RqSeqLUN) >> 2) != ((((IPMIMsgHdr_T*)pReq->Data)->RqSeqLUN) >> 2) ) && 
+        ( (pReq->NetFnLUN & 0x4) && (PARAM_NO_RESPONSE != pRes->Param) ) )
+    {
+        return FALSE;
+    }
+  
+    return TRUE;
+}
+
+
+
+/**
+ * @fn RecvIPMBPkt
+ * @brief This function receives IPMB request packet and post the message to
+ *        IPMB interface queue
+**/
+static void* RecvIPMBPkt (void *Param)
+{
+    MsgPkt_T    IPMBReqPkt;
+    int IPMBSlaveFd;
+    int retval;
+    uint8_t ipmbSelect = *(uint8_t*)Param;
+    int i;
+
+    prctl(PR_SET_NAME, __FUNCTION__, 0, 0, 0);
+    int curThreadIndex = 0;
+    pthread_mutex_t *pMutex;
+
+    memset(&IPMBReqPkt,0,sizeof(MsgPkt_T));
+    if(0 == ipmbSelect)
+    {
+    	printf ("Primary IPMB Receiver Started...\n");
+        IPMBReqPkt.Data [0] = g_BMCInfo.PrimaryIPMBAddr;
+        IPMBReqPkt.Channel = PRIMARY_IPMB_CHANNEL;
+        IPMBSlaveFd = gFd_Primary;
+        pMutex = &primary_mutex;
+        //printf("Primary: %p\n", RecvIPMBPkt);
+    }
+    else if(1 == ipmbSelect)
+    {
+    	printf ("Secondary IPMB Receiver Started...\n");
+        IPMBReqPkt.Data [0] = g_BMCInfo.SecondaryIPMBAddr;
+        IPMBReqPkt.Channel = SECONDARY_IPMB_CHANNEL;
+        IPMBSlaveFd = gFd_Secondary;
+        pMutex = &secondary_mutex;
+        //printf("Secondary: %p\n", RecvIPMBPkt);
+    }
+
+
+
+    /* Loop forever */
+    while (1)
+    {
+        //printf("ppid: %d, pid: %d, tid: %d, i: %d, ipmbSelect: %d\n", getppid(), getpid(), gettid(), i++, ipmbSelect);
+        pthread_mutex_lock(pMutex);
+        pthread_mutex_unlock(pMutex);
+        retval = stm32_i2c_slave_recv(IPMBSlaveFd, &IPMBReqPkt.Data[1]);
+        if( retval > 5)
+        {
+            IPMBReqPkt.Param    = PARAM_REQUEST;
+            IPMBReqPkt.Size     = retval + 1;       /* +1 to include BMC Slave address */
+
+            int cnt;
+            if(0 == ipmbSelect)
+                printf("\nPriRx: ");
+            else
+                printf("\nSecRx: ");
+
+            for(cnt=0;cnt < IPMBReqPkt.Size; cnt++)
+                printf("%#x ", IPMBReqPkt.Data[cnt]);
+            printf("\n");
+
+            /* Post the IPMB Request message to IPMBIfc Queue */
+            if(ipmbSelect == 0)
+            {
+                if (0 != PostMsg (gFd_PrimaryIpmbIfcQ, &IPMBReqPkt))
+                {
+                    printf ("IPMBIfc.c : Error posting message to IPMBIfc_Q\n");
+                }
+            }
+            else
+            {
+                if (0 != PostMsg (gFd_SecondaryIpmbIfcQ, &IPMBReqPkt))
+                {
+                    printf ("IPMBIfc.c : Error posting message to IPMBIfc_Q\n");
+                }
+            }
+
+        }
+
+       
+	}
+    return (void*)-1;
+}

+ 7 - 0
app/bmc/ipmb/IPMBIfc.h

@@ -0,0 +1,7 @@
+#ifndef __IPMB_IFC_H__
+#define __IPMB_IFC_H__
+
+
+void *IPMBIfcTask( void *Param);
+
+#endif /* __IPMB_IFC_H__ */

+ 44 - 0
app/bmc/lan/Ciphertable.h

@@ -0,0 +1,44 @@
+/*************************************************************** 
+**                                                            **
+**    (C)Copyright 2006-2009,American Megatrends Inc.         **
+**                                                            **
+**            All Rights Reserved.                            **
+**                                                            **
+**        5555 Oakbrook Pkwy Suite 200, Norcross,             **
+**                                                            **
+**        Georgia - 30093, USA. Phone-(770)-246-8600.         **
+**                                                            **
+***************************************************************/
+/***************************************************************/
+/* This file contain the cipher suite table   	               */
+/*						               */
+/*   						               */
+/***************************************************************/
+
+
+#ifndef __CIPHERTABLE_H__
+#define __CIPHERTABLE_H__
+#define MAX_CIPHER_SUITES_BYTES     60
+
+#define N0_OF_CIPHER_SUITE_SUPPORTED  9
+
+/*** Global Variables ***/
+
+//const unsigned char  g_CipherRec [MAX_CIPHER_SUITES_BYTES] =
+//{
+    /* Standard records */
+/*- Start -- ID --- Auth --- Intgr - Conf-*/
+    //0xC0,   0x00,   0x00,   0x40,   0x80,
+    //0xC0,   0x01,   0x01,   0x40,   0x80,
+    //0xC0,   0x02,   0x01,   0x41,   0x80,
+    //0xC0,   0x03,   0x01,   0x41,   0x81,
+    //0xC0,   0x06,   0x02,   0x40,   0x80,
+    //0xC0,   0x07,   0x02,   0x42,   0x80,
+    //0xC0,   0x08,   0x02,   0x42,   0x81,
+    //0xC0,   0x0B,   0x02,   0x43,   0x80,
+    //0xC0,   0x0C,   0x02,   0x43,   0x81,
+/*- Start --OEM-ID -- OEM-IANA - Auth --- Intgr - Conf-*/
+//};
+
+#endif
+

+ 723 - 0
app/bmc/lan/LANIfc.c

@@ -0,0 +1,723 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * LANIfc.c
+ * LAN Interface Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+
+#include "com_IPMI_LANIfc.h"
+#include "com_IPMI_RMCP.h"
+#include "RMCP.h"
+#include "LANIfc.h"
+#include "com_IPMIDefs.h"
+#include "RMCP.h"
+#include "MD.h"
+#include <netdb.h>        /* getaddrinfo(3) et al.                       */
+#include <netinet/in.h>   /* sockaddr_in & sockaddr_in6 definition.      */
+#include  <net/if.h>
+#include <sys/prctl.h>
+#include "main.h"
+#include "Session.h"
+
+#define NO_OF_RETRY                     3
+#define MAX_POSSIBLE_IPMI_DATA_SIZE     1000
+#define MAX_LAN_BUFFER_SIZE             1024
+#define LAN_TIMER_INTERVAL              10
+
+#define RMCP_CLASS_MSG_OFFSET           3
+#define IPMI_MSG_AUTH_TYPE_OFFSET       4
+#define RMCP_ASF_PING_MESSAGE_LENGTH    12
+#define IPMI_MSG_LEN_OFFSET             13
+#define IPMI20_MSG_LEN_OFFSET           14
+#define RMCP_CLASS_MSG_ASF              0x06
+#define RMCP_CLASS_MSG_IPMI             0x07
+
+//static void*    LANTimer (void*);
+static void*    RecvLANPkt (void*);
+static int      SendLANPkt (MsgPkt_T *pRes );
+static void     ProcessLANReq (  MsgPkt_T* pReq);
+static void		ProcessBridgeMsg (  MsgPkt_T* pReq );
+
+static int 		InitUDPSocket(void);
+static int SetIPv4Header(int socketID);
+
+
+/****************************Our additions for timing out connections****************************/
+/*We need a way to timeout connect calls faster in case of wrong email server ip entered
+so I created a connect_tmout function that gives this granularity
+we don't want to spend too much time in test alert etc waiting for connection timeouts*/
+
+// static void SetSocketNonBlocking(int s)
+// {
+// 	int flags;
+
+// 	flags = fcntl(s, F_GETFL, 0);
+// 	if(flags == -1)
+// 	{
+// 		flags = 0;
+// 	}
+
+// 	flags |= O_NONBLOCK;
+
+// 	flags = fcntl(s, F_SETFL, flags);
+// 	if(flags == -1)
+// 	{
+// 		printf("Could not set socket to non blocking!!\n");
+// 	}
+
+// 	return;
+// }
+
+int gSocket_LAN = -1;
+int gFd_LanIfcQ, gFd_LanResQ;
+
+/**
+ * @brief LAN Interface Task.
+**/
+void *LANIfcTask (void *param)
+{
+	MsgPkt_T    Req;
+	int i,BMC,Buffer = 0;
+	uint8_t ethindex=0;
+	
+	prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
+	int curThreadIndex = 0;
+
+	/* Init LAN SMB */
+	printf("LANIfc Task Started... \n");
+
+	//create LAN_IFC_Q
+    if(-1 != access(LAN_IFC_Q, F_OK))
+    {
+        remove(LAN_IFC_Q);
+    }
+    if(0 != mkfifo (LAN_IFC_Q, 0777))
+    {
+        printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, LAN_IFC_Q, strerror(errno));
+        return (void*)-1;
+    }
+    gFd_LanIfcQ = open (LAN_IFC_Q, O_RDWR);
+    if(-1 == gFd_LanIfcQ)
+    {
+        printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, LAN_IFC_Q, strerror(errno));
+        return (void*)-1;
+    }
+
+	//create LAN_RES_Q
+    if(-1 != access(LAN_RES_Q, F_OK))
+    {
+        remove(LAN_RES_Q);
+    }
+    if(0 != mkfifo (LAN_RES_Q, 0777))
+    {
+        printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, LAN_RES_Q, strerror(errno));
+        return (void*)-1;
+    }
+    gFd_LanResQ = open (LAN_RES_Q, O_RDWR);
+    if(-1 == gFd_LanResQ)
+    {
+        printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, LAN_RES_Q, strerror(errno));
+        return (void*)-1;
+    }
+
+    /* Create LAN socket */
+    if(0 != InitUDPSocket())
+    {
+    	printf("%s: Create UDP socket failed! %s\n", __FUNCTION__, strerror(errno));
+    	return (void *)-1; 
+    }
+
+	/*Create a thread to recv UDS Pkt */
+	gThreadIndex++;	
+    if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,RecvLANPkt,NULL))
+    {
+        printf("%s: Create RecvLANPkt thread failed! %s\n", __FUNCTION__, strerror(errno));
+        return (void *)-1; 
+    }
+
+	while (1)
+	{		
+		/* Wait for a message in LANIfc interface Queue */
+		if (0 != GetMsg (gFd_LanIfcQ, &Req, WAIT_INFINITE))
+		{
+			printf("LANIfc.c : Error fetching message from hLANIfc_Q\n");
+			continue;
+		}
+
+		switch (Req.Param)
+		{
+		case LAN_SMB_REQUEST :
+			ProcessLANReq (&Req);
+			break;
+
+		case BRIDGING_REQUEST :
+			ProcessBridgeMsg (&Req );
+			break;
+
+		default :
+			printf ("LANIfc.c : Invalid request\n");
+			break;
+		}
+	}
+}
+
+/**
+ * @fn InitUnixDomainSocket
+ * @brief This function is used to create the Socket for each BMC
+ * @param BMCInst
+**/
+static int InitUDPSocket(void)
+{
+  	struct  sockaddr_in local;
+  	char    UDPIfcName [MAX_STR_LENGTH];
+  	int 	reuseaddr = 1;
+
+  	memset(UDPIfcName,0,sizeof(UDPIfcName));
+
+  	if(gSocket_LAN != -1)
+  	{
+  		close(gSocket_LAN);
+  		gSocket_LAN = -1;
+  	}
+
+	memset(&local, 0, sizeof(struct sockaddr_in));
+	local.sin_family = AF_INET;
+	local.sin_port = htons(623);
+	local.sin_addr.s_addr = htonl(INADDR_ANY);  
+
+    gSocket_LAN = socket(AF_INET,SOCK_DGRAM,0);
+    if(-1 == gSocket_LAN)
+    {
+        printf("LANIfc.c : Unable to create the UDP Socket\n");
+        return -1;
+    }
+
+    //printf("UDP Socket %d\n", gSocket_LAN);
+
+    strcpy(UDPIfcName,"eth0");
+	
+	if (0 != setsockopt (gSocket_LAN, SOL_SOCKET,SO_BINDTODEVICE, UDPIfcName, sizeof (UDPIfcName)+1))
+	{
+		printf("LANIfc.c: SetSockOpt(SO_BINDTODEVICE) Failed for UDP Socket\n");
+		return -1;
+	}
+	if (0 != setsockopt(gSocket_LAN, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)))
+	{
+		printf("LANIfc.c: Setsockopt(SO_REUSEADDR) Failed for UDP socket\n");
+	}
+	SetIPv4Header(gSocket_LAN);
+  
+    /* Bind */
+    if (-1 == bind(gSocket_LAN,(struct sockaddr *)&local,sizeof(local)))
+    {
+        printf("LANIfc.c : Error binding  UDP Socket, %d, %s\n", errno, strerror(errno));
+        return -1;
+    }
+
+    //printf("Create UDP socket successfully, socket %d, port: %d\n", gSocket_LAN, local.sin_port);
+
+    return 0;
+}
+
+/**
+ * @fn  ReadData
+ * @brief This function receives the IPMI LAN request packets
+ *
+ * @param pMsgPkt - pointer to message packet
+ * @param Socket  - Socket handle
+**/
+static
+int  ReadData (MsgPkt_T *pMsgPkt, int Socket )
+{
+	unsigned int    SourceLen = 0,Index,SocktIndex=0,addrlen=0;
+	int 			Channel = 0;
+	uint8_t   *pData      = pMsgPkt->Data;
+	int16_t   Len         = 0;
+	uint16_t  RecvdLen    = 0;
+	uint16_t  IPMIMsgLen  = 0;
+	uint16_t  IPMIMsgOffset   = 0;
+	struct  sockaddr_in Sourcev4;
+	struct  sockaddr_in server_v4addr;
+	void *Source = NULL ;
+	void *server_addr = NULL ;
+	uint8_t  WaitCount;
+	int i;
+			
+	
+	Source = &Sourcev4;
+	SourceLen = sizeof (Sourcev4);
+	
+	//printf("ReadData:\n");
+	 //SourceLen = sizeof (Source);
+	/* Read minimum bytes to find class of message */
+	while (RecvdLen < RMCP_CLASS_MSG_OFFSET)
+	{
+		Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0, (struct sockaddr *)Source, &SourceLen);
+		// printf("Recv1 %d: ", Len);
+		// for(i=0;i<Len;i++)
+		// 	printf("%#x ", pData[RecvdLen+i]);
+		// printf("\n");
+
+		if ((Len >= -1) && (Len <= 0))
+		{
+			return -1;
+		}
+		RecvdLen += (uint16_t)Len;
+	}
+
+
+	/*  if RMCP Presence Ping Requested */
+	if (RMCP_CLASS_MSG_ASF == pData[RMCP_CLASS_MSG_OFFSET])
+	{
+		/* Read remaining RMCP ASF ping message */
+		while (RecvdLen < RMCP_ASF_PING_MESSAGE_LENGTH)
+		{
+			Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0, (struct sockaddr *)Source, &SourceLen);
+			// printf("Recv2 %d: ", Len);
+			// for(i=0;i<Len;i++)
+			// 	printf("%#x ", pData[RecvdLen+i]);
+			// printf("\n");
+			if ((Len >= -1) && (Len <= 0))
+			{
+				return -1;
+			}
+			RecvdLen += (uint16_t)Len;
+		}
+	}
+			/*else if IPMI RMCP request */
+	else if (RMCP_CLASS_MSG_IPMI == pData[RMCP_CLASS_MSG_OFFSET])
+	{
+		/* Read minimum no of bytes for IPMI Auth type offset*/
+		while (RecvdLen < IPMI_MSG_AUTH_TYPE_OFFSET)
+		{
+			Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
+			// printf("Recv3 %d: ", Len);
+			// for(i=0;i<Len;i++)
+			// 	printf("%#x ", pData[RecvdLen+i]);
+			// printf("\n");
+			if ((Len >= -1) && (Len <= 0))
+			{
+				return -1;
+			}
+			RecvdLen += (uint16_t)Len;
+		}
+		/* Get the IPMI message length offset based on format/authentication type */
+		if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == RMCP_PLUS_FORMAT)
+		{
+			IPMIMsgOffset = IPMI20_MSG_LEN_OFFSET + 1;
+		}
+		else if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == AUTH_TYPE_NONE)
+		{
+			IPMIMsgOffset = IPMI_MSG_LEN_OFFSET;
+		}
+		else
+		{
+			IPMIMsgOffset = IPMI_MSG_LEN_OFFSET + AUTH_CODE_LEN;
+		}
+
+		/* Read minimum no of bytes for IPMI message length offset*/
+		while (RecvdLen < IPMIMsgOffset)
+		{
+			Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
+			// printf("Recv4 %d: ", Len);
+			// for(i=0;i<Len;i++)
+			// 	printf("%#x ", pData[RecvdLen+i]);
+			// printf("\n");
+			if ((Len >= -1) && (Len <= 0))
+			{
+				return -1;
+			}
+			RecvdLen += (uint16_t)Len;
+		}
+
+		/* Get the IPMI message length based on RMCP format type */
+		if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == RMCP_PLUS_FORMAT)
+		{
+			IPMIMsgLen = *((uint16_t*)&pData [IPMI20_MSG_LEN_OFFSET]);
+		}
+		else
+		{
+			IPMIMsgLen = pData [IPMIMsgOffset];
+		}
+		/* We are assuming that we cannot get more than 17 K data in IPMI Msg */
+		/* This work around for fix the malformed IPMI Msg length */
+
+		if(IPMIMsgOffset > MAX_POSSIBLE_IPMI_DATA_SIZE )
+		{
+			return -1;
+		}
+		/* Read the remaining IPMI message packets */
+		WaitCount = 3;
+		while (RecvdLen < IPMIMsgLen)
+		{
+			Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
+			// printf("Recv5 %d: ", Len);
+			// for(i=0;i<Len;i++)
+			// 	printf("%#x ", pData[RecvdLen+i]);
+			// printf("\n");
+			if ((Len >= -1) && (Len <= 0))
+			{
+				if(Len == -1)
+				{
+					if(errno == EAGAIN)
+					{
+					   WaitCount--;
+					}
+					else
+					   return -1;
+				}
+				else
+					return -1;
+			}
+			if(WaitCount == 0)
+			{
+				return -1;
+			}
+			RecvdLen += (uint16_t)Len;
+		}
+	}/* else other RMCP class are not supported. */
+	else
+	{
+		printf ("Unknown RMCP class\n");
+	}
+
+	pMsgPkt->Size     = RecvdLen;
+	pMsgPkt->UDPPort  = ((struct sockaddr_in *)Source)->sin_port;
+	pMsgPkt->Socket   = Socket;
+	pMsgPkt->Channel  = LAN_RMCP_CHANNEL;
+	
+	// printf("\nLan received %d: ",RecvdLen);
+	// for(i=0;i<RecvdLen;i++)
+	// {
+	// 	printf("%#x ", pData[i]);
+	// }
+	// printf("\n");
+
+	if(SourceLen!=0) 
+	{
+		memcpy (pMsgPkt->IPAddr, &((struct sockaddr_in *)Source)->sin_addr.s_addr, sizeof (struct in_addr));
+	}
+
+	pMsgPkt->Param    = LAN_SMB_REQUEST;
+	
+	return 0;
+}
+
+void *RecvLANPkt(void *pArg)
+{
+    MsgPkt_T            MsgPkt;
+    struct timeval Timeout;
+    struct sockaddr_in local;
+    int RetVal,max,Index = 0;
+    unsigned int locallen;
+    prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
+    fd_set  fds;
+
+    memset(&local,0,sizeof(local));
+
+    locallen=sizeof(local);
+
+    printf("RecvLANPkt start...\n");
+    while(1)
+    {
+        Timeout.tv_sec  =   SESSION_TIMEOUT; 
+        Timeout.tv_usec  =   0; 
+
+        FD_ZERO(&fds);
+        if(gSocket_LAN != -1)
+            FD_SET(gSocket_LAN,&fds);
+        
+        max = gSocket_LAN+1;
+
+        /*Waits for an event to occur on socket*/
+        RetVal = select (max, &fds, NULL, NULL, &Timeout);
+        if (-1 == RetVal)
+        {
+            continue;
+        }
+        if (0 == RetVal)
+        {
+            /* Its due to timeout - continue */
+            continue;
+        }
+        
+        /*Accepting Connection*/
+        if(FD_ISSET(gSocket_LAN,&fds))
+        {
+            if(0 ==  ReadData( &MsgPkt,gSocket_LAN))
+            {
+                /* Post the request packet to LAN Interface Queue */
+				if (0 != PostMsg (gFd_LanIfcQ, &MsgPkt))
+				{
+					printf ("Warning: LANIfc.c Error posting message to LANIfc Q\n");
+				}               
+            }       
+            else
+            {
+                close(gSocket_LAN);
+                gSocket_LAN = -1;
+            }      
+        }
+   }
+}
+
+/**
+ * @fn SendLANPkt
+ * @brief This function sends the IPMI LAN Response to the requester
+ * @param pRes - Response message.
+**/
+int SendLANPkt (MsgPkt_T *pRes )
+{
+	struct  sockaddr_in Dest;
+	//struct stat Stat;
+	int ret = 0;
+	
+	/* Set the destination UDP port and IP Address */
+	Dest.sin_family     =   AF_INET;
+	Dest.sin_port       =   pRes->UDPPort;
+	memcpy (&Dest.sin_addr.s_addr, pRes->IPAddr, sizeof (struct in_addr));
+	
+	/* Send the LAN response packet */
+	//int i;
+	//printf("\nLan send socket: %d, byte: %d: ", pRes->Socket, pRes->Size);
+	// for (i = 0; i < pRes->Size; ++i)
+	// {
+	// 	printf("%#x ", pRes->Data[i]);
+	// }
+	//printf("\n");
+
+	//Check the socket before send a message on a socket
+	//if (fstat(pRes->Socket, &Stat) != -1) 
+	{
+		
+		ret = sendto (pRes->Socket, pRes->Data, pRes->Size, 0, (struct sockaddr*)&Dest, sizeof (Dest));
+		if (ret == -1)
+		{
+			printf ("Warning: LANIfc.c Error sending response packets to LAN, %s\n",strerror(errno));
+		}
+		// else
+		// {
+		// 	printf ("LANIfc.c : LAN packet sent successfully\n");
+		// }
+	}
+
+	return 1;
+}
+
+
+/**
+ * @brief Process SMB Request.
+ * @param pReq - Request message.
+**/
+static void
+ProcessLANReq (  MsgPkt_T* pReq )
+{
+	MsgPkt_T        Res;
+	SessionInfo_T*  pSessionInfo;
+	SessionHdr_T*   pSessionHdr;
+	SessionHdr2_T*  pSessionHdr2;
+	uint32_t          SessionID =0;
+
+	/* Copy the request to response */
+	Res = *pReq;
+
+	/* Save the LAN header inofmation */
+	pSessionHdr  = (SessionHdr_T*) (((RMCPHdr_T*)pReq->Data) + 1);
+	pSessionHdr2 = (SessionHdr2_T*)(((RMCPHdr_T*)pReq->Data) + 1);
+	if (RMCP_PLUS_FORMAT == pSessionHdr->AuthType)
+	{
+		SessionID = pSessionHdr2->SessionID;
+		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
+	}
+	else
+	{
+		SessionID = pSessionHdr->SessionID;
+		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID );
+	}
+	if (NULL != pSessionInfo)
+	{
+		pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort = Res.UDPPort;
+		pSessionInfo->hSocket                   = Res.Socket;
+		//SocktIndex=GetSocketInfoIndex(pSessionInfo->hSocket );
+		
+		memcpy (pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, Res.IPAddr, sizeof (struct in_addr));
+		memcpy (&pSessionInfo->LANRMCPPkt.RMCPHdr, Res.Data, sizeof (RMCPHdr_T));
+	}
+
+	/* Process the RMCP Request */
+	Res.Size = ProcessRMCPReq ((RMCPHdr_T*)pReq->Data, (RMCPHdr_T*)Res.Data);
+
+	/* ResLen is 0, don't send the packet */
+	if (0 == Res.Size )
+	{
+        printf ("Note: LANIfc.c LAN request packet dropped, not processed\n");
+	 	return;
+	}
+
+	/* Sent the response packet */
+	SendLANPkt (&Res);
+
+	return;
+}
+
+/*--------------------------------------------
+ * ProcessBridgeMsg
+ *--------------------------------------------*/
+static void
+ProcessBridgeMsg (  MsgPkt_T* pReq )
+{
+	MsgPkt_T        ResPkt;
+	uint16_t          PayLoadLen   = 0;
+	uint8_t           PayLoadType  = 0;
+	SessionInfo_T   *pSessionInfo = getSessionInfo (SESSION_HANDLE_INFO, pReq->Data);
+
+ 	//printf ("LANIfc: Bridge Request\n");
+
+	if (NULL == pSessionInfo)
+	{
+		printf ("Warning: LANIfc ProcessBridgeMsg - No Session with the LAN\n");
+		return;
+	}
+
+	/* Copy Lan RMCP headers from Session Record */
+	ResPkt.UDPPort  = pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort;
+	ResPkt.Socket   = pSessionInfo->hSocket;
+	
+	memcpy (ResPkt.IPAddr, pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, sizeof (struct in_addr));
+	memcpy (ResPkt.Data, &pSessionInfo->LANRMCPPkt.RMCPHdr, sizeof (RMCPHdr_T));
+
+// #if IPMI20_SUPPORT == 1
+// 	if (RMCP_PLUS_FORMAT == pSessionInfo->AuthType)
+// 	{
+// 		/* Fill Session Header */
+// 		pSessionInfo->OutboundSeq++;
+// 		PayLoadLen      = pReq->Size - 1;
+// 		PayLoadType     = pReq->Cmd;
+// 		PayLoadType    |= (pSessionInfo->SessPyldInfo[PayLoadType].AuxConfig[0] & 0xC0);
+// 		PayLoadLen      = Frame20Payload (PayLoadType, (  RMCPHdr_T*)&ResPkt.Data [0],
+// 									 &pReq->Data[1], PayLoadLen, pSessionInfo );
+// 	}
+// 	else
+// #endif /*IPMI20_SUPPORT == 1*/
+	{
+		/* Fill Session Header */
+		  SessionHdr_T* pSessionHdr = (  SessionHdr_T*)(&ResPkt.Data [sizeof(RMCPHdr_T)]);
+		  uint8_t*        pPayLoad    = (  uint8_t*)(pSessionHdr + 1);
+
+		pSessionHdr->AuthType       = pSessionInfo->AuthType;
+		pSessionHdr->SessionSeqNum  = pSessionInfo->OutboundSeq++;
+		pSessionHdr->SessionID      = pSessionInfo->SessionID;
+
+		/* If AuthType is not 0 - Compute AuthCode */
+		if (0 != pSessionInfo->AuthType)
+		{
+			PayLoadLen = AUTH_CODE_LEN;
+			pPayLoad [PayLoadLen++] = pReq->Size - 1;
+			memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
+			PayLoadLen += pReq->Size;
+			PayLoadLen--;
+			PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
+			ComputeAuthCode (pSessionInfo->Password, pSessionHdr,
+							 (  IPMIMsgHdr_T*) &pPayLoad [AUTH_CODE_LEN+1],
+							 pPayLoad, MULTI_SESSION_CHANNEL);
+		}
+		else
+		{
+		   pPayLoad [PayLoadLen++] = pReq->Size - 1;
+			/*  Fill the ipmi message */
+		   memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
+		   PayLoadLen += pReq->Size;
+		   PayLoadLen--;
+		   PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
+		}
+
+	}
+
+	ResPkt.Size = PayLoadLen;
+
+	if(pSessionInfo->Activated)
+	{
+		/* Sent the response packet */
+		SendLANPkt (&ResPkt);
+	}
+
+	return;
+}
+
+
+// /**
+//  * @fn  LANTimer
+//  * @brief This function handles the time out for lan connections.
+//  * @param None
+// **/
+// static
+// void*  LANTimer (void *pArg)
+// {
+// 	int *inst = (int*)pArg;
+// 	int BMCInst= *inst;
+// 	prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
+
+// 	while (1)
+// 	{
+// 		UpdateTimeout (BMCInst);
+// 		sleep (LAN_TIMER_INTERVAL);
+// 	}
+
+// 	return 0;
+// }
+
+
+static int SetIPv4Header(int socketID)
+{
+	uint8_t   	flag = 0;
+	uint8_t 	TimeToLive = 64;
+	//uint8_t		TypeOfService = 0;
+
+	if (setsockopt(socketID, IPPROTO_IP, IP_TTL,
+			&TimeToLive, sizeof(uint8_t)) == -1)
+	{
+		printf("LANIfc.c: Setsockopt(IP_TTL) Failed for UDP socket:");
+		return -1;
+	}
+
+	flag = 0;	/* Never send DF frames.  */
+	if (setsockopt(socketID, IPPROTO_IP, IP_MTU_DISCOVER,
+			&(flag), sizeof(uint8_t)) == -1)
+	{
+		printf("LANIfc.c: Setsockopt(IP_MTU_DISCOVER) Failed for UDP socket\n");
+		return -1;
+	}
+
+	// if (setsockopt(socketID, IPPROTO_IP, IP_TOS,
+	// 		&(pBMCInfo->LANCfs[ethIndex].Ipv4HdrParam.TypeOfService), sizeof(INT8U)) == -1)
+	// {
+	// 	printf("LANIfc.c: Setsockopt(IP_TOS) Failed for UDP socket\n");
+	// 	return -1;
+	// }
+
+	return 0;
+}
+

+ 86 - 0
app/bmc/lan/LANIfc.h

@@ -0,0 +1,86 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * LANIfc.h
+ * LAN Interface Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#ifndef LANIFC_H
+#define LANIFC_H
+#include <stdio.h>
+#include <stdint.h>
+#include "com_BmcType.h"
+#include "com_Message.h"
+#include "com_IPMI_LANIfc.h"
+
+
+/*** External Definitions ***/
+#define GRATUITOUS_ARP_REQUEST		5
+#define PCI_RST_INTR				6
+#define LAN_SMB_ALERT				6
+#define INIT_SMB					7
+#define LAN_ICTS_MODE				8
+#define VLAN_SMB_REQUEST			9
+#define LOOP_BACK_LAN_SMB_REQUEST	10
+#define LAN_IFC_READY				11
+
+#define LAN_CONFIG_IPV4_HEADER      12
+#define LAN_RMCP_PORT_CHANGE     13
+#define LAN_IFC_UP 1
+#define LAN_IFC_DOWN 0
+#define FLAG_SET 1
+#define FLAG_UNSET 0
+
+#pragma pack(1)
+
+typedef struct
+{
+    int 	Socket;
+    uint8_t   Valid;
+    time_t  Time;
+    uint8_t  IsLoopBackSocket;
+    uint8_t  IsFixedSocket;
+}  SocketTbl_T;
+
+#pragma pack()
+
+
+void *LANIfcTask (void *param);
+
+
+
+/**
+ * This variable is used to define if the packet
+ * is from VLAN channel or not 
+ */
+//extern uint8_t	g_IsPktFromVLAN;
+
+/**
+ * @defgroup lanifc LAN Interface Module
+ * LAN interface functions.
+ * @{
+**/
+// extern BOOL	ValidateUDPChkSum	(  UDPPseudoHdr_T* pUDPPseudoHdr,   UDPHdr_T* pUDPHdr);
+// extern BOOL	ValidateIPChkSum	(  IPHdr_T* pIPHdr);
+// extern uint16_t CalculateUDPChkSum (  UDPPseudoHdr_T* pUDPPseudoHdr,   UDPHdr_T* pUDPHdr);
+// extern uint16_t CalculateIPChkSum	(  IPHdr_T* pIPHdr);
+
+//extern int SendSOLPkt  (uint8_t* pSOLPkt, uint16_t Len);
+/** @} */
+
+#endif /* LANIFC_H */

+ 1224 - 0
app/bmc/lan/RMCP+.c

@@ -0,0 +1,1224 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * RMCP.c
+ * RMCP Message Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#include <stdio.h>
+#include <stdint.h>
+
+#include "com_Message.h"
+#include "com_IPMIDefs.h"
+#include "RMCP.h"
+#include "RMCP+.h"
+#include "Session.h"
+#include "LANIfc.h"
+#include "MD.h"
+#include "MD5_128.h"
+#include "main.h"
+
+#if IPMI20_SUPPORT == 1
+
+/*** Local definitions ***/
+#define AUTH_ALGORITHM                      00
+#define INTEGRITY_ALGORITHM                 01
+#define CONFIDENTIALITY_ALGORITHM           02
+
+#define MAX_ROLE_SUPPORTED                  0x05
+#define MAX_REM_CON_RAND_NO_LEN             0x10
+#define MAX_MGD_SYS_RAND_NO_LEN             0x10
+#define MAX_MGD_SYS_GUID_LEN                0x10
+#define MAX_HMAC_BUF_SIZE                   128
+#define RAKP1_HASH_SIZE                     20
+#define RAKP1_HASH_HMAC_MD5_SIZE            16
+#define RAKP1_HASH_HMAC_SHA256_SIZE  		32
+
+/* RSSP and RAKP Message Status Codes */
+#define SC_NO_ERROR                         0
+#define SC_INSUFFICIENT_RESOURCE            1
+#define SC_INV_SESSION_ID                   2
+#define SC_INV_PAYLOAD_TYPE                 3
+#define SC_INV_AUTH_ALGORITHM               4
+#define SC_INV_INTEGRITY_ALGORITHM          5
+#define SC_NO_MATCHED_AUTH_PAYLOAD          6
+#define SC_NO_MATCHED_INTEGRITY_PAYLOAD     7
+#define SC_INACTIVE_SESSION_ID              8
+#define SC_INV_ROLE                         9
+#define SC_UNAUTHORISED_ROLE                10
+#define SC_INSUFFICIENT_RESOURCE_AT_ROLE    11
+#define SC_INV_NAME_LEN                     12
+#define SC_UNAUTHORISED_NAME                13
+#define SC_UNAUTHORISED_GUID                14
+#define SC_INV_INTEGRITY_CHECK              15
+#define SC_INV_CONFIDENTIALITY_ALGORTHM     16
+#define SC_NO_CIPHER_SUITE_MATCH            17
+#define SC_ILLEGAL_OR_UNRECOGNIZED_PARAM    18
+
+/* Authentication Algorithm Numbers */
+#define RAKP_NONE                   0
+#define RAKP_HMAC_SHA1              1
+#define RAKP_HMAC_MD5	            2
+#define RAKP_HMAC_SHA256            3
+
+#define HASH_KEY1_CONST_SIZE                20
+#define HASH_KEY2_CONST_SIZE                20
+
+/**
+ * @var m_SIK
+ * @brief Session Key.
+**/
+static  _FAR_ INT8U m_SIK [SHA2_HASH_KEY_SIZE];
+
+
+/*----------------------------------------
+ * RSSPOpenSessionReq
+ *----------------------------------------*/
+int
+RSSPOpenSessionReq (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes, MiscParams_T *pParams, INT8U Channel, int BMCInst)
+{
+    _NEAR_  RSSPOpenSessionReq_T    *Req        =
+                                      (_NEAR_ RSSPOpenSessionReq_T*)pReq;
+    _NEAR_  RSSPOpenSessionRes_T    *Res        =
+                                      (_NEAR_ RSSPOpenSessionRes_T*)pRes;
+    _NEAR_  RSSPOpenSessionErrRes_T *ErrRes     =
+                                      (_NEAR_ RSSPOpenSessionErrRes_T*)pRes;
+    _FAR_   BMCInfo_t               *pBMCInfo   = 
+                                    &g_BMCInfo[BMCInst];
+    _FAR_   ChannelInfo_T           *pChannelInfo;
+    INT8U                           Role, i, id;
+    BOOL                            IsMatchReq      = FALSE;
+    BOOL                            TrackRollOver   = FALSE;
+    SessionInfo_T                   SessionInfo;
+    INT32U                          TempSessId;
+    INT8U                           CipherSuitePrivilage = 0;
+    INT8U                           EthIndex;
+    INT32U                          TrackRollOverSeq = SEQNUM_ROLLOVER;
+    unsigned int                    seed = 1; 
+
+
+    if(Channel == 0xFF)
+    {
+        Channel=GetLANChannel(Req->Reserved[0], BMCInst);
+    }
+    EthIndex= GetEthIndex(Channel, BMCInst);
+
+    if(0xff == EthIndex)
+    {
+        IPMI_WARNING("\n Invalid Channel number :%x",Channel);
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof (INT8U);
+    }
+
+    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+    /* Get information abt this channel */
+    pChannelInfo = getChannelInfo (Channel, BMCInst);
+    if (NULL == pChannelInfo)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        Res->StatusCode = SC_INSUFFICIENT_RESOURCE;
+        return sizeof (RSSPOpenSessionErrRes_T);
+    }
+
+    if(pChannelInfo->ActiveSession >= pChannelInfo->SessionLimit)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        /* Session limit reached*/
+        IPMI_WARNING ("RMCP+.c : OpenSessionReq - Session limit exceeded :%x\t%x BMCInst %x\n ",pChannelInfo->ActiveSession,pChannelInfo->SessionLimit,BMCInst);
+        Res->StatusCode = SC_INSUFFICIENT_RESOURCE;
+        return sizeof (RSSPOpenSessionErrRes_T);
+    }
+    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+
+    /* Get Role */
+    Role = Req->Role & 0x0F;
+
+    /* Fill Err Response to return, in case any error occurred */
+    ErrRes->Reserved = 0;
+    ErrRes->RemConSessionID = Req->RemConSessionID;
+
+    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex,WAIT_INFINITE);
+    if (GetNumOfUsedSessions(BMCInst) >= pBMCInfo->IpmiConfig.MaxSession)
+    {
+        if(FALSE == CleanSession(BMCInst))
+        {
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+            /* Session limit reached*/
+            IPMI_WARNING ("RMCP+.c : OpenSessionReq - Session limit exceeded\n");
+            Res->StatusCode = SC_INSUFFICIENT_RESOURCE;
+            return sizeof (RSSPOpenSessionErrRes_T);
+        }
+    }
+
+    /* Check Role  */
+    if (Role > MAX_ROLE_SUPPORTED)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /* Invalid Payload Type */
+        IPMI_WARNING ("RMCP+.c : OpenSessionReq - Invalid role\n");
+        Res->StatusCode = SC_INV_ROLE;
+        return sizeof (RSSPOpenSessionErrRes_T);
+    }
+
+    /*Check Payload Type */
+    if ((AUTH_ALGORITHM             != Req->Auth.PayloadType) ||
+        (INTEGRITY_ALGORITHM        != Req->Integrity.PayloadType) ||
+        (CONFIDENTIALITY_ALGORITHM  != Req->Confidentiality.PayloadType))
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /* Invalid Payload Type */
+        IPMI_WARNING ("RMCP+.c : OpenSessionReq - Invalid Payload\n");
+        Res->StatusCode = SC_INV_PAYLOAD_TYPE;
+        return sizeof (RSSPOpenSessionErrRes_T);
+    }
+
+    /* Search for the matching cipher suite id from Cipher suite record. if matching id found
+           check for for requested role/privilege is allowed for privilege level for the cipher suite */
+    for (i = 0, id = 0; i < MAX_CIPHER_SUITES_BYTES; i++, id++)
+    {
+        if (i * 5 + 1 > MAX_CIPHER_SUITES_BYTES)
+        {
+            break;
+        }
+
+        if (
+            (((Req->Auth.PayloadType 	     << 6) | (Req->Auth.Algorithm & 0x3F))     	 	== g_CipherRec [(i * 5) + 2]) &&
+            (((Req->Integrity.PayloadType    << 6) | (Req->Integrity.Algorithm & 0x3F))     == g_CipherRec [(i * 5) + 3]) &&
+            (((Req->Confidentiality.PayloadType<< 6) | (Req->Confidentiality.Algorithm & 0x3F))== g_CipherRec [(i * 5) + 4])
+           )
+        {
+            id = g_CipherRec[(i * 5) + 1];
+            /* The Cipher Suite ID is matched */
+            /* get the privilege level for the given cipher suite id, if id is even its lower nibble else upper nibble */
+            CipherSuitePrivilage = pBMCInfo->LANCfs[EthIndex].CipherSuitePrivLevels [(id/2)+1];
+            CipherSuitePrivilage = ((id % 2) == 0) ? (CipherSuitePrivilage & 0x0f) : ((CipherSuitePrivilage >> 4) & 0x0f) ;
+
+            if(CipherSuitePrivilage == 0)
+            {
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                Res->StatusCode = SC_NO_CIPHER_SUITE_MATCH;
+                return sizeof (RSSPOpenSessionErrRes_T);
+            }
+
+            /*if requested privilege level is greater than cipher suite id privilege level return errror*/
+            if ((CipherSuitePrivilage != 0) && (Role > CipherSuitePrivilage))
+            {
+                /* Invalid Payload Type */
+                //Res->StatusCode = SC_UNAUTHORISED_ROLE;
+                //return sizeof (RSSPOpenSessionErrRes_T);
+                Role = CipherSuitePrivilage;
+            }
+            break;
+        }
+    }
+    /* Role 0 indicates to find possible match */
+    if (0 == Role)
+    {
+        IsMatchReq  = TRUE;
+        Role        = MAX_ROLE_SUPPORTED;
+    }
+
+    /* Find Match */
+    do
+    {
+        Res->StatusCode = SC_NO_ERROR;
+
+        /*Check if requested authentication Algorithm supported **/
+        if (0 != Req->Auth.PayloadLen)
+        {
+            if ((sizeof (RSSPPayloadInfo_T) != Req->Auth.PayloadLen) ||
+                (0 == (pBMCInfo->RMCPPlus[EthIndex].Algorithm [Req->Auth.PayloadType] [Role] &
+                         (1 << Req->Auth.Algorithm))))
+            {
+                /* AuthAlgorithm not supported */
+                IPMI_DBG_PRINT ("RMCP+.c : OpenSessionReq - Authentication not supported \n");
+                Res->StatusCode = SC_NO_CIPHER_SUITE_MATCH;
+            }
+        }
+
+        /*Check if requested Integrity Algorithm supported  **/
+        if (0 != Req->Integrity.PayloadLen)
+        {
+            if ((sizeof (RSSPPayloadInfo_T) != Req->Integrity.PayloadLen) ||
+                (0 == (pBMCInfo->RMCPPlus[EthIndex].Algorithm [Req->Integrity.PayloadType] [Role] &
+                         (1 << Req->Integrity.Algorithm))))
+            {
+                /* Integrity Algorithm not supported */
+                IPMI_DBG_PRINT ("RMCP+.c : OpenSessionReq - Integrity not supported\n");
+                Res->StatusCode = SC_NO_CIPHER_SUITE_MATCH;
+            }
+        }
+
+        /*Check if requested Confidentiality Algorithm supported    **/
+        if (0 != Req->Confidentiality.PayloadLen)
+        {
+            if ((sizeof (RSSPPayloadInfo_T) != Req->Confidentiality.PayloadLen) ||
+                (0 == (pBMCInfo->RMCPPlus[EthIndex].Algorithm [Req->Confidentiality.PayloadType] [Role] &
+                         (1 << Req->Confidentiality.Algorithm))))
+            {
+                /* Confidentiality Algorithm not supported */
+                IPMI_DBG_PRINT ("RMCP+.c : OpenSessionReq - Confidentiality not supported \n");
+                Res->StatusCode = SC_NO_CIPHER_SUITE_MATCH;
+            }
+        }
+
+        if ((SC_NO_ERROR  == Res->StatusCode) &&
+            ((CipherSuitePrivilage == 0) || (Role <= CipherSuitePrivilage)))
+        {
+            /* Found Match */
+            break;
+        }
+
+    } while (IsMatchReq && Role--);
+
+    /* Return Err response */
+    if (Res->StatusCode != SC_NO_ERROR)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        IPMI_WARNING ("RMCP+.c : OpenSessionReq - Error Response\n");
+        return sizeof (RSSPOpenSessionErrRes_T);
+    }
+
+    if (GetNumOfActiveSessions (BMCInst) >= pBMCInfo->IpmiConfig.MaxSession)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /* No slot available */
+        Res->StatusCode = SC_INSUFFICIENT_RESOURCE;
+        return sizeof (RSSPOpenSessionErrRes_T);
+    }
+    /* Add Session Info */
+    _fmemset (&SessionInfo, 0, sizeof (SessionInfo_T));
+    /* Activated in ActivateSession Command */
+    SessionInfo.Activated       = FALSE;
+    SessionInfo.RemConSessionID = Req->RemConSessionID;
+    SessionInfo.MaxPrivilege = Role;
+
+    do{
+        /*generate 32 bit temp session Id*/
+        TempSessId = ((INT32U)rand_r(&seed) << 16) | rand_r (&seed); 
+    } while ((NULL != getSessionInfo (SESSION_ID_INFO, &TempSessId, BMCInst)) ||
+             (0 == TempSessId));
+
+    SessionInfo.SessionID               = TempSessId;
+    SessionInfo.Channel                 = Channel;
+    SessionInfo.AuthAlgorithm           = Req->Auth.Algorithm;
+    SessionInfo.IntegrityAlgorithm      = Req->Integrity.Algorithm;
+    SessionInfo.ConfidentialityAlgorithm = Req->Confidentiality.Algorithm;
+    if(pParams->IsPktFromLoopBack)
+    {
+        if(IPMITimeout > 0)
+        {
+            SessionInfo.TimeOutValue = (IPMITimeout+10);
+        }
+        else
+        {
+            /*If it is not defined the timeout values for loop back session should be 
+                    SESSION_TIMEOUT defined in config.make.ipmi (60 seconds) */
+            SessionInfo.TimeOutValue =  pBMCInfo->IpmiConfig.SessionTimeOut;
+        }
+        SessionInfo.IsLoopBack              = TRUE;
+    }
+    else
+        SessionInfo.TimeOutValue          = pBMCInfo->IpmiConfig.SessionTimeOut;
+    
+    if(pBMCInfo->IpmiConfig.SOLIfcSupport == 1)
+    {
+        if(SessionInfo.SessPyldInfo [PAYLOAD_SOL].Type == PAYLOAD_SOL)
+        {
+            SessionInfo.TimeOutValue = pBMCInfo->IpmiConfig.SOLSessionTimeOut;
+        }
+    }
+    
+    SessionInfo.UserId  = 0xff;
+    SessionInfo.SessPyldInfo [0].AuxConfig [0] =
+        ((0 != Req->Integrity.Algorithm) ? 0x40: 0x00) |
+        ((0 != Req->Confidentiality.Algorithm) ? 0x80: 0x00);
+    SessionInfo.InitialInboundSeq   = SEQNUM_ROLLOVER;
+    SessionInfo.InboundSeq  = 0x00;
+
+    for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
+    {
+        if(((SessionInfo.InitialInboundSeq - (i+1)) != 0) &&(TrackRollOver == FALSE))
+            SessionInfo.InboundTrac[i] = SessionInfo.InitialInboundSeq - (i+1);
+        else if(((SessionInfo.InitialInboundSeq - (i+1)) == 0) &&(TrackRollOver == FALSE))
+        {
+            SessionInfo.InboundTrac[i] = SessionInfo.InitialInboundSeq - (i+1);
+            TrackRollOver = TRUE;
+        }
+        else if(TrackRollOver == TRUE)
+        {
+            SessionInfo.InboundTrac[i] = TrackRollOverSeq;
+            TrackRollOverSeq--;
+        }
+    }
+
+    SessionInfo.InboundRecv = 0xFF; 
+    AddSession (&SessionInfo, BMCInst);
+
+    /* Load RSSP Open session Response */
+    Res->Role = Role;
+    Res->Reserved = 0x00;
+    Res->RemConSessionID    = Req->RemConSessionID;
+    Res->MgdSysSessionID    = SessionInfo.SessionID;
+
+    /* Auth Algorithm Details */
+    Res->Auth.PayloadType   = AUTH_ALGORITHM;
+    Res->Auth.Reserved1 = 0;
+    Res->Auth.PayloadLen    = sizeof (RSSPPayloadInfo_T);
+    Res->Auth.Algorithm     = Req->Auth.Algorithm;
+    memset(Res->Auth.Reserved2, 0x0, 3);
+
+    /* Integrity Algorithm Details */
+    Res->Integrity.PayloadType  = INTEGRITY_ALGORITHM;
+    Res->Integrity.Reserved1 = 0;
+    Res->Integrity.PayloadLen   = sizeof (RSSPPayloadInfo_T);
+    Res->Integrity.Algorithm    = Req->Integrity.Algorithm;
+    memset(Res->Integrity.Reserved2, 0x0, 3);
+
+    /* Confidentiality Algorithm Details */
+    Res->Confidentiality.PayloadType = CONFIDENTIALITY_ALGORITHM;
+    Res->Confidentiality.Reserved1 = 0;
+    Res->Confidentiality.PayloadLen  = sizeof (RSSPPayloadInfo_T);
+    Res->Confidentiality.Algorithm   = Req->Confidentiality.Algorithm;
+    memset(Res->Confidentiality.Reserved2, 0x0, 3);
+    
+    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+
+    return sizeof (RSSPOpenSessionRes_T);
+}
+
+
+/*----------------------------------------
+ * RAKPMsg1
+ *----------------------------------------*/
+int
+RAKPMsg1 (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes, MiscParams_T *pParams, INT8U Channel, int BMCInst)
+{
+    _NEAR_  RAKPMsg1Req_T       *Req     = (_NEAR_ RAKPMsg1Req_T*) pReq;
+    _NEAR_  RAKPMsg2Res_T       *Res     = (_NEAR_ RAKPMsg2Res_T*) pRes;
+    _NEAR_  RAKPMsg2ErrRes_T    *ErrRes  = (_NEAR_ RAKPMsg2ErrRes_T*) pRes;
+    _FAR_   SessionInfo_T       *pSessInfo;
+    _FAR_   ChannelUserInfo_T   *pChUserInfo;
+    _FAR_   ChannelInfo_T       *pChannelInfo;
+    _FAR_   UserInfo_T          *pUserInfo;
+    _FAR_   RAKPMsg1HMAC_T      *pMsghmac;
+    _FAR_   BMCInfo_t           *pBMCInfo = &g_BMCInfo[BMCInst];
+    INT8U   Index;
+    INT8U   AuthCodeLen = 0;
+    INT8U   Role;
+    INT32U  ManSysSessionID;
+    int     i;
+    unsigned int seed = 1;
+    INT8U PwdEncKey[MAX_SIZE_KEY + 1] = {0};
+
+    /*Validate Mgd session ID*/
+    Role                    = Req->Role & 0x0f;
+    ManSysSessionID         = Req->ManSysSessionID;
+    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex,WAIT_INFINITE);
+    pSessInfo               = getSessionInfo (SESSION_ID_INFO, (_FAR_ void*)&ManSysSessionID, BMCInst);
+    if (NULL == pSessInfo)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        IPMI_WARNING ("RMCP+.c : RAKPMsg1 - Invalid Session ID\n");
+        ErrRes->StatusCode  = SC_INV_SESSION_ID;
+        return sizeof (RAKPMsg2ErrRes_T);
+    }
+    /* In case of error, delete this session info */
+    pBMCInfo->LANConfig.DeleteThisLANSessionID = ManSysSessionID;
+
+    if(Channel == 0xFF)
+    {
+        Channel= pSessInfo->Channel;
+    }
+
+    ErrRes->RemConSessionID = pSessInfo->RemConSessionID;
+
+    /* Check Role  */
+    if (Role >  MAX_ROLE_SUPPORTED)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /* Invalid Role */
+        IPMI_WARNING ("RMCP+.c : RAKPMsg1 - Invalid Role\n");
+        Res->StatusCode = SC_INV_ROLE;
+        return sizeof (RAKPMsg2ErrRes_T);
+    }
+
+    /* Check User Name Length */
+    if (Req->UsrNameLen > MAX_USERNAME_LEN)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /* Invalid Name Len */
+        IPMI_WARNING ("RMCP+.c : RAKPMsg1 - Username len exceeded\n");
+        Res->StatusCode = SC_INV_NAME_LEN;
+        return sizeof (RAKPMsg2ErrRes_T);
+    }
+
+    /* Privilege for the session has to be assigned in RAKP1 only */
+    pSessInfo->Privilege = Role & 0xF;
+
+    /* Pad with NULL characters */
+    _fmemset (&Req->UsrName [Req->UsrNameLen], 0, MAX_USERNAME_LEN - Req->UsrNameLen);
+
+    pChannelInfo = getChannelInfo (Channel, BMCInst);
+    if (NULL == pChannelInfo)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /* InSufficient resources */
+        IPMI_WARNING ("RMCP+.c : RAKPMsg1 - Insufficient resource\n");
+        Res->StatusCode = SC_INSUFFICIENT_RESOURCE;
+        return sizeof (RAKPMsg2ErrRes_T);
+    }
+
+
+    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+    pSessInfo->Lookup = ((Req->Role & 0x10) >> 0x04);
+
+    if( pParams->IsPktFromLoopBack == TRUE  &&  Req->UsrName[0] == 0 )
+    {
+        pUserInfo = getUserIdInfo (NULL_USER, BMCInst);
+        pSessInfo->UserId = NULL_USER;
+        memset (pSessInfo->Password, 0, MAX_PASSWORD_LEN);
+    }
+    else
+    {
+        if (USER_ROLE_LOOKUP == pSessInfo->Lookup)
+        {
+        /* Get userInfo for the given userName and privilege */
+        pChUserInfo = getChUserPrivInfo ((_NEAR_ char *)Req->UsrName, Role, &Index,
+        pChannelInfo->ChannelUserInfo, BMCInst);
+
+        /* If user not found  */
+        if (NULL == pChUserInfo)
+        {
+            /* Invalid user     */
+            IPMI_WARNING ("RMCP+.c : RAKPMsg1 - user_priv - User not found : %s\n", (_NEAR_ char *)Req->UsrName);
+
+            if ( 0 != AddLoginEvent( 0xFF, Req->UsrName, EVENT_LOGIN_FAILURE, BMCInst ) )
+            {
+                    TCRIT("Problem while adding Log record \n");
+            }
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+            Res->StatusCode = SC_UNAUTHORISED_NAME;
+            return sizeof (RAKPMsg2ErrRes_T);
+        }
+
+        /* Check Role  */
+        if (pChUserInfo->AccessLimit == 0xF )
+        {
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+            /* Invalid Role */
+            IPMI_WARNING ("RMCP+.c : RAKPMsg1 - user_priv - Invalid Role\n");
+            Res->StatusCode = SC_INV_ROLE;
+            return sizeof (RAKPMsg2ErrRes_T);
+        }
+
+        //we cannot assign the pSessInfo->privilege here..this will cause RAKP3 integrity check to fail
+        //this is because the client will do integrity with the requested role rather than the max permissible role
+        // which we set here. client has no way of knowing at that time
+        //pSessInfo->Privilege = Role;
+        }
+        else /* if (NAME_ONLY_LOOKUP == pSessInfo->Lookup) */
+        {
+            /* Get userInfo for the given userName*/
+            pChUserInfo = getChUserInfo ((_NEAR_ char *)Req->UsrName, &Index,
+            pChannelInfo->ChannelUserInfo, BMCInst);
+            /* If user not found  */
+            if (NULL == pChUserInfo)
+            {
+                /* Invalid user     */
+                IPMI_WARNING ("RMCP+.c : RAKPMsg1 - name_only - User not found\n");
+
+                if ( 0 != AddLoginEvent( 0xFF, Req->UsrName, EVENT_LOGIN_FAILURE, BMCInst ))
+                {
+                    TCRIT("Problem while adding Log record \n");
+                }
+
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                Res->StatusCode = SC_UNAUTHORISED_NAME;
+                return sizeof (RAKPMsg2ErrRes_T);
+            }
+
+            /* Check Role  */
+            if (pChUserInfo->AccessLimit == 0xF )
+            {
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                /* Invalid Role */
+                IPMI_WARNING ("RMCP+.c : RAKPMsg1 - name_only - Invalid Role\n");
+                Res->StatusCode = SC_INV_ROLE;
+                return sizeof (RAKPMsg2ErrRes_T);
+            }
+        }
+
+        pUserInfo = getUserIdInfo (pChUserInfo->UserId, BMCInst);
+        if (pUserInfo == NULL || FALSE == pUserInfo->UserStatus)
+        {
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+            /*user name not enabled*/
+            IPMI_WARNING ("RMCP+.c : RAKPMsg1 - User not found in database\n");
+            Res->StatusCode = SC_UNAUTHORISED_NAME;
+            return sizeof (RAKPMsg2ErrRes_T);
+        }
+
+        /* Load UserId Session Info */
+        pSessInfo->UserId = (INT8U)pChUserInfo->UserId;
+        if (g_corefeatures.userpswd_encryption == ENABLED)
+        {
+            /* Get Encryption Key from the MBMCInfo_t structure */
+            memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
+
+            if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pChUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S*)pSessInfo->Password, MAX_PASSWORD_LEN, PwdEncKey))
+            {
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                TCRIT("Error in decrypting the user password for user ID:%d. .\n", pChUserInfo->UserId);
+                Res->StatusCode  = SC_INSUFFICIENT_RESOURCE;
+                return sizeof(RAKPMsg2ErrRes_T);
+            }
+        }
+        else
+        {
+        	_fmemcpy (pSessInfo->Password, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
+        }
+    }
+
+    /* Check for Empty password login */
+    if ( ENABLED == g_corefeatures.disable_empty_passwd_login && NULL_USER != pSessInfo->UserId && 0 == pSessInfo->Password[0])
+    {
+        IPMI_WARNING("RMCP+c : RAKPMsg1 - Empty Password Login is not allowed \n");
+
+        if ( 0 != AddLoginEvent(pSessInfo->UserId, NULL, EVENT_LOGIN_FAILURE, BMCInst))
+        {
+             TCRIT("Problem while adding Log record \n");
+        }
+
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        Res->StatusCode = SC_ILLEGAL_OR_UNRECOGNIZED_PARAM;
+        return sizeof(RAKPMsg2ErrRes_T);
+    }
+
+    /* Check for Default Empty password login */
+    if(ENABLED != g_corefeatures.allow_default_empty_passwd_login && NULL_USER != pSessInfo->UserId && 0 == pSessInfo->Password[0] && pUserInfo->UserPasswdConfigured == 0)
+    {
+        TDBG("RMCP+c : RAKPMsg1 - User Password is not yet configured; Default Empty Password Login is not allowed \n");
+        if ( 0 != AddLoginEvent(pSessInfo->UserId, NULL, EVENT_LOGIN_FAILURE, BMCInst))
+        {
+             TCRIT("Problem while adding Log record \n");
+        }
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        Res->StatusCode = SC_ILLEGAL_OR_UNRECOGNIZED_PARAM;
+        return sizeof(RAKPMsg2ErrRes_T);
+    }
+
+    if(FindUserLockStatus(pSessInfo->UserId, Channel, BMCInst) != 0)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        IPMI_WARNING("RMCP+c : RAKPMsg1 - User is Locked \n");
+        /* As of now sending Invalid Role for bad password*/
+        Res->StatusCode = SC_INV_ROLE;
+        return sizeof(RAKPMsg2ErrRes_T);
+    }
+
+    /* Check the number of active sessions */
+    if (pUserInfo->CurrentSession >= pUserInfo->MaxSession)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        /*can't accept any more session for this user*/
+        Res->StatusCode = SC_INSUFFICIENT_RESOURCE;
+        return  sizeof (RAKPMsg2ErrRes_T);
+    }
+    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+
+    /* Load Response */
+    Res->StatusCode = SC_NO_ERROR;
+    /* Store the Remote Console Random number in SessionInfo */
+    _fmemcpy (pSessInfo->RemConRandomNo, Req->RemConRandomNo,
+              MAX_REM_CON_RAND_NO_LEN);
+
+    for (i = 0 ; i < MAX_MGD_SYS_RAND_NO_LEN; i++)
+    {
+        Res->ManSysRandomNo [i] = rand_r (&seed);
+    }
+
+    /* Store the Managed System Random number in SessionInfo */
+    _fmemcpy (pSessInfo->MgdSysRandomNo, Res->ManSysRandomNo,
+              MAX_MGD_SYS_RAND_NO_LEN);
+
+    /* Copy the System GUID */
+    _fmemcpy (Res->ManSysGUID, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
+
+    /* Key Exchange Auth Code  */
+    switch (pSessInfo->AuthAlgorithm)
+    {
+        case RAKP_NONE:
+            AuthCodeLen = 0;
+            break;
+
+        case RAKP_HMAC_SHA1:
+            {
+                INT8U PasswdLen = 0;
+
+                pMsghmac                    = (_FAR_ RAKPMsg1HMAC_T*)pBMCInfo->LANConfig.HmacInBuf;
+                pMsghmac->RemConSessionID   = pSessInfo->RemConSessionID;
+                pMsghmac->MgdSysSessionID   = pSessInfo->SessionID;
+                /* Copy Random no.s  and GUID */
+                _fmemcpy (pMsghmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+                _fmemcpy (pMsghmac->MgdSysRandNo, pSessInfo->MgdSysRandomNo, 16);
+                _fmemcpy (pMsghmac->MgdSysGUID, Res->ManSysGUID, MAX_MGD_SYS_GUID_LEN);
+
+                pMsghmac->Role          = Req->Role;
+                pMsghmac->UsrNameLen    = Req->UsrNameLen;
+                _fmemcpy (pMsghmac->UsrName, Req->UsrName, Req->UsrNameLen);
+
+                PasswdLen = _fstrlen ((_FAR_ char*)pSessInfo->Password);
+                PasswdLen = (PasswdLen > MAX_PASSWORD_LEN) ?
+                            MAX_PASSWORD_LEN : PasswdLen;
+                hmac_sha1 ((INT8U *)pSessInfo->Password, PasswdLen, (INT8U *)pBMCInfo->LANConfig.HmacInBuf,
+                           (sizeof (RAKPMsg1HMAC_T) - MAX_USERNAME_LEN + Req->UsrNameLen),
+                           (INT8U *)&pRes [sizeof (RAKPMsg2Res_T)], RAKP1_HASH_SIZE);
+                AuthCodeLen = RAKP1_HASH_SIZE;
+                break;
+            }
+
+        case RAKP_HMAC_MD5:
+            {
+                INT8U PasswdLen = 0;
+
+                pMsghmac                    = (_FAR_ RAKPMsg1HMAC_T*)pBMCInfo->LANConfig.HmacInBuf;
+                pMsghmac->RemConSessionID   = pSessInfo->RemConSessionID;
+                pMsghmac->MgdSysSessionID   = pSessInfo->SessionID;
+                /* Copy Random no.s  and GUID */
+                _fmemcpy (pMsghmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+                _fmemcpy (pMsghmac->MgdSysRandNo, pSessInfo->MgdSysRandomNo, 16);
+                _fmemcpy (pMsghmac->MgdSysGUID, Res->ManSysGUID, MAX_MGD_SYS_GUID_LEN);
+
+                pMsghmac->Role          = Req->Role;
+                pMsghmac->UsrNameLen    = Req->UsrNameLen;
+                _fmemcpy (pMsghmac->UsrName, Req->UsrName, Req->UsrNameLen);
+
+                PasswdLen = _fstrlen ((_FAR_ char*)pSessInfo->Password);
+                PasswdLen = (PasswdLen > MAX_PASSWORD_LEN) ?
+                            MAX_PASSWORD_LEN : PasswdLen;
+                hmac_md5(pSessInfo->Password, PasswdLen, pBMCInfo->LANConfig.HmacInBuf,
+                           (sizeof (RAKPMsg1HMAC_T) - MAX_USERNAME_LEN + Req->UsrNameLen),
+                           &pRes [sizeof (RAKPMsg2Res_T)], RAKP1_HASH_HMAC_MD5_SIZE);
+                AuthCodeLen = RAKP1_HASH_HMAC_MD5_SIZE;
+                break;
+            }
+
+        case RAKP_HMAC_SHA256:
+			{
+        		INT8U PasswdLen = 0;
+
+         		pMsghmac                    = (_FAR_ RAKPMsg1HMAC_T*)pBMCInfo->LANConfig.HmacInBuf;
+                pMsghmac->RemConSessionID   = pSessInfo->RemConSessionID;
+                pMsghmac->MgdSysSessionID   = pSessInfo->SessionID;
+                /* Copy Random nos  and GUID */
+				_fmemcpy (pMsghmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+				_fmemcpy (pMsghmac->MgdSysRandNo, pSessInfo->MgdSysRandomNo, 16);
+				_fmemcpy (pMsghmac->MgdSysGUID, Res->ManSysGUID, MAX_MGD_SYS_GUID_LEN);
+
+				pMsghmac->Role          = Req->Role;
+				pMsghmac->UsrNameLen    = Req->UsrNameLen;
+				_fmemcpy (pMsghmac->UsrName, Req->UsrName, Req->UsrNameLen);
+
+				PasswdLen = _fstrlen ((_FAR_ char*)pSessInfo->Password);
+				PasswdLen = (PasswdLen > MAX_PASSWORD_LEN) ?
+								MAX_PASSWORD_LEN : PasswdLen;
+
+        		hmac_sha256(pSessInfo->Password, PasswdLen, pBMCInfo->LANConfig.HmacInBuf,
+        			 (sizeof (RAKPMsg1HMAC_T) - MAX_USERNAME_LEN + Req->UsrNameLen),
+        	               &pRes [ sizeof (RAKPMsg2Res_T)], RAKP1_HASH_HMAC_SHA256_SIZE);
+				AuthCodeLen = RAKP1_HASH_HMAC_SHA256_SIZE;
+                break;
+           	}        	
+			
+        default:
+            IPMI_WARNING ("RMCP+.c : RAKPMsg1 - Invalid Authentication\n");
+            AuthCodeLen = 0;
+    }
+
+    pBMCInfo->LANConfig.DeleteThisLANSessionID = 0;
+    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+
+    return sizeof (RAKPMsg2Res_T) + AuthCodeLen;
+}
+
+
+/*----------------------------------------
+ * RAKPMsg3
+ *----------------------------------------*/
+int
+RAKPMsg3 (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes, MiscParams_T *pParams,INT8U Channel, int BMCInst)
+{
+    _NEAR_  RAKPMsg3Req_T       *Req     = (_NEAR_ RAKPMsg3Req_T*)pReq;
+    _NEAR_  RAKPMsg4Res_T       *Res     = (_NEAR_ RAKPMsg4Res_T*)pRes;
+    _FAR_   SessionInfo_T       *pSessInfo;
+    _NEAR_  INT8U               *pKeyXchgCode;
+    _NEAR_  SIKhmac_T           *pSIKhmac;
+    _FAR_   Msg3hmac_T          *pMsg3hmac;
+    _FAR_   UserInfo_T          *pUserInfo;
+    _FAR_   RAKPMsg4hmac_T      *pMsg4hmac;
+    _FAR_   ChannelInfo_T       *pChannelInfo;
+    _FAR_   ChannelUserInfo_T   *pChUserInfo;
+    _FAR_   BMCInfo_t           *pBMCInfo = &g_BMCInfo[BMCInst];
+            INT8U               TempKey [HASH_KEY1_CONST_SIZE];
+            INT8U               TempKey2 [HASH_KEY2_CONST_SIZE];
+            INT8U               UserPasswdLen=0;
+            int                 i;
+            INT8U               ResIntigrityKeyLen=0;
+            INT8U               Index;
+            INT8U               EthIndex;
+            INT8U               UserPswd [MAX_PASSWORD_LEN];
+            INT32U              SessionID;
+            INT8U PwdEncKey[MAX_SIZE_KEY + 1] = {0};
+
+    SessionID = Req->ManSysSessionID;
+    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex,WAIT_INFINITE);
+    pSessInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
+    /* In case of error, delete this session info */
+    pBMCInfo->LANConfig.DeleteThisLANSessionID = Req->ManSysSessionID;
+
+    /* Check if Management System SessionID */
+    if (NULL == pSessInfo)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid Session ID\n");
+        Res->StatusCode = SC_INV_SESSION_ID;
+        return sizeof (RAKPMsg4Res_T);
+    }
+
+    /* Check if previous transactions caused an error */
+    if (Req->StatusCode !=  SC_NO_ERROR)
+    {
+        if(Req->StatusCode == SC_INV_INTEGRITY_CHECK)
+        {
+            OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+            LockUser(pSessInfo->UserId,Channel, BMCInst);
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        }
+        IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid Status\n");
+
+        if ( 0 != AddLoginEvent( pSessInfo->UserId, NULL, EVENT_LOGIN_FAILURE, BMCInst ))
+        {
+            IPMI_WARNING("Problem while adding Log record \n");
+        }
+
+        Res->StatusCode = Req->StatusCode;
+        DeleteSession(pSessInfo,BMCInst);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        return 0;
+    }
+
+    UnlockUser(pSessInfo->UserId,Channel,BMCInst);
+
+    if(Channel == 0xFF)
+    {
+        Channel= pSessInfo->Channel;
+    }
+
+    EthIndex= GetEthIndex(Channel, BMCInst);
+
+    if(0xff == EthIndex)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof (INT8U);
+    }
+
+    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+    /* Get User Info */
+    pUserInfo = getUserIdInfo((INT8U)pSessInfo->UserId, BMCInst);
+    if (NULL == pUserInfo)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        IPMI_WARNING ("RMCP+.c : RAKPMsg3 - User not found\n");
+        Res->StatusCode = SC_UNAUTHORISED_NAME;
+        return sizeof (RAKPMsg4Res_T);
+    }
+
+    if (g_corefeatures.userpswd_encryption == ENABLED)
+    {
+        /* Get Encryption Key from the MBMCInfo_t structure */
+            memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
+
+        if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pSessInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, (char *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
+        {
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+            IPMI_ERROR("Error in decrypting the user password for user ID:%d. .\n", pSessInfo->UserId);
+            Res->StatusCode = CC_UNSPECIFIED_ERR;
+            return sizeof(RAKPMsg4Res_T);
+        }
+    }
+    else
+    {
+    	_fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
+    }
+
+    UserPasswdLen = _fstrlen ((_FAR_ char*)UserPswd);
+    UserPasswdLen = (UserPasswdLen > MAX_PASSWORD_LEN) ?
+                    MAX_PASSWORD_LEN : UserPasswdLen;
+
+    /* Check for Key Exchange Auth Code */
+    pKeyXchgCode = (_FAR_ INT8U*)(pReq + sizeof (RAKPMsg3Req_T));
+
+    /*Construct hmac to check Auth code */
+    pMsg3hmac = (_FAR_	Msg3hmac_T*) &pBMCInfo->LANConfig.HmacInBuf;
+    _fmemcpy (pMsg3hmac->MgdSysRandNo, pSessInfo->MgdSysRandomNo, 16);
+    pMsg3hmac->RemConSessionID  = pSessInfo->RemConSessionID;
+    pMsg3hmac->Role             = pSessInfo->Privilege | (pSessInfo->Lookup << 4);
+    pMsg3hmac->UsrNameLen       = _fstrlen ((_FAR_ char*)pUserInfo->UserName);
+    pMsg3hmac->UsrNameLen        = (pMsg3hmac->UsrNameLen > MAX_USERNAME_LEN) ?
+                                        MAX_USERNAME_LEN : pMsg3hmac->UsrNameLen;
+
+    _fmemcpy ((_FAR_ char*)pMsg3hmac->UsrName,
+          (_FAR_ char*)pUserInfo->UserName, pMsg3hmac->UsrNameLen);
+
+    /* Key Exchange Auth Code  */
+    switch (pSessInfo->AuthAlgorithm)
+    {
+        case RAKP_NONE:
+            break;
+
+        case RAKP_HMAC_SHA1:
+            hmac_sha1 ((INT8U *)UserPswd, UserPasswdLen, (INT8U *)pBMCInfo->LANConfig.HmacInBuf,
+                       sizeof (Msg3hmac_T) - (16 - pMsg3hmac->UsrNameLen),
+                       (INT8U *)&pRes [ sizeof (RAKPMsg4Res_T)], RAKP1_HASH_SIZE);
+
+            if (0 != _fmemcmp (pKeyXchgCode, &pRes [sizeof (RAKPMsg4Res_T)], RAKP1_HASH_SIZE))
+            {
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid integrity check\n");
+                Res->StatusCode = SC_INV_INTEGRITY_CHECK;
+                return sizeof (RAKPMsg4Res_T);
+            }
+            break;
+
+        case RAKP_HMAC_MD5:
+            hmac_md5(UserPswd, UserPasswdLen, pBMCInfo->LANConfig.HmacInBuf,
+                       sizeof (Msg3hmac_T) - (MAX_USERNAME_LEN - pMsg3hmac->UsrNameLen),
+                       &pRes [ sizeof (RAKPMsg4Res_T)], RAKP1_HASH_HMAC_MD5_SIZE);
+
+            if (0 != _fmemcmp (pKeyXchgCode, &pRes [sizeof (RAKPMsg4Res_T)], RAKP1_HASH_HMAC_MD5_SIZE))
+            {
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid integrity check\n");
+                Res->StatusCode = SC_INV_INTEGRITY_CHECK;
+                return sizeof (RAKPMsg4Res_T);
+            }
+            break;
+
+        case RAKP_HMAC_SHA256:
+        	hmac_sha256(pSessInfo->Password, UserPasswdLen, pBMCInfo->LANConfig.HmacInBuf,
+        		 sizeof (Msg3hmac_T) - (MAX_USERNAME_LEN - pMsg3hmac->UsrNameLen),
+                       &pRes [ sizeof (RAKPMsg4Res_T)], RAKP1_HASH_HMAC_SHA256_SIZE);
+        	 if (0 != _fmemcmp (pKeyXchgCode, &pRes [sizeof (RAKPMsg4Res_T)], RAKP1_HASH_HMAC_SHA256_SIZE))
+                {
+                    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+                    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+                    IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid integrity check\n");
+                    Res->StatusCode = SC_INV_INTEGRITY_CHECK;
+                    return sizeof (RAKPMsg4Res_T);
+                }
+                break;        
+
+        default:
+            IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid Authentication\n");
+    }
+
+    /*Construct SIK to send the Integrity check */
+    memset(pBMCInfo->LANConfig.HmacInBuf,0,sizeof(pBMCInfo->LANConfig.HmacInBuf));
+    memset(pBMCInfo->LANConfig.SIK,0,sizeof(pBMCInfo->LANConfig.SIK));
+
+    pSIKhmac = (_FAR_  SIKhmac_T*) &pBMCInfo->LANConfig.HmacInBuf;
+
+    _fmemcpy (pSIKhmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+    _fmemcpy (pSIKhmac->MgdSysRandNo, pSessInfo->MgdSysRandomNo, 16);
+    pSIKhmac->Role = pSessInfo->Privilege | (pSessInfo->Lookup << 4) ;
+    pSIKhmac->UsrNameLen = _fstrlen ((_FAR_ char*)pUserInfo->UserName);
+    pSIKhmac->UsrNameLen = (pSIKhmac->UsrNameLen > MAX_USERNAME_LEN) ?
+                           MAX_USERNAME_LEN : pSIKhmac->UsrNameLen;
+    _fmemcpy ((_FAR_ char*)pSIKhmac->UsrName,
+              (_FAR_ char*)pUserInfo->UserName, pSIKhmac->UsrNameLen);
+
+    for (i = 0; i < HASH_KEY_LEN; i++)
+    {
+        if (pBMCInfo->RMCPPlus[EthIndex].KGHashKey [i] != 0)
+        {
+            break;
+        }
+    }
+
+    switch(pSessInfo->AuthAlgorithm)
+    {
+        case RAKP_NONE:
+             break;
+
+        case RAKP_HMAC_SHA1: 
+        {
+            // Encryption key must not be used for packets from VLAN or Loopback.
+        #ifdef  LAN_RESTRICTIONS_BYPASS_FOR_LOOPBACK_AND_VLAN
+            if ((i < HASH_KEY_LEN) && !(pParams->IsPktFromVLAN || pParams->IsPktFromLoopBack) )
+        #else
+            if ((i < HASH_KEY_LEN))
+        #endif
+            {
+                /* Use the KG (BMC Key set through SetChSecurityKeys command) Key */
+                hmac_sha1 ((INT8U *)pBMCInfo->RMCPPlus[EthIndex].KGHashKey, HASH_KEY_LEN, (INT8U *)pBMCInfo->LANConfig.HmacInBuf,
+                                    (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen),
+                                    (INT8U *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE);
+            }
+            else
+            {
+                /* Use the KUID (User Password) Key */
+                hmac_sha1 ((INT8U *)UserPswd, UserPasswdLen, (INT8U *)pBMCInfo->LANConfig.HmacInBuf,
+                                    (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen),
+                                    (INT8U *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE);
+            }
+
+            /* Create Key1 & Key2 for Rest of packet Integrity & Encryption */
+            _fmemset (TempKey, 1, HASH_KEY1_CONST_SIZE);
+            hmac_sha1 ((INT8U *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, (INT8U *)TempKey, HASH_KEY1_CONST_SIZE,
+                                    (INT8U *)pSessInfo->Key1, HASH_KEY1_SIZE);
+            _fmemset (TempKey2, 2, HASH_KEY2_CONST_SIZE);
+            hmac_sha1 ((INT8U *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, (INT8U *)TempKey2, HASH_KEY2_CONST_SIZE,
+                                    (INT8U *)pSessInfo->Key2, HASH_KEY2_SIZE);
+
+            /* Construct HMAC to send the Integrity check value using SIK got from prev hmac*/
+            pMsg4hmac = (_FAR_ RAKPMsg4hmac_T*) &pBMCInfo->LANConfig.HmacInBuf;
+            _fmemcpy (pMsg4hmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+            pMsg4hmac->MgdSysSessionID = pSessInfo->SessionID;
+            /*Get System GUID */
+            _fmemcpy (pMsg4hmac->MgdSysGUID, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
+            hmac_sha1 ((INT8U *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, (INT8U *)pBMCInfo->LANConfig.HmacInBuf, sizeof (RAKPMsg4hmac_T),
+                                    (INT8U *)&pRes [sizeof (RAKPMsg4Res_T)], HASH_KEY1_CONST_SIZE);
+            ResIntigrityKeyLen = HMAC_SHA1_96_LEN;
+            break;
+        }
+
+        case RAKP_HMAC_MD5:
+            {
+            #ifdef  LAN_RESTRICTIONS_BYPASS_FOR_LOOPBACK_AND_VLAN
+                if ((i < HASH_KEY_LEN) && !(pParams->IsPktFromVLAN || pParams->IsPktFromLoopBack) )
+            #else
+                if ((i < HASH_KEY_LEN))
+            #endif
+                {
+                    /* Use the KG (BMC Key set through SetChSecurityKeys command) Key */
+                    hmac_md5 (pBMCInfo->RMCPPlus[EthIndex].KGHashKey, HASH_KEY_LEN, pBMCInfo->LANConfig.HmacInBuf,
+                                            (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen),
+                                            pBMCInfo->LANConfig.SIK, SESSION_HMAC_MD5_I_KEY_SIZE);
+                }
+                else
+                {
+                    /* Use the KUID (User Password) Key */
+                    hmac_md5 (UserPswd, UserPasswdLen, pBMCInfo->LANConfig.HmacInBuf,
+                                    (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen),
+                                    pBMCInfo->LANConfig.SIK, SESSION_HMAC_MD5_I_KEY_SIZE);
+                }
+    
+                /* Create Key1 & Key2 for Rest of packet Integrity & Encryption */
+                _fmemset (TempKey, 1, HASH_KEY1_CONST_SIZE);
+                hmac_md5 (pBMCInfo->LANConfig.SIK, SESSION_HMAC_MD5_I_KEY_SIZE, TempKey, HASH_KEY1_CONST_SIZE,
+                                pSessInfo->Key1, SESSION_HMAC_MD5_I_KEY_SIZE);
+                _fmemset (TempKey2, 2, HASH_KEY2_CONST_SIZE);
+                hmac_md5 (pBMCInfo->LANConfig.SIK, SESSION_HMAC_MD5_I_KEY_SIZE, TempKey2, HASH_KEY2_CONST_SIZE,
+                                pSessInfo->Key2, SESSION_HMAC_MD5_I_KEY_SIZE);
+
+                /* Construct HMAC to send the Integrity check value using SIK got from prev hmac*/
+                pMsg4hmac = (_FAR_ RAKPMsg4hmac_T*) &pBMCInfo->LANConfig.HmacInBuf;
+                _fmemcpy (pMsg4hmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+                pMsg4hmac->MgdSysSessionID = pSessInfo->SessionID;
+                /*Get System GUID */
+                _fmemcpy (pMsg4hmac->MgdSysGUID, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
+                hmac_md5 (pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, pBMCInfo->LANConfig.HmacInBuf, sizeof (RAKPMsg4hmac_T),
+                &pRes [sizeof (RAKPMsg4Res_T)], SESSION_HMAC_MD5_I_KEY_SIZE);
+                ResIntigrityKeyLen = HMAC_MD5_LEN;
+            }
+            break;
+
+        
+ 
+#if 0   //algorithm not specified in IPMI spec, to be removed after review         
+        case AUTH_MD5_128:
+            {
+                // Encryption key must not be used for packets from VLAN or Loopback.
+            #ifdef  LAN_RESTRICTIONS_BYPASS_FOR_LOOPBACK_AND_VLAN
+                if ((i < HASH_KEY_LEN) && !(pParams->IsPktFromVLAN || pParams->IsPktFromLoopBack) )
+            #else
+                if ((i < HASH_KEY_LEN))
+            #endif
+                {
+                    /* Use the KG (BMC Key set through SetChSecurityKeys command) Key */
+                    MD5_128 ((char *)pBMCInfo->RMCPPlus[EthIndex].KGHashKey, HASH_KEY_LEN, (char *)pBMCInfo->LANConfig.HmacInBuf,
+                                (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen),
+                                (char *)pBMCInfo->LANConfig.SIK, SESSION_MD5_KEY_SIZE);
+                }
+                else
+                {
+                    /* Use the KUID (User Password) Key */
+                    MD5_128 ((char *)pUserInfo->UserPassword, UserPasswdLen, (char *)pBMCInfo->LANConfig.HmacInBuf,
+                                (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen), (char *)pBMCInfo->LANConfig.SIK, SESSION_MD5_KEY_SIZE);
+                }
+
+                /* Create Key1 & Key2 for Rest of packet Integrity & Encryption */
+                _fmemset (TempKey, 1, HASH_KEY1_CONST_SIZE);
+                MD5_128 ((char *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, (char *)TempKey, HASH_KEY1_CONST_SIZE,
+                                (char *)pSessInfo->Key1, SESSION_MD5_KEY_SIZE);
+                _fmemset (TempKey2, 2, HASH_KEY2_CONST_SIZE);
+                MD5_128 ((char *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, (char *)TempKey2, HASH_KEY2_CONST_SIZE,
+                                (char *)pSessInfo->Key2, SESSION_MD5_KEY_SIZE);
+
+                /* Construct HMAC to send the Integrity check value using SIK got from prev hmac*/
+                pMsg4hmac = (_FAR_ RAKPMsg4hmac_T*) &pBMCInfo->LANConfig.HmacInBuf;
+                _fmemcpy (pMsg4hmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+                pMsg4hmac->MgdSysSessionID = pSessInfo->SessionID;
+
+                /*Get System GUID */
+                _fmemcpy (pMsg4hmac->MgdSysGUID, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
+                MD5_128 ((char *)pBMCInfo->LANConfig.SIK, SESSION_INTEGRITY_KEY_SIZE, (char *)pBMCInfo->LANConfig.HmacInBuf, sizeof (RAKPMsg4hmac_T),
+                                (char *)&pRes [sizeof (RAKPMsg4Res_T)], SESSION_MD5_KEY_SIZE);
+                ResIntigrityKeyLen = MD5_LEN;
+                break;
+            }
+#endif           
+            
+	case RAKP_HMAC_SHA256:
+	{
+		// Encryption key must not be used for packets from VLAN or Loopback.
+		#ifdef	LAN_RESTRICTIONS_BYPASS_FOR_LOOPBACK_AND_VLAN
+			if ((i < HASH_KEY_LEN) && !(pParams->IsPktFromVLAN || pParams->IsPktFromLoopBack) )
+		#else
+			if ((i < HASH_KEY_LEN))
+		#endif
+			{
+				/* Use the KG (BMC Key set through SetChSecurityKeys command) Key */
+				hmac_sha256((unsigned char *)pBMCInfo->RMCPPlus[EthIndex].KGHashKey, HASH_KEY_LEN, (unsigned char *)pBMCInfo->LANConfig.HmacInBuf,
+					   (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen),
+				 (unsigned char *)m_SIK, SHA2_HASH_KEY_SIZE);
+			}
+			else
+			{
+				/* Use the KUID (User Password) Key */
+				hmac_sha256 ((unsigned char *)UserPswd, UserPasswdLen, (unsigned char *)pBMCInfo->LANConfig.HmacInBuf,
+			   (sizeof (SIKhmac_T) - 16 + pSIKhmac->UsrNameLen), (unsigned char *)m_SIK, SHA2_HASH_KEY_SIZE);
+					
+			}
+
+		/* Create Key1 & Key2 for Rest of packet Integrity & Encryption */
+				_fmemset (TempKey, 1, HASH_KEY1_CONST_SIZE);
+				hmac_sha256 (m_SIK, SHA2_HASH_KEY_SIZE, TempKey, HASH_KEY1_CONST_SIZE,
+ 			      pSessInfo->Key1, SHA2_HASH_KEY_SIZE);
+				_fmemset (TempKey2, 2, HASH_KEY2_CONST_SIZE);
+				  hmac_sha256 (m_SIK, SHA2_HASH_KEY_SIZE, TempKey2, HASH_KEY2_CONST_SIZE,
+ 			     pSessInfo->Key2, SHA2_HASH_KEY_SIZE);
+       /* Construct HMAC to send the Integrity check value using SIK got from prev hmac*/
+			 pMsg4hmac = (_FAR_ RAKPMsg4hmac_T*) &pBMCInfo->LANConfig.HmacInBuf;
+			 _fmemcpy (pMsg4hmac->RemConRandNo, pSessInfo->RemConRandomNo, 16);
+			pMsg4hmac->MgdSysSessionID = pSessInfo->SessionID;
+			 /*Get System GUID */
+			 _fmemcpy (pMsg4hmac->MgdSysGUID, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
+			 hmac_sha256 (m_SIK, SHA2_HASH_KEY_SIZE, pBMCInfo->LANConfig.HmacInBuf, sizeof (RAKPMsg4hmac_T),
+				&pRes [sizeof (RAKPMsg4Res_T)], HASH_KEY1_CONST_SIZE); 
+			 ResIntigrityKeyLen = HMAC_SHA256_128_LEN;
+	 
+			break;
+	}
+        default:
+            IPMI_DBG_PRINT("\nRMCP+.c : Invalid Integrity Algorithm \n");
+    }
+
+    /* Get information abt this channel */
+    pChannelInfo = getChannelInfo (Channel, BMCInst);
+    if (NULL == pChannelInfo)
+    {
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+        IPMI_WARNING ("RMCP+.c : RAKPMsg3 - Invalid Integrity check\n");
+        Res->StatusCode = SC_INV_INTEGRITY_CHECK;
+        return sizeof (RAKPMsg4Res_T);
+    }
+
+    pUserInfo = getUserIdInfo((INT8U)pSessInfo->UserId, BMCInst);
+
+	// check the session activated or not, or it will add repeatedly. And finally it will happen "No session slot available."
+	if((!pSessInfo->IsLoopBack) && (pSessInfo->Activated!=TRUE))
+    {
+        /* Update active sessions for current user */
+        pUserInfo->CurrentSession++;
+
+        /* Number of active session */
+        pChannelInfo->ActiveSession++;
+    }
+
+    /* Get userInfo for the given Used Id & Channel */
+    pChUserInfo = getChUserIdInfo (pSessInfo->UserId, &Index, pChannelInfo->ChannelUserInfo, BMCInst);
+
+#ifdef  LAN_RESTRICTIONS_BYPASS_FOR_LOOPBACK_AND_VLAN
+    if( pParams->IsPktFromVLAN || pParams->IsPktFromLoopBack )
+    {
+        /* If the packet is from VLAN or LoopBack, then channel privilege should not be
+                    considered for session privilege calculation */
+        pSessInfo->Privilege = 0x4; //set to admin for loopback and VLAN always
+        //UTIL_MIN (pSessInfo->Privilege, pChUserInfo->AccessLimit);
+    }
+    else
+    {
+        /* if requested privilege is greater than privilege level for channel or user
+                set the minimum of Channel or user privilege*/
+        pSessInfo->Privilege =
+        UTIL_MIN (pSessInfo->Privilege, UTIL_MIN (pChannelInfo->MaxPrivilege, pChUserInfo->AccessLimit));
+    }
+#else
+    /* if requested privilege is greater than privilege level for channel or user
+            set the minimum of Channel or user privilege*/
+    pSessInfo->Privilege =
+    UTIL_MIN (pSessInfo->Privilege, UTIL_MIN (pChannelInfo->MaxPrivilege, pChUserInfo->AccessLimit));
+#endif
+
+    pSessInfo->AuthType     = RMCP_PLUS_FORMAT;
+    pSessInfo->Activated    = TRUE;
+    /* Set the Max Privilege allowed for the Session*/
+    pSessInfo->MaxPrivilege = pSessInfo->Privilege;
+    BMC_GET_SHARED_MEM (BMCInst)->SessionHandle += 1;
+    pSessInfo->SessionHandle = BMC_GET_SHARED_MEM (BMCInst)->SessionHandle;
+
+    /*Load Response */
+    Res->StatusCode      = SC_NO_ERROR;
+    Res->RemConSessionID = pSessInfo->RemConSessionID;
+    pSessInfo->EventFlag = 1;
+    pBMCInfo->LANConfig.DeleteThisLANSessionID = 0;
+    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+    return (sizeof (RAKPMsg4Res_T) + ResIntigrityKeyLen);
+}
+
+
+#endif /*#if IPMI20_SUPPORT == 1*/

+ 73 - 0
app/bmc/lan/RMCP+.h

@@ -0,0 +1,73 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * rmcp.h
+ * RMCP Packet Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com> 
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ * 
+ *****************************************************************/
+#ifndef RMCP_PLUS_H
+#define RMCP_PLUS_H
+#include "com_BmcType.h"
+#include "com_IPMI_RMCP.h"
+#include "com_IPMI_RMCP+.h"
+#include "RMCP.h"
+#include "Ciphertable.h"
+
+
+/*** External Definitions *****/
+#define MAX_ALGORITHMS              2
+#define HMAC_SHA1_96_LEN            12
+#define HMAC_SHA256_128_LEN         16
+#define HMAC_MD5_LEN				16
+#define MD5_LEN						16
+
+#define USER_ROLE_LOOKUP 			0
+#define NAME_ONLY_LOOKUP 			1
+
+#pragma pack( 1 )
+
+/**
+ * @var g_CipherRec
+ * @brief Cipher suite record.
+**/
+extern const uint8_t  g_CipherRec[MAX_CIPHER_SUITES_BYTES];
+
+
+
+#pragma pack( )
+
+/**
+ * @defgroup rmcp RMCP+ Session Establishment
+ * A set of pre-session messages as per RMCP+ specifiation.
+ * These messages negotiate integrity and confidentiality algorithms and develop
+ * keys for encoding/decoding furthur messages.
+ * @{
+**/
+// extern int  RSSPOpenSessionReq (  uint8_t* pReq, uint8_t ReqLen,   uint8_t* pRes, uint8_t Channel );
+// extern int  RAKPMsg1           (  uint8_t* pReq, uint8_t ReqLen,   uint8_t* pRes, uint8_t Channel );
+// extern int  RAKPMsg3           (  uint8_t* pReq, uint8_t ReqLen,   uint8_t* pRes, uint8_t Channel );
+// /** @} */
+
+// /**
+//  * @brief  sha256 open source algorithm
+// **/
+// extern void hmac_sha256(unsigned char *key, unsigned int key_size,
+//         unsigned char *message, unsigned int message_len,
+//         unsigned char *mac, unsigned mac_size);
+
+#endif /* RMCP_PLUS_H */

+ 1388 - 0
app/bmc/lan/RMCP.c

@@ -0,0 +1,1388 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * RMCP.c
+ * RMCP Message Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#include "com_Message.h"
+#include "com_IPMIDefs.h"
+#include "Session.h"
+#include "LANIfc.h"
+#include "MD.h"
+#include "RMCP.h"
+#include "RMCP+.h"
+#include "main.h"
+#include "MD5_128.h"
+#include <string.h>
+#include "BmcType.h"
+#include "AuthCode.h"
+
+
+/*** Local definitions ***/
+#define RMCP_VERSION                6
+#define IPMI_MESSAGE_CLASS          7
+#define PRESENCE_PING_MSGTYPE       0x80
+#define RMCP_VERSION                6
+
+#define AMI_CMD_NETFN_LUN           (((0x2E | 1) << 2) | 0x00)
+#define AMI_CMD_12                  0x12
+#define PING_IPMI_15_SUPPORT        1
+#define PING_IPMI_20_SUPPORT        2
+#define MAX_AUTH_CODE_SIZE          12
+#define INIT_VECTOR_SIZE            16
+#define INTEGRITY_MASK              BIT6
+#define CONFIDENT_MASK              BIT7
+
+#define PAYLOAD_RSSP_OS_REQ         0x10
+#define PAYLOAD_RSSP_OS_RES         0x11
+#define PAYLOAD_RAKP_MSG1           0x12
+#define PAYLOAD_RAKP_MSG2           0x13
+#define PAYLOAD_RAKP_MSG3           0x14
+#define PAYLOAD_RAKP_MSG4           0x15
+
+// /*** Prototype Declaration ***/
+static int ProcIPMIReq (  SessionInfo_T*  pSessionInfo, uint8_t Payload, MsgPkt_T *pReq, MsgPkt_T *pRes);
+static uint8_t  ValidateRMCPHdr    (  RMCPHdr_T* pRMCPHdr);
+// static bool  ValidateSessionHdr (uint32_t SessionID, uint32_t SeqNo );
+static uint8_t ProcessPingMsg     (  RMCPHdr_T* pRMCPReq,
+ 								   RMCPHdr_T* pRMCPRes );
+static uint8_t  ValidateAuthCode   (  uint8_t* pAuthCode,   uint8_t* pPassword,
+ 								   SessionHdr_T* pSessionHdr,
+ 								   IPMIMsgHdr_T* pIPMIMsg);
+// static int   Proc20Payload      (  RMCPHdr_T* pRMCPReq,
+// 								   RMCPHdr_T* pRMCPRes, MiscParams_T *pParams, uint8_t Channel );
+
+/*** Local typedefs ***/
+/**
+ * @struct PreSessionCmd_T
+ * @brief Pre-session command entry.
+**/
+typedef struct
+{
+	uint8_t   NetFn;
+	uint8_t   Cmd;
+} PreSessionCmd_T;
+
+/**
+ * @brief Message Payload Handler function.
+ * @param pReq   - Request message.
+ * @param ReqLen - Request length.
+ * @param pRes   - Response message.
+ * @return 0 if success, -1 if error.
+**/
+typedef int (*pPayloadHndlr_T) (  uint8_t* pReq, uint8_t ReqLen,
+								  uint8_t* pRes, uint8_t Channel );
+
+/**
+ * @struct PayloadTbl_T;
+ * @brief Payload Table structure.
+**/
+typedef struct
+{
+	uint8_t           Payload;
+	pPayloadHndlr_T PayloadHndlr;
+} PayloadTbl_T;
+
+
+// static const PayloadTbl_T m_PayloadTbl [] =
+// {
+// 	 /*  Payload              Handler           */
+// 	{PAYLOAD_RSSP_OS_REQ,   RSSPOpenSessionReq  },
+// 	{PAYLOAD_RAKP_MSG1,     RAKPMsg1            },
+// 	{PAYLOAD_RAKP_MSG3,     RAKPMsg3            },
+// };
+
+// /* Pre-Session establishment commands */
+// static const PreSessionCmd_T m_PreSessionCmdsTbl[] =
+// {
+// 	{ NETFN_APP,    CMD_GET_CH_AUTH_CAP },
+// 	{ NETFN_APP,    CMD_GET_SESSION_CHALLENGE },
+// 	{ NETFN_APP,    CMD_GET_DEV_GUID },
+// 	{ NETFN_APP,    CMD_GET_CH_CIPHER_SUITES },
+// 	{ NETFN_APP,    CMD_GET_SYSTEM_GUID },
+// 	{ NETFN_SENSOR, CMD_PET_ACKNOWLEDGE},
+// };
+
+// /**
+//  * @struct IPMIAuditMaskTbl_T;
+//  * @brief  Maps Audit Event types to their bitmask in configuration.
+// **/
+// typedef struct
+// {
+// 	uint8_t EventType;
+// 	uint8_t EventMask;
+// }IPMIAuditMaskTbl_T;
+
+// static const IPMIAuditMaskTbl_T m_IPMIAuditMaskMap[] =
+// {
+// 	{ EVENT_LOGIN,           0x0 },
+// 	{ EVENT_LOGOUT,          0x1 },
+// 	{ EVENT_AUTO_LOGOUT,     0x2 },
+// 	{ EVENT_LOGIN_FAILURE,   0x3 },
+// };
+
+
+// int RmcpSeqNumValidation(SessionInfo_T* pSessionInfo, uint32_t SessionSeqNum, IPMIMsgHdr_T* pIPMIMsgReq)
+// {
+// 	uint32_t  SeqTrac[SIXTEEN_COUNT_WINDOW_LEN];
+// 	bool    TrackRollOver       = FALSE;
+// 	uint32_t  TrackRollOverSeq    = SEQNUM_ROLLOVER;
+// 	int     i;
+	
+// 	if((pIPMIMsgReq->Cmd != CMD_ACTIVATE_SESSION) ||
+// 	   ((pIPMIMsgReq->Cmd == CMD_ACTIVATE_SESSION) &&
+// 	   (SessionSeqNum != 0)))
+// 	{
+// 		if( pSessionInfo->InboundSeq == SessionSeqNum)
+// 			return -1;
+
+// 		 if((pSessionInfo->InboundSeq < (SEQNUM_ROLLOVER - EIGHT_COUNT_WINDOW_LEN)) && (pSessionInfo->InboundSeq > EIGHT_COUNT_WINDOW_LEN))
+// 		 {
+// 			if(SessionSeqNum < pSessionInfo->InboundSeq)
+// 			{
+// 				if((pSessionInfo->InboundSeq -SessionSeqNum) > EIGHT_COUNT_WINDOW_LEN)
+// 				{
+// 				   return -1;
+// 				}
+// 				else
+// 				{
+// 					for(i=0;i<EIGHT_COUNT_WINDOW_LEN;i++)
+// 					{
+// 						if(SessionSeqNum == pSessionInfo->InboundTrac[i])
+// 						{
+// 							if(((1 << i) & pSessionInfo->InboundRecv) != 0)
+// 							{
+// 								 return -1;
+// 							}
+// 							else
+// 							{
+// 								 pSessionInfo->InboundRecv |= (1<<i);
+// 							}
+// 						}
+// 					}
+// 				}
+// 			}
+// 			else
+// 			{
+// 				if((SessionSeqNum - pSessionInfo->InboundSeq) > EIGHT_COUNT_WINDOW_LEN)
+// 				{
+// 					return -1;
+// 				}
+
+// 				_fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * EIGHT_COUNT_WINDOW_LEN));
+
+// 				for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq); i++)
+// 				{
+// 					pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 				}
+
+// 				pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
+// 				pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq)-1));
+
+// 				_fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
+// 								(uint8_t *)&SeqTrac[0],
+// 								(sizeof(uint32_t) *(EIGHT_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
+// 				pSessionInfo->InboundSeq = SessionSeqNum;
+// 			}
+// 		}
+// 		else if((pSessionInfo->InboundSeq  < EIGHT_COUNT_WINDOW_LEN)
+// 					|| (pSessionInfo->InboundSeq  > (SEQNUM_ROLLOVER -EIGHT_COUNT_WINDOW_LEN))) /* Checking for Roll over condition */
+// 		{
+// 			if(SessionSeqNum < pSessionInfo->InboundSeq)
+// 			{
+// 				if(!((((pSessionInfo->InboundSeq -SessionSeqNum) <= EIGHT_COUNT_WINDOW_LEN) &&
+// 				   (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) >= EIGHT_COUNT_WINDOW_LEN )) ||
+// 				   ((((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= EIGHT_COUNT_WINDOW_LEN ) &&
+// 					   (pSessionInfo->InboundSeq -SessionSeqNum) >= EIGHT_COUNT_WINDOW_LEN)))
+// 				{
+// 				  return -1;
+// 				}
+// 				else
+// 				{
+// 					if((pSessionInfo->InboundSeq -SessionSeqNum) <= EIGHT_COUNT_WINDOW_LEN)
+// 					{
+// 						for(i=0;i<EIGHT_COUNT_WINDOW_LEN;i++)
+// 						{
+// 							if(SessionSeqNum == pSessionInfo->InboundTrac[i])
+// 							{
+// 								if(((1 << i) & pSessionInfo->InboundRecv) != 0)
+// 								{
+// 									return -1;
+// 								}
+// 								else
+// 								{
+// 									pSessionInfo->InboundRecv |= (1<<i);
+// 								}
+// 							}
+// 						}
+// 					 }
+// 					else if(((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= EIGHT_COUNT_WINDOW_LEN )
+// 					{
+// 						_fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * EIGHT_COUNT_WINDOW_LEN));
+
+// 						for(i=0; i < ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1); i++)
+// 						{
+// 							if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
+// 								pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 							else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
+// 							{
+// 								pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 								TrackRollOver = TRUE;
+// 							}
+// 							else if(TrackRollOver ==  TRUE)
+// 							{
+// 								pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
+// 								TrackRollOverSeq--;
+// 							}
+// 						}
+// 						TrackRollOverSeq = SEQNUM_ROLLOVER;
+// 						TrackRollOver = FALSE;
+
+// 						pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1);
+// 						pSessionInfo->InboundRecv |= (1 << (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) -1));
+
+// 						_fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[(SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1],
+// 						(uint8_t *)&SeqTrac[0],
+// 						(sizeof(uint32_t) *(EIGHT_COUNT_WINDOW_LEN - ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1))));
+// 						pSessionInfo->InboundSeq = SessionSeqNum;
+// 					}
+// 				}
+// 			}
+// 			else if(SessionSeqNum > pSessionInfo->InboundSeq)
+// 			{
+// 				if(!((((SessionSeqNum -pSessionInfo->InboundSeq) <= EIGHT_COUNT_WINDOW_LEN) &&
+// 				   (((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) >= EIGHT_COUNT_WINDOW_LEN )) ||
+// 				   ((((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) <= EIGHT_COUNT_WINDOW_LEN ) &&
+// 					   (SessionSeqNum-pSessionInfo->InboundSeq) >= EIGHT_COUNT_WINDOW_LEN)))
+// 				{
+// 					return -1;
+// 				}
+// 				else
+// 				{
+// 					if((SessionSeqNum  - pSessionInfo->InboundSeq) <= EIGHT_COUNT_WINDOW_LEN)
+// 					{
+// 						_fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * EIGHT_COUNT_WINDOW_LEN));
+// 						for(i=0;i<(SessionSeqNum  - pSessionInfo->InboundSeq) ;i++)
+// 						{
+// 							if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
+// 							{
+// 								pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 							}
+// 							else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
+// 							{
+// 								pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 								TrackRollOver = TRUE;
+// 							}
+// 							else if(TrackRollOver ==  TRUE)
+// 							{
+// 								pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
+// 								TrackRollOverSeq--;
+// 							}
+// 						}
+// 						TrackRollOverSeq = SEQNUM_ROLLOVER;
+// 						TrackRollOver = FALSE;
+
+// 						pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum  - pSessionInfo->InboundSeq);
+// 						pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum  - pSessionInfo->InboundSeq) -1));
+
+// 						_fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum  - pSessionInfo->InboundSeq],
+// 						(uint8_t *)&SeqTrac[0],
+// 						(sizeof(uint32_t) *(EIGHT_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
+// 						pSessionInfo->InboundSeq = SessionSeqNum;
+// 					}
+// 					else if(((SEQNUM_ROLLOVER -SessionSeqNum) + pSessionInfo->InboundSeq+1) <= EIGHT_COUNT_WINDOW_LEN)
+// 					{
+// 						for(i=0;i<EIGHT_COUNT_WINDOW_LEN;i++)
+// 						{
+// 							if(SessionSeqNum == pSessionInfo->InboundTrac[i])
+// 							{
+// 								if(((1 << i) & pSessionInfo->InboundRecv) != 0)
+// 								{
+// 									return -1;
+// 								}
+// 								else
+// 								{
+// 									pSessionInfo->InboundRecv |= (1<<i);
+// 								}
+// 							}
+// 						}
+
+// 					}
+// 				}
+// 			}
+// 		 }
+// 	}
+
+// 	return 0;
+// }
+
+/*-------------------------------------------
+ * ProcessRMCPReq
+ *-------------------------------------------*/
+uint32_t
+ProcessRMCPReq( RMCPHdr_T* pRMCPReq,  RMCPHdr_T* pRMCPRes)
+{
+	SessionInfo_T*  pSessionInfo = NULL;
+	IPMIMsgHdr_T*   pIPMIMsgReq;
+	IPMIMsgHdr_T*   pIPMIMsgRes;
+	uint8_t*          pReqMsgAuthCode;
+	uint8_t*          pResMsgAuthCode;
+	SessionHdr_T*   pReqSessionHdr = ( SessionHdr_T*)(pRMCPReq + 1);
+	SessionHdr_T*   pResSessionHdr = ( SessionHdr_T*)(pRMCPRes + 1);
+	uint8_t           IPMIMsgLen;
+	uint32_t          SessionID;
+	uint32_t          ResLen, IPMIMsgResLen;
+	MsgPkt_T	Req,Res;
+
+	/* Validate RMCP Header */
+	if (TRUE != ValidateRMCPHdr(pRMCPReq))
+	{
+		printf ("RMCP.c : RMCP header validation failed\r\n");
+		return 0;
+	}
+
+	/* If RMCP Ping, process it seperately */
+	if (pRMCPReq->MsgClass == 0x06)
+	{
+		return ProcessPingMsg (pRMCPReq, pRMCPRes);
+	}
+
+	/* Process IPMI 2.0 Separately */
+#if IPMI20_SUPPORT == 1
+//	if (RMCP_PLUS_FORMAT == pReqSessionHdr->AuthType)
+//	{
+//		ResLen = Proc20Payload (pRMCPReq, pRMCPRes);
+//	}
+//	else
+#endif
+	{
+		SessionID             = pReqSessionHdr->SessionID;
+
+		/* Get Session Information */
+		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
+	
+		if (0 == pReqSessionHdr->AuthType)
+		{
+			IPMIMsgLen  = (uint8_t) (*(( uint8_t*)(pReqSessionHdr + 1)));
+
+			pIPMIMsgReq = ( IPMIMsgHdr_T*) ((( uint8_t*)(pReqSessionHdr + 1)) +
+						  sizeof (IPMIMsgLen));
+			pIPMIMsgRes = ( IPMIMsgHdr_T*) ((( uint8_t*)(pResSessionHdr + 1)) +
+						  sizeof (IPMIMsgLen));
+		}
+		else
+		{
+			pReqMsgAuthCode = (( uint8_t*)(pReqSessionHdr + 1));
+			pResMsgAuthCode = (( uint8_t*)(pResSessionHdr + 1));
+			IPMIMsgLen      = *(pReqMsgAuthCode + AUTH_CODE_LEN);
+			pIPMIMsgReq     = ( IPMIMsgHdr_T*) (pReqMsgAuthCode + AUTH_CODE_LEN +
+							  sizeof (IPMIMsgLen));
+			pIPMIMsgRes     = ( IPMIMsgHdr_T*) (pResMsgAuthCode + AUTH_CODE_LEN +
+							  sizeof (IPMIMsgLen));
+			
+			if (TRUE != ValidateAuthCode (pReqMsgAuthCode, g_BMCInfo.pUserInfo->UserPassword,
+										  pReqSessionHdr, pIPMIMsgReq))
+			{
+				printf("Password error!\n");
+				return 0;
+			}
+			//TODO:pSessionInfo->Password到底是在哪里赋值的?在这里可以吗?
+			//memcpy(pSessionInfo->Password,g_BMCInfo.pUserInfo->UserPassword,MAX_PASSWORD_LEN);
+		}
+
+		/* Frame the Message Packet for Message Handler */
+		Req.Param	  = PARAM_IFC;
+		Req.Cmd       = pIPMIMsgReq->Cmd;
+		Req.NetFnLUN  = pIPMIMsgReq->NetFnLUN;
+		Req.SessionID = SessionID;
+		Req.SessionType = LAN_SESSION_TYPE;
+		Req.Channel 	= LAN_RMCP_CHANNEL;
+		
+		//UpdateGetMsgTime( &pBMCInfo->LANConfig.MsgReq,IfcType, BMCInst);
+		Req.Size = IPMIMsgLen;
+		memcpy(Req.Data, ( uint8_t*) pIPMIMsgReq, Req.Size);
+
+		/* Post Msg to MsgHndlr and Get Res */
+		if (0 != ProcIPMIReq (pSessionInfo, PAYLOAD_IPMI_MSG, &Req, &Res))
+		{
+			return 0;
+		}
+
+		/* Fill Response data */
+		memcpy (pRMCPRes, pRMCPReq, sizeof (RMCPHdr_T) + sizeof (SessionHdr_T));
+
+		/* Fill Authentication Code */
+		if (0 != pReqSessionHdr->AuthType)
+		{
+			pResMsgAuthCode = ( uint8_t*)(pResSessionHdr + 1);
+			pIPMIMsgRes     = ( IPMIMsgHdr_T*)(( uint8_t*)(pResSessionHdr + 1) +
+							  AUTH_CODE_LEN + sizeof (IPMIMsgLen));
+			IPMIMsgResLen      = AUTH_CODE_LEN + sizeof (IPMIMsgLen) + Res.Size;
+			/* Fill IPMI Message */
+			memcpy (pIPMIMsgRes, Res.Data, Res.Size);
+			*(pResMsgAuthCode + AUTH_CODE_LEN) = Res.Size;
+
+//			ComputeAuthCode ((uint8_t*)g_BMCInfo.pUserInfo->UserPassword, pResSessionHdr, pIPMIMsgRes,
+//							 pResMsgAuthCode, MULTI_SESSION_CHANNEL);
+		}
+		else
+		{
+			pIPMIMsgRes = ( IPMIMsgHdr_T*)(( uint8_t*)(pResSessionHdr + 1) +
+						  sizeof (IPMIMsgLen));
+			IPMIMsgResLen  = Res.Size + sizeof (IPMIMsgLen);
+			/* Fill IPMI Message */
+			memcpy (pIPMIMsgRes, Res.Data, Res.Size);
+			*(( uint8_t*) (pResSessionHdr + 1)) = Res.Size;
+		}
+
+//		if( (NETFN_APP == (pIPMIMsgReq->NetFnLUN >> 2)) && (CMD_GET_SESSION_CHALLENGE == pIPMIMsgReq->Cmd) && 
+//			(CC_GET_SESSION_INVALID_USER == Res.Data[sizeof(IPMIMsgHdr_T)]) && (NULL == pSessionInfo) )
+//		{
+//			if ( 0 != AddLoginEvent( 0xFF, &pBMCInfo->LANConfig.MsgReq.Data[7], EVENT_LOGIN_FAILURE, BMCInst ))
+//			{
+//				TCRIT("Problem while adding Log record \n");
+//			}
+//		}
+		ResLen = sizeof (RMCPHdr_T) + sizeof (SessionHdr_T) + IPMIMsgResLen;
+	}
+
+	return ResLen;
+}
+
+/**
+ * @brief Process the IPMI request and prepare response.
+ * @param pSessionInfo - Session information.
+ * @param Payload     - Payload type.
+ * @return 0 if success, -1 if error.
+**/
+int ProcIPMIReq (  SessionInfo_T*  pSessionInfo, uint8_t Payload, MsgPkt_T *pReq, MsgPkt_T *pRes)
+{
+//	ChannelInfo_T*      pChannelInfo;
+//	int	RetVal = 0;
+
+	//printf("ProcIPMIReq\n");
+	/* Frame the Message Packet for Message Handler */
+	pReq->Param     = PARAM_IFC;
+	pReq->SrcQ		= gFd_LanResQ;
+	
+	if (PAYLOAD_IPMI_MSG == Payload)
+	{
+//		printf("\n\n===> Post to MsgHndlr\n");
+		PostMsg (gFd_MsgHndlrIfc, pReq);
+	}
+   
+	
+		
+	if ( GetMsg (gFd_LanResQ, pRes, DEFAULT_TIMEOUT) != 0)
+	{
+		//FillIPMIResFailure (pReq, pRes);
+		printf("Warning: RMCP get message error!\n");
+	}
+
+//	printf("===> gFd_LanResQ Recv: ");
+	// int i;
+	// for(i=0;i<pRes->Size;i++)
+	// 	printf("%#x ", pRes->Data[i]);
+	// printf("\n");
+
+
+	if (PARAM_NO_RESPONSE == pRes->Param)
+	{
+		printf ("RMCP.c : No response from message handler\n");
+		return -1;
+	}
+
+	//printf("ProcIPMIReq get response: Param %#x, netfn %#x, cmd %#x, len %#x\n", pRes->Param, pRes->NetFnLUN, pRes->Cmd, pRes->Size);
+	
+	if (((pReq->NetFnLUN >> 2) == 0x06) && (pReq->Cmd  == 0x3A) &&			//Active Session , ipmi2.0 page 613
+		(PAYLOAD_IPMI_MSG == Payload))
+	{
+		//TODO:
+	}    
+
+	/* If Request IPMI Message is Close Session */
+	if (((pReq->NetFnLUN >> 2) == 0x06) && (pReq->Cmd  == 0x3C) &&			//close session
+		(PAYLOAD_IPMI_MSG == Payload))
+	{
+		//TODO:
+	}
+
+	return 0;
+}
+
+/**
+ * @brief Validate RMCP Header
+ * @param pRMCPHdr - RMCP header.
+ * @return TRUE if valid, FALSE if invalid.
+**/
+static uint8_t
+ValidateRMCPHdr (  RMCPHdr_T* pRMCPHdr)
+{
+	/* If RMCP Packet is NULL */
+	if (pRMCPHdr == NULL)
+	{
+		printf ("RMCP.c : RMCP Packet is NULL\n");
+		return FALSE;
+	}
+
+	/* Verify RMCP Version */
+	if (pRMCPHdr->Version != RMCP_VERSION)
+	{
+		printf ("RMCP.c : Invalid RMCP Version\n");
+		return FALSE;
+	}
+
+	/* LOOK for RMCP MessageClass */
+	if ((pRMCPHdr->MsgClass != IPMI_MESSAGE_CLASS) &&
+		(pRMCPHdr->MsgClass != 0x06))
+	{
+		printf ("RMCP.c : Invalid Message Class\n");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+// /**
+//  * @brief Validate session header.
+//  * @param SessionID - Session ID.
+//  * @param SeqNo    - Session Sequence Number.
+//  * @return TRUE if valid, FALSE if invalid.
+// **/
+// static bool
+// ValidateSessionHdr (uint32_t SessionID, uint32_t SeqNo )
+// {
+// 	   SessionInfo_T*   pSessionInfo;
+
+// 	/* if its Pre Session commands  */
+// 	if (0 == SessionID)
+// 	{
+// 		return TRUE;
+// 	}
+
+// 	pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
+// 	if ( pSessionInfo == NULL)
+// 	{
+// 		return FALSE;
+// 	}
+
+// 	/* If packet is already received - drop the packet  */
+// /*  if (ntohs(SeqNo) <= ntohs (CAST_32 (&pSessionInfo->InboundSeq)))
+// 	{
+// 		 IPMI_DBG_PRINT ("RMCP: Duplicate Seq No - Packet dropped\n");
+// 		 return FALSE;
+// 	}
+// */
+
+// 	/* inc the Sequence No  */
+
+// 	return TRUE;
+// }
+
+/**
+ * @brief Process RMCP Ping Message.
+ * @param pRMCPReq - Request RMCP message.
+ * @param pRMCPRes - Response RMCP message.
+ * @return the response length.
+**/
+static uint8_t
+ProcessPingMsg (  RMCPHdr_T* pRMCPReq,   RMCPHdr_T* pRMCPRes )
+{
+	  RMCPPingHdr_T* pReqPingHdr = (  RMCPPingHdr_T*)(pRMCPReq + 1);
+	  RMCPPingHdr_T* pResPingHdr = (  RMCPPingHdr_T*)(pRMCPRes + 1);
+
+	if (PRESENCE_PING_MSGTYPE != pReqPingHdr->MsgType) { return 0; }
+	if((pReqPingHdr->IANANum[0]!=0x00)||(pReqPingHdr->IANANum[1]!=0x00)||
+		 (pReqPingHdr->IANANum[2]!=0x11)||(pReqPingHdr->IANANum[3]!=0xBE)) 
+	   { return 0; }
+
+	/* Construct Response Header */
+	memcpy (pResPingHdr, pReqPingHdr, sizeof (RMCPPingHdr_T));
+	pResPingHdr->MsgType = 0x40;
+	pResPingHdr->DataLen = 0x10;
+
+	/* Fill Response Data */
+	memset (pResPingHdr + 1, 0, pResPingHdr->DataLen);
+	*((  uint8_t*)(pResPingHdr + 1) + 8) = 0x81;
+	*((  uint8_t*)(pResPingHdr + 1) + 4) = PING_IPMI_15_SUPPORT;
+
+#if IPMI20_SUPPORT == 1
+//	*((  uint8_t*)(pResPingHdr + 1) + 4) |= PING_IPMI_20_SUPPORT;
+#endif
+
+	// /*Update the OEM IANA Number for DCMI Discovery (36465 = Data Center Manageability Forum,Spec .1.5)*/
+	// if(g_corefeatures.dcmi_1_5_support == ENABLED)
+	// {
+	// 	if(pBMCInfo->IpmiConfig.DCMISupport == 1)
+	// 	{
+	// 		*((  uint8_t*)(pResPingHdr + 1) + 2) = 0x8E;
+	// 		*((  uint8_t*)(pResPingHdr + 1) + 3) = 0x71;
+	// 	}
+	// }
+
+	return (sizeof (RMCPHdr_T) + sizeof (RMCPPingHdr_T) + pResPingHdr->DataLen);
+}
+
+
+/**
+ * @brief Validate Authentication Code
+ * @param pAuthCode - Request authentication code.
+ * @param pPassword - Password string.
+ * @param pSessionHdr - Request Session header.
+ * @param pIPMIMsg - Request IPMI message.
+ * @return TRUE if valid, FALSE if invalid.
+**/
+static uint8_t
+ValidateAuthCode (  uint8_t* pAuthCode,   uint8_t* pPassword,
+				    SessionHdr_T* pSessionHdr,   IPMIMsgHdr_T* pIPMIMsg)
+{
+	uint8_t   ComputedAuthCode [AUTH_CODE_LEN];
+
+	memset(ComputedAuthCode, 0, sizeof (ComputedAuthCode));
+
+	ComputeAuthCode (pPassword, pSessionHdr, pIPMIMsg,
+					 ComputedAuthCode, MULTI_SESSION_CHANNEL);
+
+	// int i;
+	// printf("pAuthCode: ");
+	// for(i=0;i<AUTH_CODE_LEN;i++)
+	// 	printf("%#x ", pAuthCode[i]);
+	// printf("\n");
+	// printf("pPassword: %s\n", pPassword);
+	// printf("pComputeAuthCode: ");
+	// for(i=0;i<AUTH_CODE_LEN;i++)
+	// 	printf("%#x ", ComputedAuthCode[i]);
+	// printf("\n");
+	
+
+	return (0 == memcmp (pAuthCode, ComputedAuthCode, AUTH_CODE_LEN));
+}
+
+ #if IPMI20_SUPPORT
+
+// /*-------------------------------------------
+//  * Frame20Payload
+//  *-------------------------------------------*/
+// int
+// Frame20Payload (uint8_t PayloadType,   RMCPHdr_T* pRMCPPkt,
+// 				  uint8_t* pPayload,  uint32_t PayloadLen,  
+// 				SessionInfo_T* pSessionInfo )
+// {
+// 	   BMCInfo_t*       pBMCInfo        = &g_BMCInfo[BMCInst];
+// 	  SessionHdr2_T*   pResSessionHdr  = (  SessionHdr2_T*)(pRMCPPkt + 1);
+// 	  uint8_t*           pRes            = (  uint8_t*)(pResSessionHdr + 1);
+// 	  uint8_t*           pConfHdr;
+// 	  uint8_t*           pConfPayld;
+// 	  uint8_t*           pIntPad;
+// 	  uint8_t*           pResMsgAuthCode;
+// 	uint8_t                   ConfPadLen, IntPadLen;
+// 	INT16U                  ConfPayldLen, AuthCodeLen;
+// 	int                     i, ResLen;
+// 	unsigned int            seed = 1;
+
+// 	/* Fill Session Hdr */
+// 	pResSessionHdr->AuthType      = RMCP_PLUS_FORMAT;
+// 	pResSessionHdr->PayloadType   = PayloadType;
+
+
+// 	if (NULL == pSessionInfo)
+// 	{
+// 		pResSessionHdr->SessionID = 0;
+// 		pResSessionHdr->SessionSeqNum = 0;
+// 	}
+// 	else
+// 	{
+// 		/* Response packets should send the Remote Console
+// 		 * Session ID so the remote console can correctly
+// 		 * match up the session with its own table of active
+// 		 * session IDs. */
+// 		pResSessionHdr->SessionID = pSessionInfo->RemConSessionID;
+
+// 		/* Increment session sequence number */
+// 		/* During RMCP Opensession , OutboundSeq initialized to 0 and but 0 is  reserved  */
+// 		/* and also  When It reach 0xffffffff then It  become zero */
+// 		if(0==pSessionInfo->OutboundSeq)
+// 		{
+// 			pSessionInfo->OutboundSeq=1;
+// 		}
+// 		pResSessionHdr->SessionSeqNum = htoipmi_u32(pSessionInfo->OutboundSeq++);
+// 	}
+
+// 	/* Fill Payload and Do Encryption if needed */
+// 	if ((NULL != pSessionInfo) &&
+// 		(0 != (pResSessionHdr->PayloadType & CONFIDENT_MASK)))
+// 	{
+// 		pConfHdr = (  uint8_t*)(pResSessionHdr + 1);
+// 		switch (pSessionInfo->ConfidentialityAlgorithm)
+// 		{
+// 		case CONF_AES_CBC_128:
+
+// 			/* Fill Init Vector */
+// 			for (i =0; i < CONF_AES_CBC_128_HDR_LEN; i++)
+// 			{
+// 				pConfHdr [i] = (uint8_t)rand_r (&seed);
+// 			}
+// 			pConfPayld = pConfHdr + CONF_AES_CBC_128_HDR_LEN;
+
+// 			/* Add Padding; include size of confpadlen */
+// 			ConfPadLen = (PayloadLen + 1) % CONF_BLOCK_SIZE;
+// 			if (0 != ConfPadLen)
+// 			{
+// 				ConfPadLen =  CONF_BLOCK_SIZE - ConfPadLen;
+// 			}
+// 			for (i = 0; i < ConfPadLen; i++)
+// 			{
+// 				*(pPayload + PayloadLen + i) = i + 1;
+// 			}
+// 			*(pPayload + PayloadLen + ConfPadLen) = ConfPadLen;
+// 			ConfPayldLen = PayloadLen + ConfPadLen + 1;
+// 			aesEncrypt ((  uint8_t*)pPayload,  ConfPayldLen,
+// 						(  uint8_t*)pConfHdr, pSessionInfo->Key2,
+// 						(  uint8_t*)pConfPayld);
+
+// 			IPMI_DBG_PRINT_BUF ((  uint8_t*)pConfPayld, ConfPayldLen);
+// 			PayloadLen	  = ConfPayldLen + CONF_AES_CBC_128_HDR_LEN;
+// 			pBMCInfo->LANConfig.MsgReq.Size = PayloadLen;
+// 			break;
+
+// 		case CONF_xCR4_128:
+// 		case CONF_xCR4_40:
+// 		default:
+// 			IPMI_WARNING ("RMCP.c : Invalid confidentiality Algorithm\n");
+// 			return 0;
+// 		}
+// 	}
+// 	else
+// 	{
+// 		_fmemcpy (pRes, pPayload, PayloadLen);
+// 	}
+
+// 	/* Fill Payload Length */
+// 	pResSessionHdr->IPMIMsgLen = htoipmi_u16 (PayloadLen);
+
+// 	ResLen = sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T) + PayloadLen;
+
+// 	/* Add Integrity Check Value */
+// 	if ((NULL != pSessionInfo) &&
+// 		(0 != (pResSessionHdr->PayloadType & INTEGRITY_MASK)))
+// 	{
+// 		/* Add Integrity Pad */
+// 		pIntPad   = (  uint8_t*)(pResSessionHdr + 1) + PayloadLen;
+// 		IntPadLen = (sizeof (SessionHdr2_T) + PayloadLen + 2) % sizeof (uint32_t);
+// 		if (0 != IntPadLen)
+// 		{
+// 			IntPadLen  = sizeof(uint32_t) - IntPadLen;
+// 		}
+// 		_fmemset (pIntPad, 0xFF, IntPadLen);
+// 		*(pIntPad + IntPadLen)      = IntPadLen;    /* Integrity Pad Len  */
+// 		*(pIntPad + IntPadLen + 1)  = 0x07;         /* Next Header        */
+
+// 		pResMsgAuthCode =  pIntPad + IntPadLen + 2;
+// 		AuthCodeLen     = sizeof (SessionHdr2_T) + PayloadLen + IntPadLen + 2;
+// 		ResLen          += IntPadLen + 2;
+
+// 		switch (pSessionInfo->IntegrityAlgorithm)
+// 		{
+// 		case AUTH_HMAC_SHA1_96:
+
+// 			hmac_sha1 ((uint8_t *)pSessionInfo->Key1, HASH_KEY1_SIZE,
+// 					   (  uint8_t*)pResSessionHdr, AuthCodeLen,
+// 					   (uint8_t *)pResMsgAuthCode, MAX_INTEGRITY_LEN);
+// 			ResLen += HMAC_SHA1_96_LEN;
+// 			break;
+
+// 		case AUTH_HMAC_MD5_128:
+// 			hmac_md5(pSessionInfo->Key1,HASH_KEY1_SIZE,(  uint8_t*)pResSessionHdr, AuthCodeLen,
+// 			pResMsgAuthCode, MAX_HMAC_MD5_INTEGRITY_LEN);
+// 			ResLen += HMAC_MD5_LEN;
+// 			break;
+			
+// 		case AUTH_MD5_128:
+// 			MD5_128((char *)pSessionInfo->Password,MAX_PASSWORD_LEN,(  INT8S*)pResSessionHdr, AuthCodeLen,
+// 			(char *)pResMsgAuthCode, MAX_MD5_INTEGRITY_LEN);
+// 			ResLen += MD5_LEN;
+// 			break;
+			
+// 		case AUTH_HMAC_SHA256_128:
+	
+// 			hmac_sha256 ((unsigned char *)pSessionInfo->Key1, SHA2_HASH_KEY_SIZE, (unsigned char *)pResSessionHdr,
+// 					AuthCodeLen, (unsigned char *)pResMsgAuthCode, HMAC_SHA256_128_LEN);                
+// 			ResLen += HMAC_SHA256_128_LEN;  
+// 			break;
+
+// 		default:
+// 			IPMI_WARNING ("RMCP.c : Invalid Integrity Algorithm\n");
+// 			return 0;
+// 		}
+// 	}
+
+// 	return ResLen;
+// }
+
+// int RMCPplusSeqNumValidation(SessionInfo_T * pSessionInfo,uint32_t SessionSeqNum)
+// {
+// 	uint32_t SeqTrac[SIXTEEN_COUNT_WINDOW_LEN];
+// 	bool TrackRollOver = FALSE;
+// 	uint32_t TrackRollOverSeq = SEQNUM_ROLLOVER;
+// 	int i=0;
+
+
+// 	if( pSessionInfo->InboundSeq == SessionSeqNum)
+// 		return -1;
+
+// 	if((pSessionInfo->InboundSeq < (SEQNUM_ROLLOVER -RMCPPLUS_SEQUPLIMIT)) && (pSessionInfo->InboundSeq > RMCPPLUS_SEQLOWLIMIT))
+// 	{
+// 		if(SessionSeqNum < pSessionInfo->InboundSeq)
+// 		{
+// 			if((pSessionInfo->InboundSeq -SessionSeqNum) > RMCPPLUS_SEQLOWLIMIT)
+// 				return -1;
+// 			else
+// 			{
+// 				for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
+// 			   {
+// 					if(SessionSeqNum == pSessionInfo->InboundTrac[i])
+// 					{
+// 						if(((1 << i) & pSessionInfo->InboundRecv) != 0)
+// 							return -1;
+// 						else
+// 							pSessionInfo->InboundRecv |= (1<<i);
+// 					}
+// 				}
+// 			}
+// 		}
+// 		else
+// 		{
+// 		   if((SessionSeqNum - pSessionInfo->InboundSeq) > RMCPPLUS_SEQUPLIMIT)
+// 				   return -1;
+
+// 		   _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
+
+// 			for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq); i++)
+// 						pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+
+
+// 			pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
+// 			pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq)-1));
+
+// 			_fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
+// 							   (uint8_t *)&SeqTrac[0],
+// 							   (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
+// 			pSessionInfo->InboundSeq = SessionSeqNum;
+// 		}
+// 	}
+// 	else if((pSessionInfo->InboundSeq  < RMCPPLUS_SEQLOWLIMIT)
+// 			  || (pSessionInfo->InboundSeq  > (SEQNUM_ROLLOVER -RMCPPLUS_SEQUPLIMIT)))  /* Checking condition for rollover */
+// 	{
+// 		  if(SessionSeqNum < pSessionInfo->InboundSeq)
+// 		  {
+// 			  if(!((((pSessionInfo->InboundSeq -SessionSeqNum) <= RMCPPLUS_SEQLOWLIMIT) &&
+// 				  (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) >= RMCPPLUS_SEQLOWLIMIT )) ||
+// 				  ((((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= RMCPPLUS_SEQLOWLIMIT ) &&
+// 					  (pSessionInfo->InboundSeq -SessionSeqNum) >= RMCPPLUS_SEQLOWLIMIT)))
+// 			   {
+// 						 return -1;
+// 			   }
+// 			   else
+// 			   {
+// 					if((pSessionInfo->InboundSeq -SessionSeqNum) <= RMCPPLUS_SEQLOWLIMIT)
+// 					{
+// 						for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
+// 						{
+// 							if(SessionSeqNum == pSessionInfo->InboundTrac[i])
+// 							{
+// 								if(((1 << i) & pSessionInfo->InboundRecv) != 0)
+// 									return -1;
+// 								else
+// 									pSessionInfo->InboundRecv |= (1<<i);
+// 							}
+// 						}
+// 					}
+// 					else if(((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= RMCPPLUS_SEQUPLIMIT )
+// 					{
+// 						_fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
+
+// 						for(i=0; i < ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) ; i++)
+// 						{
+// 							if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
+// 								pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 							else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
+// 							{
+// 								pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 								TrackRollOver = TRUE;
+// 							}
+// 							else if(TrackRollOver ==  TRUE)
+// 							{
+// 								pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
+// 								TrackRollOverSeq--;
+// 							}
+// 						}
+// 						TrackRollOverSeq = SEQNUM_ROLLOVER;
+// 						TrackRollOver = FALSE;
+
+// 						pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1);
+// 						pSessionInfo->InboundRecv |= (1 << (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) -1));
+
+// 						_fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[(SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1],
+// 									  (uint8_t *)&SeqTrac[0],
+// 									  (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1))));
+// 						pSessionInfo->InboundSeq = SessionSeqNum;
+// 					}
+// 			  }
+// 		  }
+// 		 else if(SessionSeqNum > pSessionInfo->InboundSeq)
+// 		{
+// 			if(!((((SessionSeqNum -pSessionInfo->InboundSeq) <= RMCPPLUS_SEQUPLIMIT) &&
+// 				(((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) >= RMCPPLUS_SEQUPLIMIT )) ||
+// 				((((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) <= RMCPPLUS_SEQLOWLIMIT ) &&
+// 				  (SessionSeqNum-pSessionInfo->InboundSeq) >= RMCPPLUS_SEQLOWLIMIT)))
+// 			  {
+// 				   return -1;
+// 			  }
+// 			 else
+// 			 {
+// 				 if((SessionSeqNum  - pSessionInfo->InboundSeq) <= RMCPPLUS_SEQUPLIMIT)
+// 				 {
+// 					 _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
+// 					  for(i=0; i < (SessionSeqNum  - pSessionInfo->InboundSeq) ; i++)
+// 					  {
+// 							if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
+// 								   pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 							else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
+// 							{
+// 								  pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
+// 								  TrackRollOver = TRUE;
+// 							}
+// 							else if(TrackRollOver ==  TRUE)
+// 							{
+// 								  pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
+// 								  TrackRollOverSeq--;
+// 							}
+// 					   }
+// 						TrackRollOverSeq = SEQNUM_ROLLOVER;
+// 						TrackRollOver = FALSE;
+
+// 						pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum  - pSessionInfo->InboundSeq);
+// 						pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum  - pSessionInfo->InboundSeq) -1));
+
+// 						_fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum  - pSessionInfo->InboundSeq],
+// 									  (uint8_t *)&SeqTrac[0],
+// 									  (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
+// 						pSessionInfo->InboundSeq = SessionSeqNum;
+// 				 }
+// 				 else if(((SEQNUM_ROLLOVER -SessionSeqNum) + pSessionInfo->InboundSeq+1) <= RMCPPLUS_SEQLOWLIMIT)
+// 				 {
+// 					   for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
+// 					   {
+// 							if(SessionSeqNum == pSessionInfo->InboundTrac[i])
+// 						   {
+// 								if(((1 << i) & pSessionInfo->InboundRecv) != 0)
+// 									 return -1;
+// 								else
+// 									 pSessionInfo->InboundRecv |= (1<<i);
+// 							}
+// 					   }
+// 				 }
+// 			 }
+// 					   }
+// 	}
+
+// 	return 0;
+// }
+
+
+// /**
+//  * @brief Process IPMI 2.0 Payload.
+//  * @param pRMCPReq - RMCP request message.
+//  * @param pRMCPRes _ RMCP response message.
+//  * @return 0 if success, -1 if error.
+// **/
+// static int
+// Proc20Payload (  RMCPHdr_T* pRMCPReq,   RMCPHdr_T* pRMCPRes, MiscParams_T *pParams,uint8_t Channel )
+// {
+// 	  SessionHdr2_T*  pReqSession2Hdr = (  SessionHdr2_T*)(pRMCPReq + 1);
+// 	  SessionHdr2_T*  pResSession2Hdr = (  SessionHdr2_T*)(pRMCPRes + 1);
+// 	  uint8_t*          pReq  = (  uint8_t *)(pReqSession2Hdr + 1);
+// 	  uint8_t*          pRes  = (  uint8_t *)(pResSession2Hdr + 1);
+// 	   SessionInfo_T*  pSessionInfo = NULL;
+// 	  uint8_t*          pIntPad;
+// 	  uint8_t*          pConfHdr;
+// 	  uint8_t*          pConfPayld;
+// 	  uint8_t*          pReqMsgAuthCode;
+// 	   UserInfo_T*     pUserInfo;
+// 	   BMCInfo_t*      pBMCInfo = &g_BMCInfo[BMCInst];
+// 		   uint8_t           Payload, IntPadLen, ComputedAuthCode [25];
+// 		   INT16U          IPMIMsgLen, AuthCodeLen, ConfPayldLen;
+// 		   uint32_t          SessionID;
+// 		   uint32_t          SessionSeqNum;
+// 		   int             len, i;
+// 		   uint8_t           UserPswd [MAX_PASSWORD_LEN];
+// 		   uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
+
+// 	/* Get SessionID & Session Seq */
+// 	SessionID       = pReqSession2Hdr->SessionID;
+// 	SessionSeqNum   = pReqSession2Hdr->SessionSeqNum;
+
+// 	/* Validate IPMI Session Header */
+// 	if (TRUE != ValidateSessionHdr (SessionID, SessionSeqNum, BMCInst))
+// 	{
+// //        IPMI_WARNING ("RMCP.c : IPMI Session header validation failed\n");
+// 		return 0;
+// 	}
+
+// 	IPMIMsgLen = ipmitoh_u16 (pReqSession2Hdr->IPMIMsgLen);
+// 	Payload    = pReqSession2Hdr->PayloadType & 0x3F;
+
+// 	/* Process PreSession Payloads */
+// 	for (i = 0; i < sizeof (m_PayloadTbl) / sizeof (m_PayloadTbl [0]); i++)
+// 	{
+// 		if (m_PayloadTbl [i].Payload == Payload)
+// 		{
+// 			/* Copy RMCP & Session Hdr */
+// 			_fmemcpy ((  uint8_t*)pRMCPRes, (  uint8_t*)pRMCPReq,
+// 					   sizeof (RMCPHdr_T) +  sizeof (SessionHdr2_T));
+
+// 			/* For response the type is type + 1 */
+// 			pResSession2Hdr->PayloadType++;
+// 			/* Copy message tag from request */
+// 			*pRes = *pReq;
+
+// 			OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+// 			/* Call the function and pass the data after message tag */
+// 			len = m_PayloadTbl [i].PayloadHndlr ((pReq),
+// 				  (uint8_t)(IPMIMsgLen - sizeof (uint8_t)), (pRes), pParams,Channel,BMCInst);
+// 			OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex,WAIT_INFINITE);
+
+// 			/* Copy the message length */
+// 			pResSession2Hdr->IPMIMsgLen = htoipmi_u16 ((len));
+
+// 		   if(len!=0)
+// 			len += sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T);
+
+// 			return len;
+// 		}
+// 	}
+
+// 	/* Check for Invalid Payload Type */
+// 	if ((PAYLOAD_IPMI_MSG !=  Payload) && (PAYLOAD_SOL !=  Payload))
+// 	{
+// 		IPMI_WARNING ("RMCP.c : Invalid payload\n");
+// 		return 0;
+// 	}
+
+// 	/* check for the pre-session commands */
+// 	if (0 == SessionID)
+// 	{
+// 		int i;
+// 		  IPMIMsgHdr_T* pIPMIMsg = (  IPMIMsgHdr_T*) pReq;
+
+// 		for (i=0; i < sizeof (m_PreSessionCmdsTbl) / sizeof (PreSessionCmd_T); i++)
+// 		{
+// 			if ((m_PreSessionCmdsTbl[i].NetFn == (pIPMIMsg->NetFnLUN >> 2)) &&
+// 				(m_PreSessionCmdsTbl[i].Cmd == pIPMIMsg->Cmd))
+// 			{
+// 				pBMCInfo->LANConfig.MsgReq.Size = IPMIMsgLen;
+// 				_fmemcpy (pBMCInfo->LANConfig.MsgReq.Data, pReq, pBMCInfo->LANConfig.MsgReq.Size);
+// 				break;
+// 			}
+// 		}
+// 		if (i >= (sizeof (m_PreSessionCmdsTbl) / sizeof (PreSessionCmd_T)))
+// 		{
+// 			IPMI_WARNING ("RMCP.c : Presession command not found\n");
+// 			return 0;
+// 		}
+// 	}
+// 	else
+// 	{
+// 		/* Get Session Information */
+// 		pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
+
+// 		if (NULL == pSessionInfo)
+// 		{
+// 			IPMI_WARNING ("RMCP.c : Proc20Payload - Invalid Session Id\n");
+// 			return 0;
+// 		}
+
+// 		/* Check if session is activated */
+// 		if (TRUE != pSessionInfo->Activated)
+// 		{
+// 			IPMI_WARNING ("RMCP.c : Session not activated with session id %lx\n", SessionID);
+// 			return 0;
+// 		}
+
+// 		if(pBMCInfo->IpmiConfig.LinkDownResilentSupport == 1)
+// 		{
+// 			if(pSessionInfo->Linkstat == TRUE)
+// 			{
+// 				pSessionInfo->Linkstat = FALSE;
+// 				memset(pSessionInfo->InboundTrac,0,SIXTEEN_COUNT_WINDOW_LEN);
+// 			}
+// 		}
+
+// 		if( ((((  IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->NetFnLUN)>>2==NETFN_APP) &&
+// 			((((  IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->Cmd)==CMD_SET_SESSION_PRIV_LEVEL) &&
+// 			((pSessionInfo->EventFlag)== 1) )
+// 		{
+// 			 pSessionInfo->EventFlag=0;
+// 			 if ( 0 != AddLoginEvent ( pSessionInfo->UserId, NULL, EVENT_LOGIN, BMCInst ))
+// 			 {
+// 				  TCRIT("Problem while adding Log record \n");
+// 			 }
+// 		}
+		
+// 		if(RMCPplusSeqNumValidation(pSessionInfo,ipmitoh_u32(SessionSeqNum)) != 0)
+// 		{
+// 			return 0;
+// 		}
+		
+// 		if (0 != (pReqSession2Hdr->PayloadType & INTEGRITY_MASK))
+// 		{
+// 			uint8_t Len;
+
+// 			/*  check Integrity pad which starts from auth type till auth code */
+// 			pIntPad   = (  uint8_t*)(pReqSession2Hdr + 1) + IPMIMsgLen;
+
+// 				IntPadLen = (sizeof (SessionHdr2_T) + IPMIMsgLen + 2) % sizeof (uint32_t);
+// 			if (0 != IntPadLen)
+// 			{
+// 				IntPadLen  = sizeof(uint32_t) - IntPadLen;
+// 			}
+
+// 			if (pIntPad [IntPadLen] != IntPadLen)
+// 			{
+// 				IPMI_WARNING ("RMCP.c : Invalid Padlength\n");
+// 				return 0;
+// 			}
+
+// 			/* Check auth code */
+// 			pReqMsgAuthCode =  pIntPad + IntPadLen + 2;
+// 			AuthCodeLen     = sizeof (SessionHdr2_T) + IPMIMsgLen + IntPadLen + 2;
+
+
+// 			switch (pSessionInfo->IntegrityAlgorithm)
+// 			{
+// 			case AUTH_HMAC_SHA1_96:
+// 				hmac_sha1 ((uint8_t *)pSessionInfo->Key1, HASH_KEY1_SIZE,
+// 						   (  uint8_t*)pReqSession2Hdr, AuthCodeLen,
+// 						   (  uint8_t*)ComputedAuthCode, MAX_INTEGRITY_LEN);
+// 				Len = HMAC_SHA1_96_LEN;
+// 				break;
+
+// 			case AUTH_HMAC_MD5_128:
+// 				hmac_md5 (pSessionInfo->Key1, HASH_KEY1_SIZE,
+// 							(  uint8_t*)pReqSession2Hdr, AuthCodeLen,
+// 							(  uint8_t*)ComputedAuthCode, MAX_HMAC_MD5_INTEGRITY_LEN);
+// 				Len = HMAC_MD5_LEN;
+// 				break;
+				
+// 			case AUTH_MD5_128:
+// 				/* Get User Info */
+// 				pUserInfo = getUserIdInfo((uint8_t)pSessionInfo->UserId, BMCInst);
+// 				if (g_corefeatures.userpswd_encryption == ENABLED)
+// 				{
+// 					/* Get Encryption Key from the MBMCInfo_t structure */
+// 						memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
+// 					if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pSessionInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
+// 					{
+// 						TCRIT("Error in decrypting the user password for user ID:%d. .\n", pSessionInfo->UserId);
+// 						return -1;
+// 					}
+// 				}
+// 				else
+// 				{
+// 					_fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
+// 				}
+
+// 				MD5_128((char *)pUserInfo->UserPassword, MAX_PASSWORD_LEN,
+// 							(  INT8S*)pReqSession2Hdr, AuthCodeLen,
+// 							(  INT8S*)ComputedAuthCode, MAX_MD5_INTEGRITY_LEN);
+// 				Len= MD5_LEN;
+// 				break;
+				
+// 			case AUTH_HMAC_SHA256_128:
+		
+// 				hmac_sha256 ((unsigned char *)pSessionInfo->Key1, SHA2_HASH_KEY_SIZE, (unsigned char *)pReqSession2Hdr,
+// 						AuthCodeLen, (unsigned char *)ComputedAuthCode, SHA2_HASH_KEY_SIZE);                
+// 				Len= HMAC_SHA256_128_LEN;
+// 				break;                
+				
+// 			default:
+// 				IPMI_WARNING ("RMCP.c : Invalid Integrity Algorithm\n");
+// 				return 0;
+// 			}
+
+// 			IPMI_DBG_PRINT_BUF ((  uint8_t*)ComputedAuthCode, Len);
+// 			if (0 != _fmemcmp ((  uint8_t*)ComputedAuthCode, pReqMsgAuthCode, Len))
+// 			{
+// 				return 0;
+// 			}
+// 		}
+
+// 		/*  Decrypt the message if Encrypted */
+// 		/* Verify confidentiality header and trailer */
+// 		if (0 != (pReqSession2Hdr->PayloadType & CONFIDENT_MASK))
+// 		{
+// 			pConfHdr = (  uint8_t*)(pReqSession2Hdr + 1);
+// 			switch (pSessionInfo->ConfidentialityAlgorithm)
+// 			{
+// 			case CONF_AES_CBC_128:
+// 				pConfPayld   = pConfHdr + CONF_AES_CBC_128_HDR_LEN;
+// 				ConfPayldLen = IPMIMsgLen - CONF_AES_CBC_128_HDR_LEN;
+// 				aesDecrypt ((  uint8_t*)pConfPayld,  ConfPayldLen,
+// 							(  uint8_t*)pConfHdr, pSessionInfo->Key2,
+// 							(  uint8_t*)pBMCInfo->LANConfig.MsgReq.Data);
+
+// 				/* Remove pad length */
+// 				if (pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1] >  CONF_BLOCK_SIZE)
+// 				{
+// 					IPMI_WARNING ("Invalid Conf Blocke size  %d\n", pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1]);
+// 					return 0;
+// 				}
+
+// 				ConfPayldLen -= (pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1] + 1);
+// 				break;
+
+// 			case CONF_xCR4_128:
+
+// 			case CONF_xCR4_40:
+
+// 			default:
+// 				IPMI_WARNING ("RMCP.c : Invalid confidentiality Algorithm\n");
+// 				return 0;
+// 			}
+
+// 			pBMCInfo->LANConfig.MsgReq.Size = ConfPayldLen;
+// 		}
+// 		else
+// 		{
+// 			pBMCInfo->LANConfig.MsgReq.Size = IPMIMsgLen;
+// 			_fmemcpy (pBMCInfo->LANConfig.MsgReq.Data, pReq, pBMCInfo->LANConfig.MsgReq.Size);
+// 		}
+// 	}
+
+// 	/* Fill IPMI MsgPkt Request */
+// 	pBMCInfo->LANConfig.MsgReq.Cmd       = ((  IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->Cmd;
+// 	pBMCInfo->LANConfig.MsgReq.NetFnLUN  = ((  IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->NetFnLUN;
+// 	pBMCInfo->LANConfig.MsgReq.SessionID = SessionID;
+// 	pBMCInfo->LANConfig.MsgReq.SessionType = LAN_SESSION_TYPE;
+// 	pBMCInfo->LANConfig.MsgReq.Channel =Channel;
+// 	UpdateGetMsgTime( &pBMCInfo->LANConfig.MsgReq,IfcType, BMCInst);
+// 	// Moved to line 966
+// 	// Bug : if SessionID is 0 this Unlock will be called without a Lock
+// 	//UNLOCK_BMC_SHARED_MEM();
+
+// 	/* Process IPMI Request */
+// 	if (0 != ProcIPMIReq (pSessionInfo, Payload, pParams,Channel, BMCInst))
+// 	{
+// 		return 0;
+// 	}
+
+// 	/* Fill Response data */
+// 	_fmemcpy (pRMCPRes, pRMCPReq, sizeof (RMCPHdr_T) + sizeof (SessionHdr_T));
+
+
+// 	return Frame20Payload (pReqSession2Hdr->PayloadType, pRMCPRes,
+// 						   pBMCInfo->LANConfig.MsgRes.Data, pBMCInfo->LANConfig.MsgRes.Size, pSessionInfo, BMCInst);
+// }
+
+// /**************************************************************************** 
+//  * fn AddLoginEvent
+//  * params:
+//  * pRMCPSession  pointer to RMCP Session information
+//  * EvtType	0x9 - login, 0xa - logout, 0xb - autologout, 0xc - connection lost
+//  *
+//  * return 	0 - success, -1 - failure
+//  ***************************************************************************/
+// int AddLoginEvent ( uint8_t UserID, uint8_t* UserName, uint8_t EvtType )
+// {
+// 	  BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+	
+// 	int reslen = 0, ret = -1;
+// 	int i = 0;
+// 	AddSELRes_T  AddSelRes;
+// 	uint8_t IPAddr[IP_ADDR_LEN];
+// 	SELOEM1Record_T  OEMSELRec;
+	
+// #ifdef  CONFIG_SPX_FEATURE_IANA_0
+// 	uint8_t  MfgID[] = {  CONFIG_SPX_FEATURE_IANA_2,
+// 						CONFIG_SPX_FEATURE_IANA_1, 
+// 						CONFIG_SPX_FEATURE_IANA_0 };
+// #else
+// 	uint8_t MfgID[] = { 0, 0, 0 };
+// #endif
+// 	/* Hook for RMCP Login Audit */
+// 	if  (g_PDKHandle[PDK_RMCPLOGINAUDIT] != NULL) 
+// 	{
+// 		/* Return if event type bit is not set in event mask */
+// 		for (i = 0; i < sizeof(m_IPMIAuditMaskMap)/sizeof(IPMIAuditMaskTbl_T); i++)
+// 		{
+// 			if ((EvtType == m_IPMIAuditMaskMap[i].EventType) && 
+// 				(!(pBMCInfo->LoginAuditCfg.IPMIEventMask >> m_IPMIAuditMaskMap[i].EventMask) & 0x01))
+// 			{
+// 				return reslen;
+// 			}
+// 		}
+
+// 		ret = ((int(*)(uint8_t , uint8_t, uint8_t*, uint8_t*,int))(g_PDKHandle[PDK_RMCPLOGINAUDIT]))(EvtType, UserID, UserName, pBMCInfo->LANConfig.MsgReq.IPAddr, BMCInst);
+// 		if (ret != -1)
+// 		{
+// 			return 0;
+// 		}
+	
+// 		if(g_corefeatures.global_ipv6  == ENABLED)
+// 		{
+// 			if(IN6_IS_ADDR_V4MAPPED(pBMCInfo->LANConfig.MsgReq.IPAddr))
+// 			{
+// 				/* The last bytes of IP6 contains IP4 address */
+// 				_fmemcpy(IPAddr, &pBMCInfo->LANConfig.MsgReq.IPAddr[IP6_ADDR_LEN - IP_ADDR_LEN], sizeof (struct in_addr));
+// 			}
+// 			else
+// 			{
+// 				/*
+// 				*  IPV6 address so it will be filled with 0xff. 
+// 				*/
+// 				memset(IPAddr, 0xFF, sizeof (struct in_addr));
+// 			}
+// 		}
+// 		else
+// 		{
+// 			_fmemcpy(IPAddr, pBMCInfo->LANConfig.MsgReq.IPAddr, sizeof (struct in_addr));
+// 		}
+
+// 		/* This structure values are AMI specific SEL Record data */
+// 		OEMSELRec.ID = 0x00;
+// 		OEMSELRec.Type = 0xc1;
+// 		OEMSELRec.TimeStamp = 0x00;
+// 		memcpy(OEMSELRec.MftrID, MfgID, sizeof(MfgID));
+// 		OEMSELRec.OEMData[0] = EvtType;
+// 		OEMSELRec.OEMData[1] = UserID;
+// 		memcpy (&OEMSELRec.OEMData[2], IPAddr, IP_ADDR_LEN);
+		
+// 		OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SELConfig.SELMutex, WAIT_INFINITE);
+// 		/*we are not posting login/logout audit logs to PEF*/
+// 		reslen = LockedAddSELEntry((uint8_t *)&OEMSELRec, sizeof(SELOEM1Record_T), (uint8_t *)&AddSelRes, FALSE,POST_ONLY_SEL, BMCInst);
+// 		/* Enable Reservation ID which was cancelled by this event */
+// 		pBMCInfo->SELConfig.RsrvIDCancelled = FALSE;
+// 		OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SELConfig.SELMutex);
+
+// 		return ( (sizeof(uint8_t) == reslen) ? -1 : 0 );  //reslen is only Completion code size if error
+// 	}
+// 	return 0;
+// }
+
+#endif /*#if IPMI20_SUPPORT*/

+ 103 - 0
app/bmc/lan/RMCP.h

@@ -0,0 +1,103 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ *****************************************************************
+ *
+ * rmcp.h
+ * RMCP Packet Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#ifndef RMCP_H
+#define RMCP_H
+
+#include "com_BmcType.h"
+#include "com_IPMI_RMCP.h"
+#include "com_IPMIDefs.h"
+
+
+/* Integrity Algorithm Numbers */
+#define AUTH_NONE                   0
+#define AUTH_HMAC_SHA1_96           1
+#define AUTH_HMAC_MD5_128           2
+#define AUTH_MD5_128                3
+#define AUTH_HMAC_SHA256_128        4
+
+#define CONF_AES_CBC_128            1
+#define CONF_xCR4_128               2
+#define CONF_xCR4_40                3
+
+/* Login Event OEMType definitions */
+#define EVENT_LOGIN 	            0x9
+#define EVENT_LOGOUT 	            0xA
+#define EVENT_AUTO_LOGOUT           0xB
+#define EVENT_LOGIN_FAILURE         0xE
+
+#define NULL_USER                   1
+// /**
+//  * This structure holds various params/flags that are collected/accumulated/set/reset on the way during the flow of packets in API chain.
+//  * 
+// */
+// typedef struct {
+//     uint8_t	IsPktFromLoopBack; /** packet is received thru LoopBack */
+//     uint8_t	IsPktFromVLAN; /** packet is received thru VLAN */
+// }MiscParams_T;
+
+// /**
+//  * @var   uint32_t g_DeleteThisLANSSession
+//  * @brief Flag indicates LAN ifc to delete the session after sending response
+//  **/
+// //extern      uint32_t      g_DeleteThisLANSessionID;
+
+
+// /**
+//  * @brief Process RMCP request received over LAN interface.
+//  * @param pRMCPReq - Request message.
+//  * @param pRMCPRes - Response message.
+//  * @return Message length.
+// **/
+// extern uint32_t ProcessRMCPReq(  RMCPHdr_T* pRMCPReq,   RMCPHdr_T* pRMCPRes, MiscParams_T *pParams,uint8_t Channel, int BMCInst);
+
+
+// *
+//  * @brief Compute authentication code.
+//  * @param pPassword     - User password.
+//  * @param pSessionHdr   - Session header RMCP message.
+//  * @param pIPMIMsg      - IPMI message payload.
+//  * @param pAuthCode     - Authentication Code being generated.
+//  * @param ChannelType   - Channel Type.
+// *
+// extern void  ComputeAuthCode (  uint8_t* pPassword,   SessionHdr_T* pSessionHdr,
+//                                 IPMIMsgHdr_T* pIPMIMsg,   uint8_t* pAuthCode,
+//                               uint8_t ChannelType);
+
+
+// /**
+//  * @brief Frame IPMI 2.0 payload.
+//  * @param PayloadType - Payload Type.
+//  * @param pRMCPPkt    - RMCP data.
+//  * @param pPayload    - Payload data.
+//  * @param PayloadLen  - Payload Length.
+//  * @param pSessionInfo - Session information.
+//  * @return 0 if success, -1 if error.
+// **/
+// extern int   Frame20Payload     (uint8_t PayloadType,   RMCPHdr_T* pRMCPPkt,
+//                                    uint8_t* pPayload,  uint32_t PayloadLen,  
+//                                  SessionInfo_T* pSessionInfo, int BMCInst);
+
+
+// extern int AddLoginEvent ( uint8_t UserID, uint8_t* UserName, uint8_t EvtType, int BMCInst);
+
+
+#endif /* RMCP_H */

+ 285 - 0
app/bmc/main.c

@@ -0,0 +1,285 @@
+/*
+* bmc_app application main code.
+*/
+
+
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/prctl.h>
+#include <semaphore.h>
+#include <pthread.h>
+//#include <fcntl.h>
+#include "linux/fcntl.h"
+#include <signal.h>
+#include <sys/time.h>
+
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+#include "com_Message.h"
+
+#include "BmcType.h"
+#include "main.h"
+#include "Session.h"
+
+#include "LANIfc.h"
+#include "UDSIfc.h"
+#include "IPMBIfc.h"
+#include "MsgHndlrTask.h"
+#include "ChassisTimerTask.h"
+#include "TimerTask.h"
+#include "CM_LIB.h"
+#include "stm32f429xx.h"
+#include "com_gpio.h"
+#include "hal_interface_api.h"
+#include "com_BMCCfg.h"
+#include "PendActionTask.h"
+#include "Api.h"
+#include "driver.h"
+#include "sensor_tbl.h"
+#include "com_IPMI_SDRRecord.h"
+
+
+/* gloabl varible */
+BMCInfo_t 	g_BMCInfo;
+pthread_t 	gThreadIDs[256];
+uint8_t		gThreadIndex = 0;
+SensorHistoryInfo_T 	gSensorHistoryInfo[SENSOR_NUMBERS];
+
+FanInfo_T	gFanInfo[FAN_NUMBERS] = {
+								// /* Index | name | mode | level | speed  */
+								// 	{0, {"Fan1"}, 0, 0, 0 },
+								// 	{1, {"Fan2"}, 0, 0, 0 },
+								// 	{2, {"Fan3"}, 0, 0, 0 },
+								// 	{3, {"Fan4"}, 0, 0, 0 },
+								};
+BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
+								/*  healthStatus | name | slotID | pwrStatus */
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "test", 7, 1},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+								};
+//void *test_thread(void *var);
+//uint8_t test_flag = 0;
+
+
+
+static int tmp_fd;
+void main(void)
+{
+	if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
+	{
+		printf("Initialize AT88SC0104C failed!\n");
+		sleep(1);
+		return;
+	}
+	printf("cm_Auth_Encrp_Init ok\n");
+
+#if 0
+	if(0 != cm_Auth_Encrp_Personal(1, 1))
+	{
+		printf("Personal AT88SC0104C failed!\n");
+		sleep(1);
+		return ;
+	}
+#endif
+
+	if(0 != test_cryptomem())
+	{
+		while(1)
+		{
+			printf("Illegal Board!\n");
+			sleep(3);
+		}
+	}
+
+	PlatformInit();
+	Init_IPMI_FRU_SDR_SEL();
+	Init_SessionTbl();
+	InitTimerTaskTbl();
+
+	pthread_mutex_init(&api_bridge_mutex, NULL);
+	pthread_mutex_init(&Flash_Mutex, NULL);
+
+	//初始化系统时间
+	system("date -s 2020.05.12-00:00:00");
+
+	//Initialize IP
+	char cmdStr[100];
+	LanInfo_T *pSetLanInfo = &g_BMCInfo.LanInfo[0];
+	// //down
+	// sprintf(cmdStr, "ifconfig %s down", pSetLanInfo->EthName);
+	// printf("%s\n", cmdStr);
+	// system(cmdStr);
+	// //set mac
+	// sprintf(cmdStr, "ifconfig %s hw ether %02x:%02x:%02x:%02x:%02x:%02x", 
+	// 	pSetLanInfo->EthName, pSetLanInfo->MACAddr[0], pSetLanInfo->MACAddr[1],
+	// 	pSetLanInfo->MACAddr[2], pSetLanInfo->MACAddr[3], 
+	// 	pSetLanInfo->MACAddr[4], pSetLanInfo->MACAddr[5]);
+	// printf("%s\n", cmdStr);
+	// system(cmdStr);
+	//ip, broadcast, netmask
+	sprintf(cmdStr, "ifconfig %s %d.%d.%d.%d broadcast %d.%d.%d.%d netmask %d.%d.%d.%d up",
+		pSetLanInfo->EthName, pSetLanInfo->IPAddr[0], pSetLanInfo->IPAddr[1],
+		pSetLanInfo->IPAddr[2], pSetLanInfo->IPAddr[3], pSetLanInfo->BroadCast[0],
+		pSetLanInfo->BroadCast[1], pSetLanInfo->BroadCast[2], pSetLanInfo->BroadCast[3],
+		pSetLanInfo->NetMask[0], pSetLanInfo->NetMask[1], pSetLanInfo->NetMask[2],
+		pSetLanInfo->NetMask[3]);
+	printf("%s\n", cmdStr);
+	system(cmdStr);
+
+	printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.ChassisID, g_BMCInfo.SlotID);
+	if(g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
+	{
+		printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.PrimaryIPMBBus, 
+			PRIMARY_IPMB_CHANNEL, g_BMCInfo.PrimaryIPMBAddr);
+	}
+	if(g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
+	{
+		printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.SecondaryIPMBBus,
+			SECONDARY_IPMB_CHANNEL, g_BMCInfo.SecondaryIPMBAddr);
+	}
+
+	/* Create TimerTask */
+	// gThreadIndex = 0;
+	// if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,TimerTask,NULL))
+ //    {
+ //        printf("%s: Create TimerTask thread failed!\n", __FUNCTION__);
+ //    }
+	signal(SIGALRM, TimerTask);
+
+    struct itimerval new_value;
+    new_value.it_value.tv_sec = 0;
+    new_value.it_value.tv_usec = 1;
+    new_value.it_interval.tv_sec = 1;
+    new_value.it_interval.tv_usec = 0;
+    setitimer(ITIMER_REAL, &new_value, NULL);
+
+
+	/* Create MsgHndlr Task */
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,MsgHndlrTask,NULL))
+    {
+        printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
+    }
+
+    /* Create ChassisTimerTask */
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,ChassisTimerTask,NULL))
+    {
+        printf("%s: Create ChassisTimerTask thread failed!\n", __FUNCTION__);
+    }
+
+   /* Create SensorMonitorTask */
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,SensorMonitorTask,NULL))
+   {
+       printf("%s: Create SensorMonitorTask thread failed!\n", __FUNCTION__);
+   }
+
+	/* Create UDS interface */
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,UDSIfcTask,NULL))
+    {
+        printf("%s: Create UDSIfcTask thread failed!\n", __FUNCTION__);
+    }
+
+	/* Create LAN interface */
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,LANIfcTask,NULL))
+    {
+        printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
+    }
+
+	/* Create IPMB interface */
+	uint8_t primaryIpmbSelect = 0;	//primary
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
+  {
+      printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
+  }
+
+  uint8_t secondaryIpmbSelect = 1;	//secondary
+  gThreadIndex++;
+  if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
+  {
+      printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
+  }
+
+    /* Create PendActionTask */
+	gThreadIndex++;
+	if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,PendActionTask,NULL))
+    {
+        printf("%s: Create PendActionTask thread failed!\n", __FUNCTION__);
+    }
+
+	/* Create Update FPGA thread */
+
+	/* Create UDS interface */
+
+	/* Create UDS interface */
+
+	/* Create UDS interface */
+
+    // pthread_mutex_init(&mutex,NULL);
+    // tmp_fd = open("/dev/i2c2", O_RDWR);;
+    // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
+    // gThreadIndex++;
+    // pthread_create(&gThreadIDs[gThreadIndex],NULL,test_thread,NULL);
+
+    /* 看门狗,10s无喂狗就复位 */
+    int fd_iwdg = open("/dev/iwdg", O_RDWR);
+    ioctl(fd_iwdg, START_IWATCHDOG, NULL);       //打开看狗      
+
+	while(1)	//在这里实现各线程的健康状态检测,发现出错的线程就重启它。
+	{
+		//喂看门狗
+	    if(ioctl(fd_iwdg, FEED_WATCHDOG, NULL) != 0)
+	    {
+	            printf("---> Feed watchdog failed\n");
+	    }
+
+		sleep(1);
+	}
+}
+
+// void *test_thread(void *var)
+// {
+// 	uint8_t len, i;
+// 	uint8_t recvBuf[100];
+// 	printf("---> test_thread start...\n");
+// 	stm32_i2c_set_addr(tmp_fd, 0x44);
+// 	uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
+// 	while(1)
+// 	{
+// 		pthread_mutex_lock(&mutex);
+// 		pthread_mutex_unlock(&mutex);
+// 		len = 0;
+//     	len = stm32_i2c_slave_recv(tmp_fd, recvBuf);
+//     	if(len > 0)
+//     	{
+// 	    	printf("Recv: ");
+// 	    	for(i=0;i<len; i++)
+// 	    		printf("%#x ", recvBuf[i]);
+// 	    	printf("\n");
+
+// 	    	test_flag = 1;
+// 	    	//sleep(1);
+// 	  //   	if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
+// 			// {
+// 			// 	printf("---> Send ipmb error!\n");
+// 			// }
+// 			// else
+// 			// 	printf("---> send ipmb ok\n");
+// 		}
+// 	}
+
+
+// }

+ 127 - 0
app/bmc/main.h

@@ -0,0 +1,127 @@
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+#include <stdint.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+#include "BmcType.h"
+#include "com_IPMI_SDRRecord.h"
+
+
+#include "Session.h"
+#include "sensor_tbl.h"
+#include "MsgHndlr.h"
+#include "hal_interface_api.h"
+#include "com_BMCCfg.h"
+/* Declare global variable */
+
+
+/*---------------------------------------------------------------------------*
+ * Interface SUPPORTED
+ *---------------------------------------------------------------------------*/
+#define LAN_IFC_SUPPORT					1
+#define SERIAL_IFC_SUPPORT				0
+#define SERIAL_TERMINAL_SUPPORT			0
+#define SYS_IFC_SUPPORT					0
+#define PRIMARY_IPMB_SUPPORT		1
+#define SECONDARY_IPMB_SUPPORT		1
+#define GROUP_EXTERN_SUPPORT		1
+#define UDS_IFC_SUPPORT				1
+
+
+#define PWR_CYCLE_INTERVAL			(3) 	//unit: 1s
+#define REARM_SET_SENSOR_THRESHOLD	(0)		//whether rearm sensor event when change sensor threshold
+#define CHASSIS_TIMER_INTERVAL		(1)		//1 second
+#define FAN_CONTROL_INTERVAL		(5)		//5	second 
+//IPMB
+#define PRIMARY_IPMB_BUS			1	// /dev/i2c1
+#define SECONDARY_IPMB_BUS			2	// /dev/i2c2
+//#define PRIMARY_IPMB_ADDR			0x44
+//#define SECONDARY_IPMB_ADDR			0x44
+
+//RACK-ID
+#define RACKID0_PORT	GPIOI
+#define RACKID1_PORT	GPIOI
+#define RACKID2_PORT	GPIOH
+#define RACKID3_PORT	GPIOI
+#define RACKID4_PORT	GPIOI
+#define RACKID5_PORT	GPIOI
+#define RACKID0_PIN		GPIO_PIN_6
+#define RACKID1_PIN		GPIO_PIN_7
+#define RACKID2_PIN		GPIO_PIN_15
+#define RACKID3_PIN		GPIO_PIN_9
+#define RACKID4_PIN		GPIO_PIN_10
+#define RACKID5_PIN		GPIO_PIN_11
+
+//SLOT-ID
+#define GA0_PORT	GPIOH
+#define GA1_PORT	GPIOH
+#define GA2_PORT	GPIOH
+#define GA3_PORT	GPIOH
+#define GA4_PORT	GPIOH
+#define GAP_PORT	GPIOI
+#define GA0_PIN		GPIO_PIN_10
+#define GA1_PIN		GPIO_PIN_11
+#define GA2_PIN		GPIO_PIN_12
+#define GA3_PIN		GPIO_PIN_13
+#define GA4_PIN		GPIO_PIN_14
+#define GAP_PIN		GPIO_PIN_5
+
+#define GPIO1_PORT	GPIOC
+#define GPIO2_PORT	GPIOC
+#define GPIO3_PORT	GPIOD
+#define GPIO4_PORT	GPIOD
+#define GPIO5_PORT	GPIOD
+#define GPIO6_PORT	GPIOE
+#define GPIO7_PORT	GPIOE
+#define GPIO8_PORT	GPIOE
+#define GPIO1_PIN 	GPIO_PIN_12
+#define GPIO2_PIN 	GPIO_PIN_13
+#define GPIO3_PIN 	GPIO_PIN_2
+#define GPIO4_PIN 	GPIO_PIN_3
+#define GPIO5_PIN 	GPIO_PIN_6
+#define GPIO6_PIN 	GPIO_PIN_2
+#define GPIO7_PIN 	GPIO_PIN_3
+#define GPIO8_PIN 	GPIO_PIN_4
+
+extern sensor_tbl_t 				sensor_tbl[];
+extern const OemFRUData_T 			Default_FRUData;
+//extern OEM_SENSOR_CAPABILITY_T 		g_sensorList[SENSOR_NUMBERS];
+extern const MgmtCtrlrDevLocator_T 	bmc_sdr;
+extern const FullSensorRec_T 		full_sdr_tbl[];
+extern const CompactSensorRec_T 	Compact_sdr_tbl[];
+
+#define RESTORE_IPMI 	0x01
+#define RESTORE_FRU		0x02
+#define RESTORE_SDR		0x04
+#define RESTORE_SEL		0x08
+#define RESTORE_ALL		(RESTORE_IPMI | RESTORE_FRU | RESTORE_SDR | RESTORE_SEL)
+
+
+extern pthread_t 	gThreadIDs[256];
+extern uint8_t		gThreadIndex;
+
+extern int gFd_LanIfcQ, gFd_LanResQ;
+extern int gFdUdsIfc, gFdUdsRes;
+extern int gFd_MsgHndlrIfc;
+//extern int gFd_ChassisPwrHndlrQue;
+extern int gFd_PrimaryIpmbIfcQ, gFd_PrimaryIpmbResQ;
+extern int gFd_SecondaryIpmbIfcQ, gFd_SecondaryIpmbResQ;
+extern int gPendActionIfc;
+extern TLS_T g_tls;
+extern PendingBridgedResTbl_T	m_PendingBridgedResTbl[MAX_PENDING_BRIDGE_TBL][MAX_PENDING_BRIDGE_RES];
+extern PendingSeqNoTbl_T		m_PendingSeqNoTbl[16][MAX_PENDING_SEQ_NO];
+extern KCSBridgeResInfo_T       m_KCSBridgeResInfo;
+extern TimerTaskTbl_T    		m_TimerTaskTbl [20];
+
+extern BMCInfo_t 			g_BMCInfo;
+extern SensorHistoryInfo_T 	gSensorHistoryInfo[SENSOR_NUMBERS];
+extern FanInfo_T			gFanInfo[FAN_NUMBERS];
+extern BladeStatus_T 		gBladeStatus[BLADE_NUMBERS];
+
+#endif /* __MAIN_H__ */

+ 133 - 0
app/bmc/message.c

@@ -0,0 +1,133 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/prctl.h>
+#include "com_IPMI_App.h"
+#include "com_IPMIDefs.h"
+#include "com_Message.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+/**
+ ** @fn PostMsg
+ ** @brief Post a message to the destination task.
+ ** @param MsgPkt   - Message to be posted.
+ ** @param Queue       - Queue to post this message to.
+ ** @return   0 if success, -1 if failed.
+ ***/
+int
+PostMsg (int fd, MsgPkt_T* pMsgPkt)
+{
+    int     Err,i=0;
+    uint16_t  Size;
+
+    Size    = sizeof (MsgPkt_T) - MSG_PAYLOAD_SIZE + pMsgPkt->Size;
+    
+    Err = write (fd, pMsgPkt, Size) ;
+    if ((Err == -1) || (Err != Size))
+    {
+        printf ("Message.c : PostMsg %x %s\n",errno, strerror(errno));
+        return -1;
+    }             
+
+    //printf("---> PostMsg ok, fd = %d\n", fd);
+    return 0;
+}
+
+
+/*------ Get the message from the queue -----------------------------*/
+int OS_GET_FROM_Q( int fd, uint8_t *pBuf, int Size, int16_t timeout)    
+{                                                           
+    int ReadLen = 0, Left, Len;
+    int Err = 0;                             
+    Left = Size;                                            
+    while( Left > 0 )                                       
+    {                                                       
+        Len = read (fd, (uint8_t*)pBuf + ReadLen, Left ); 
+        if( Len < 0 )                                       
+        {                                                   
+            if( errno == EINTR || errno == EAGAIN )         
+            {                                               
+                continue;                                   
+            }                                               
+            else                                            
+            {                                               
+                Err = -1;                                 
+                break;                                      
+            }                                               
+        }                                                   
+        ReadLen += Len;                                     
+        Left -= Len;                                        
+    }                                                       
+    Err = ReadLen;                                        
+    return Err;
+}
+
+/**
+ * @fn GetMsg
+ * @brief Gets the message posted to this task.
+ * @param MsgPkt   - Pointer to the buffer to hold the message packet.
+ * @param Queue    - Queue to fetch the message from.
+ * @param Timeout    - Number of seconds to wait.
+ * 
+ * WAIT_NONE       - If the function has to return immediately.
+ * WAIT_INFINITE   - If the function has to wait infinitely.
+ * NOTE :
+ * @return   0 if success, -1 if failed.
+**/
+int
+GetMsg (int fd, MsgPkt_T* pMsgPkt, int16_t Timeout)
+{
+    int     Err;
+    int     Size;
+    
+    /* check for limited wait time */
+    if (Timeout >= 0)
+    {
+        struct timeval      Timeval;
+        fd_set              fdRead;
+        int                 n, RetVal;
+
+        FD_ZERO (&fdRead);
+        FD_SET (fd, &fdRead);
+        n = fd + 1;
+
+        Timeval.tv_sec  = Timeout;
+        Timeval.tv_usec = 0;
+        RetVal = select (n, &fdRead, NULL, NULL, &Timeval);
+        if (-1 == RetVal)
+        {
+            printf ("Message.c : Error waiting on Queue, log1\n");
+            return -1;
+        }
+        else if (0 == RetVal)
+        {
+            //printf ("Message.c : Error waiting on Queue, log2\n");
+            return -2;
+        }
+    }
+
+    /* Get the header first*/
+    Size = sizeof (MsgPkt_T) - MSG_PAYLOAD_SIZE;
+
+    if(-1 == OS_GET_FROM_Q (fd, (uint8_t*)pMsgPkt, Size, WAIT_INFINITE))
+    {
+        printf ("Message.c : GetMsg %s\n",strerror(errno));
+        return -1;
+    }
+
+    /* Get the payload data */
+    Size = pMsgPkt->Size;
+    if(-1 == OS_GET_FROM_Q (fd, pMsgPkt->Data, Size, WAIT_INFINITE))
+    {
+        printf ("Message.c : GetMsg %s\n",strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}

+ 30 - 0
app/bmc/message.h

@@ -0,0 +1,30 @@
+#ifndef __MESSAGE_H__
+#define __MESSAGE_H__
+
+/**
+ ** @fn PostMsg
+ ** @brief Post a message to the destination task.
+ ** @param MsgPkt   - Message to be posted.
+ ** @param Queue       - Queue to post this message to.
+ ** @return   0 if success, -1 if failed.
+ ***/
+int
+PostMsg (int fd, MsgPkt_T* pMsgPkt);
+
+/**
+ * @fn GetMsg
+ * @brief Gets the message posted to this task.
+ * @param MsgPkt   - Pointer to the buffer to hold the message packet.
+ * @param Queue    - Queue to fetch the message from.
+ * @param Timeout    - Number of seconds to wait.
+ * 
+ * WAIT_NONE       - If the function has to return immediately.
+ * WAIT_INFINITE   - If the function has to wait infinitely.
+ * NOTE :
+ * @return   0 if success, -1 if failed.
+**/
+int
+GetMsg (int fd, MsgPkt_T* pMsgPkt, int16_t Timeout);
+
+
+#endif /* __MESSAGE_H__ */

+ 112 - 0
app/bmc/msghndlr/App/App.c

@@ -0,0 +1,112 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ *****************************************************************
+ *
+ * App.c
+ * Application Command Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com> 
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ * 
+ *****************************************************************/
+#include "MsgHndlr.h"
+#include "com_IPMI_App.h"
+#include "com_IPMI_IPM.h"
+//#include "com_IPMI_Firewall.h"
+#include "com_IPMI_App+.h"
+#include "Support.h"
+#include "com_IPMI_AppDevice.h"
+
+/*** Global Variables ***/
+const CmdHndlrMap_T g_App_CmdHndlr [] =	//notice!
+{
+#if IPM_DEVICE == 1
+    /*------------------------- IPM Device Commands -------------------------*/
+    { CMD_GET_DEV_ID,               PRIV_USER,      GET_DEV_ID,             0x00,                           0xAAAA , 0xFFFF},
+//    { CMD_BROADCAST_GET_DEV_ID,     PRIV_LOCAL,     BROADCAST_GET_DEV_ID,   0x00,                           0xAAAA ,0xFFFF},
+    { CMD_COLD_RESET,               PRIV_ADMIN,     COLD_RESET,             0x00,                           0xAAAA ,0xFFFF},
+    { CMD_WARM_RESET,               PRIV_ADMIN,     WARM_RESET,             0x00,                           0xAAAA , 0xFFFF},
+    { CMD_GET_SELF_TEST_RESULTS,    PRIV_USER,      GET_SELF_TEST_RESULTS,  0x00,                           0xAAAA , 0xFFFF},
+    { CMD_MFG_TEST_ON,              PRIV_ADMIN,     MFG_TEST_ON,            0xFF,                           0xAAAA ,0xFFFF},
+    { CMD_SET_ACPI_PWR_STATE,       PRIV_ADMIN,     SET_ACPI_PWR_STATE,     sizeof (SetACPIPwrStateReq_T),  0xAAAA ,0xFFFF},
+    { CMD_GET_ACPI_PWR_STATE,       PRIV_USER,      GET_ACPI_PWR_STATE,     0x00,                           0xAAAA ,0xFFFF},
+    { CMD_GET_DEV_GUID,             PRIV_USER,      GET_DEV_GUID,           0x00,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_NETFN_SUP,            PRIV_USER,      GET_NETFN_SUP,          0x01,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_CMD_SUP,              PRIV_USER,      GET_CMD_SUP,            0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_SUBFN_SUP,            PRIV_USER,      GET_SUBFN_SUP,          0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_CONFIG_CMDS,          PRIV_USER,      GET_CONFIG_CMDS,        0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_CONFIG_SUB_FNS,       PRIV_USER,      GET_CONFIG_SUB_FNS,     0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_SET_CMD_ENABLES,          PRIV_USER,      SET_CMD_ENABLES,        0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_CMD_ENABLES,          PRIV_USER,      GET_CMD_ENABLES,        0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_SET_SUBFN_ENABLES,        PRIV_USER,      SET_SUBFN_ENABLES,      sizeof (SetSubFnEnablesReq_T),  0xAAAA ,0xFFFF},
+//    { CMD_GET_SUBFN_ENABLES,        PRIV_USER,      GET_SUBFN_ENABLES,      sizeof (GetSubFnEnablesReq_T),  0xAAAA ,0xFFFF},
+//    { CMD_GET_OEM_NETFN_IANA_SUPPORT,    PRIV_USER,      GET_OEM_NETFN_IANA_SUPPORT,      sizeof (GetOEMNetFnIANASupportReq_T),  0xAAAA ,0xFFFF},
+#endif /* IPM_DEVICE */
+
+#if APP_DEVICE == 1
+//    /*--------------------- Watch Dog Timer Commands -----------------------*/
+//    { CMD_RESET_WDT,                PRIV_OPERATOR,  RESET_WDT,              0x00,                           0xAAAA ,0xFFFF},
+//    { CMD_SET_WDT,                  PRIV_OPERATOR,  SET_WDT,                sizeof (SetWDTReq_T),           0xAAAA ,0xFFFF},
+//    { CMD_GET_WDT,                  PRIV_USER,      GET_WDT,                0x00,                           0xAAAA ,0xFFFF},
+
+//    /*----------------- BMC Device and Messaging Commands ------------------*/
+//    { CMD_SET_BMC_GBL_ENABLES,      PRIV_LOCAL,   SET_BMC_GBL_ENABLES,    sizeof (uint8_t),                 0xAAAA ,0xFFFF},
+//    { CMD_GET_BMC_GBL_ENABLES,      PRIV_USER,      GET_BMC_GBL_ENABLES,    0x00,                           0xAAAA ,0xFFFF},
+//    { CMD_CLR_MSG_FLAGS,            PRIV_LOCAL,   CLR_MSG_FLAGS,          sizeof (uint8_t),                 0xAAAA ,0xFFFF},
+//    { CMD_GET_MSG_FLAGS,            PRIV_LOCAL,   GET_MSG_FLAGS,          0x00,                           0xAAAA ,0xFFFF},
+//    { CMD_ENBL_MSG_CH_RCV,          PRIV_LOCAL,   ENBL_MSG_CH_RCV,        sizeof (EnblMsgChRcvReq_T),     0xAAAA ,0xFFFF},
+    { CMD_GET_MSG,                  PRIV_LOCAL,      GET_MSG,                0x00,                           0xAAAA ,0xFFFF},
+    { CMD_SEND_MSG,                 PRIV_USER,      SEND_MSG,               0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_READ_EVT_MSG_BUFFER,      PRIV_LOCAL,     READ_EVT_MSG_BUFFER,    0x00,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_BTIFC_CAP,            PRIV_USER,      GET_BTIFC_CAP,          0x00,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_SYSTEM_GUID,          PRIV_NONE,      GET_SYSTEM_GUID,        0x00,                           0xAAAA ,0xFFFF},
+    { CMD_GET_CH_AUTH_CAP,          PRIV_NONE,      GET_CH_AUTH_CAP,        sizeof (GetChAuthCapReq_T),     0xAAAA ,0xFFFF},
+    { CMD_GET_SESSION_CHALLENGE,    PRIV_NONE,      GET_SESSION_CHALLENGE,  sizeof (GetSesChallengeReq_T),  0xAAAA ,0xFFFF},
+    { CMD_ACTIVATE_SESSION,         PRIV_NONE,      ACTIVATE_SESSION,       sizeof (ActivateSesReq_T),      0xAAAA ,0xFFFF},
+    { CMD_SET_SESSION_PRIV_LEVEL,   PRIV_USER,      SET_SESSION_PRIV_LEVEL, sizeof (uint8_t),                 0xAAAA ,0xFFFF},
+    { CMD_CLOSE_SESSION,            PRIV_CALLBACK,  CLOSE_SESSION,          0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_SESSION_INFO,         PRIV_USER,      GET_SESSION_INFO,       0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_AUTH_CODE,            PRIV_OPERATOR,  GET_AUTH_CODE,          sizeof (GetAuthCodeReq_T),      0xAAAA ,0xFFFF},
+//    { CMD_SET_CH_ACCESS,            PRIV_ADMIN,     SET_CH_ACCESS,          sizeof (SetChAccessReq_T),      0xAAAA ,0xFFFF},
+//    { CMD_GET_CH_ACCESS,            PRIV_USER,      GET_CH_ACCESS,          sizeof (GetChAccessReq_T),      0xAAAA ,0xFFFF},
+//    { CMD_GET_CH_INFO,              PRIV_USER,      GET_CH_INFO,            sizeof (uint8_t),                 0xAAAA ,0xFFFF},
+    { CMD_SET_USER_ACCESS,          PRIV_ADMIN,     SET_USER_ACCESS,        0xFF,    0xAAAA ,0xFFFF},
+    { CMD_GET_USER_ACCESS,          PRIV_OPERATOR,  GET_USER_ACCESS,        sizeof (GetUserAccessReq_T),    0xAAAA ,0xFFFF},
+    { CMD_SET_USER_NAME,            PRIV_ADMIN,     SET_USER_NAME,          0xff,      0xAAAA ,0xFFFF},
+    { CMD_GET_USER_NAME,            PRIV_OPERATOR,  GET_USER_NAME,          sizeof (uint8_t),                 0xAAAA ,0xFFFF},
+    { CMD_SET_USER_PASSWORD,        PRIV_ADMIN,     SET_USER_PASSWORD,      0xFF,      0xAAAA ,0xFFFF},
+//    { CMD_MASTER_WRITE_READ,        PRIV_OPERATOR,  MASTER_WRITE_READ,      0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_SET_SYSTEM_INFO_PARAM,    PRIV_ADMIN,     SET_SYSTEM_INFO_PARAM,  0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_SYSTEM_INFO_PARAM,    PRIV_USER ,  GET_SYSTEM_INFO_PARAM,  sizeof (GetSystemInfoParamReq_T),      0xAAAA ,0xFFFF},
+
+//    /*------------------------ IPMI 2.0 specific Commands ------------------*/
+//    { CMD_ACTIVATE_PAYLOAD,         PRIV_CALLBACK,  ACTIVATE_PAYLOAD,       sizeof (ActivatePayloadReq_T),  0xAAAA ,0xFFFF},
+//    { CMD_DEACTIVATE_PAYLOAD,       PRIV_CALLBACK,  DEACTIVATE_PAYLOAD,     sizeof (DeactivatePayloadReq_T),0xAAAA ,0xFFFF},
+//    { CMD_GET_PAYLD_ACT_STATUS,     PRIV_USER,      GET_PAYLD_ACT_STATUS,   1,                              0xAAAA ,0xFFFF},
+//    { CMD_GET_PAYLD_INST_INFO,      PRIV_USER,      GET_PAYLD_INST_INFO,    2,                              0xAAAA ,0xFFFF},
+//    { CMD_SET_USR_PAYLOAD_ACCESS,   PRIV_ADMIN,     SET_USR_PAYLOAD_ACCESS, sizeof (SetUsrPayldAccReq_T),   0xAAAA ,0xFFFF},
+//    { CMD_GET_USR_PAYLOAD_ACCESS,   PRIV_OPERATOR,  GET_USR_PAYLOAD_ACCESS, sizeof (GetUsrPayldAccReq_T),   0xAAAA ,0xFFFF},
+//    { CMD_GET_CH_PAYLOAD_SUPPORT,   PRIV_USER,      GET_CH_PAYLOAD_SUPPORT, 1,                              0xAAAA ,0xFFFF},
+//    { CMD_GET_CH_PAYLOAD_VER,       PRIV_USER,      GET_CH_PAYLOAD_VER,     sizeof (GetChPayldVerReq_T),    0xAAAA ,0xFFFF},
+//    { CMD_GET_CH_OEM_PAYLOAD_INFO,  PRIV_USER,      GET_CH_OEM_PAYLOAD_INFO,sizeof (GetChOemPayldInfoReq_T),0xAAAA ,0xFFFF},
+//    { CMD_GET_CH_CIPHER_SUITES,     PRIV_NONE,      GET_CH_CIPHER_SUITES,   sizeof (GetChCipherSuitesReq_T),0xAAAA ,0x0001},
+//    { CMD_SUS_RES_PAYLOAD_ENCRYPT,  PRIV_USER,      SUS_RES_PAYLOAD_ENCRYPT,sizeof (SusResPayldEncryptReq_T),0xAAAA ,0xFFFF},
+//    { CMD_SET_CH_SECURITY_KEYS,     PRIV_ADMIN,     SET_CH_SECURITY_KEYS,   0xFF,                           0xAAAA ,0xFFFF},
+//    { CMD_GET_SYS_IFC_CAPS,         PRIV_USER,      GET_SYS_IFC_CAPS,       1,                              0xAAAA ,0xFFFF},
+
+#endif  /* APP_DEVICE */
+    { 0x00,                         0x00,           0x00,                   0x00,                           0x0000 ,         0x0000}
+};
+

+ 19 - 0
app/bmc/msghndlr/App/App.h

@@ -0,0 +1,19 @@
+/*
+* Brief:	The header file of MsgHndlr_App packet.
+* Author:	Jimbo_Zhang@outlook.com
+* Date:		2019-9-16
+*/
+
+#ifndef __MSG_HNDLR_APP_H__
+#define __MSG_HNDLR_APP_H__
+
+#include "MsgHndlr.h"
+
+
+/*** Extern Definitions ***/
+extern const CmdHndlrMap_T  g_App_CmdHndlr []; /**< IPM Device and
+                        Application Device command handler table. */
+
+
+
+#endif /* __MSG_HNDLR_APP_H__ */

+ 52 - 0
app/bmc/msghndlr/App/AppDevice+.h

@@ -0,0 +1,52 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * AppDevice.h
+ * AppDevice Commands Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#ifndef APPDEVICE_PLUS_H
+#define APPDEVICE_PLUS_H
+
+#include "com_BmcType.h"
+
+/*** Function Prototypes ***/
+/**
+ * @defgroup apcf4 IPMI2.0 Payload Commands
+ * @ingroup apcf
+ * IPMI2.0 RMCP+ Payload Command Handlers. Invoked by the message handler
+ * @{
+ **/
+extern int  ActivatePayload     ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  DeactivatePayload   ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetPayldActStatus   ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetPayldInstInfo    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  SetUsrPayloadAccess ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetUsrPayloadAccess ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetChPayloadSupport ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetChPayloadVersion ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetChOemPayloadInfo ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetChCipherSuites   ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  SusResPayldEncrypt  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  SetChSecurityKeys   ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int  GetSysIfcCaps       ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+/** @} */
+
+#endif  /* APPDEVICE_H */

+ 95 - 0
app/bmc/msghndlr/App/AppDevice.h

@@ -0,0 +1,95 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************
+ *
+ * AppDevice.h
+ * AppDevice Commands Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+#ifndef APPDEVICE_H
+#define APPDEVICE_H
+
+#include "com_BmcType.h"
+#define EVT_MSG_BUF_SIZE    1  /**<Event Message maximum Buffer size */
+//#define USER_ID             (((uint32_t)'U'<< 24) | ((uint32_t)'S'<< 16) | ('E'<<8) | 'R')
+#define IPMI_ROOT_USER      ( 2 )
+#define TWENTY_BYTE_PWD  0x80
+#define CURRENT_CHANNEL_NUM		0x0E
+#define MASTER_RW_ERRCODE 0xFF
+#define IGNORE_ADD_OR_REMOVE 0
+#define IGNORE_ADD_OR_REMOVE_SHELL -1
+#define IPMI_15_PASSWORD_LEN (16 + 2)
+#define IPMI_20_PASSWORD_LEN (20 + 2)
+#define SYS_SEND_MSG_LUN 0x02
+
+/*** Extern Declaration ***/
+
+
+/*** Function Prototypes ***/
+/**
+ * @defgroup apcf2 BMC Watchdog Timer Commands
+ * @ingroup apcf
+ * IPMI BMC Watchdog Timer Command Handlers. Invoked by the message handler
+ * @{
+ **/
+extern int      ResetWDT            ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SetWDT              ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetWDT              ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+/** @} */
+
+/**
+ * @defgroup apcf3 BMC Device and Messaging Commands
+ * @ingroup apcf
+ * IPMI BMC Device and Messaging Command Handlers. Invoked by the message handler
+ * @{
+ **/
+extern int      SetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      ClrMsgFlags         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetMsgFlags         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      EnblMsgChannelRcv   ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetMessage          ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SendMessage         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      ReadEvtMsgBuffer    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetBTIfcCap         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetSystemGUID       ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetChAuthCap        ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetSessionChallenge ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      ActivateSession     ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SetSessionPrivLevel ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      CloseSession        ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetSessionInfo      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetAuthCode         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SetChAccess         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetChAccess         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetChInfo           ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SetUserAccess       ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetUserAccess       ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SetUserName         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      GetUserName         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      SetUserPassword     ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int      MasterWriteRead     ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int		SetSystemInfoParam  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int 		GetSystemInfoParam  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern uint8_t  IsChannelSuppGroups(uint8_t ChannelNum);
+extern int ModifyUsrGrp(char * UserName,uint8_t ChannelNum,uint8_t OldAccessLimit, uint8_t NewAccessLimit );
+
+/** @} */
+
+#endif  /* APPDEVICE_H */
+

+ 3631 - 0
app/bmc/msghndlr/App/AppDevice/AppDevice.c

@@ -0,0 +1,3631 @@
+/****************************************************************
+****************************************************************
+**                                                            **
+**    (C)Copyright 2005-2006, American Megatrends Inc.        **
+**                                                            **
+**            All Rights Reserved.                            **
+**                                                            **
+**        6145-F, Northbelt Parkway, Norcross,                **
+**                                                            **
+**        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+**                                                            **
+****************************************************************
+****************************************************************/
+/*****************************************************************
+*
+* AppDevice.c
+* AppDevice Commands Handler
+*
+* Author: Govind Kothandapani <govindk@ami.com>
+*       : Rama Bisa <ramab@ami.com>
+*       : Basavaraj Astekar <basavaraja@ami.com>
+*       : Bakka Ravinder Reddy <bakkar@ami.com>
+*
+*****************************************************************/
+
+#include "com_BmcType.h"
+#include "Support.h"
+#include "com_IPMIDefs.h"
+#include "com_IPMI_IPM.h"
+#include "com_IPMI_AppDevice.h"
+#include "AppDevice.h"
+#include "RMCP.h"
+#include "Session.h"
+#include "PMConfig.h"
+#include "main.h"
+#include <string.h>
+
+#define USER_ID_ENABLED 	0x01
+#define USER_ID_DISABLED 	0x02
+#define OP_USERID_ONLY_LENGTH    2
+#define OP_ENABLE_USER_ID    	 1
+#define OP_DISABLE_USER_ID    	 0
+#define BIT3_BIT0_MASK     0xf
+#define GET_AUTH_TYPE_MASK  0xc0
+#define AUTH_TYPE_V15	0x0
+#define AUTH_TYPE_V20	0x40
+#define AUTH_CODE_V15_MASK  0x0f
+#define AUTH_CODE_V15_1  0x1
+#define AUTH_CODE_V15_2  0x2
+#define AUTH_CODE_V15_3  0x5
+#define AUTH_CODE_V20_MASK  0x3f
+#define MIN_AUTH_CODE_V20 0x04
+#define MAX_AUTH_CODE_V20 0xc0
+#define NULL_USER                 1
+#define ZERO_SETSELECTOR 0x00
+#define MAX_TYPE_OF_ENCODING 0x02
+#define MAX_STRING_LENGTH_COPY 14
+
+#define ASCII_LATIN1        0x00
+#define UTF_8                     0x01
+#define UNICODE                 0x02
+
+/* Reserved bit macro definitions */
+#define RESERVED_BITS_SENDMS 0x03 //(BIT1 | BIT0)
+
+/* Auth code length */
+#define HMAC_SHA1_96_LEN            12
+
+#if APP_DEVICE == 1
+
+#define COUNT_INCREASE  1	
+#define COUNT_DECREASE -1
+#define MAX_BT_PKT_LEN 255
+
+/*macro definitions for set user password options*/
+#define DISABLE_USER    0
+#define ENABLE_USER     1
+#define SET_PASSWORD    2
+#define TEST_PASSWORD   3
+
+/*** Global variables ***/
+uint8_t   g_TmrRunning;
+/*** Module variables ***/
+static     MsgPkt_T    m_MsgPkt; /**< Message Packet for posting and retrieving messaged to/from queue */
+static uint8_t m_Set_ChReserveBit[] ={0xF0,0x0,0x30};
+
+//extern IfcName_T Ifcnametable[MAX_LAN_CHANNELS];
+
+//static void UpdateCurrentEnabledUserCount(int value, int bmcInstId)
+//{
+//	if (value == 0) return;
+
+//	 ChannelInfo_T* pChannelInfo = NULL;
+//	 ChannelInfo_T* pNvrChannelInfo = NULL;
+//	 BMCInfo_t* pBMCInfo = &g_BMCInfo[bmcInstId];
+//	uint8_t maxUserCount = pBMCInfo->IpmiConfig.MaxChUsers;
+//	uint8_t channelIndex = 0;
+
+
+//	for (channelIndex = 0; channelIndex < MAX_NUM_CHANNELS; channelIndex++)
+//	{
+//		if (pBMCInfo->ChConfig[channelIndex].ChType == 0xff) continue;
+
+//		pChannelInfo = (ChannelInfo_T*)&pBMCInfo->ChConfig[channelIndex].ChannelInfo;
+
+//		if (((value > 0) && ((pChannelInfo->NoCurrentUser + value) > maxUserCount)) || 
+//			((value < 0) && ((pChannelInfo->NoCurrentUser + value) < 0)))
+//		{
+//			continue;
+//		}
+
+//		pNvrChannelInfo = GetNVRChConfigs(pChannelInfo, bmcInstId);
+
+//		pChannelInfo->NoCurrentUser+=value;	
+//		pNvrChannelInfo->NoCurrentUser+=value;
+//              FlushChConfigs((uint8_t*)pNvrChannelInfo,pNvrChannelInfo->ChannelNumber,bmcInstId);
+//}
+//}
+
+//static int IsPrivilegeAvailable(uint8_t requestedPrivilege, uint8_t channelNumber, int bmcInstId)  
+//{  
+//	//   PMConfig_T* pPMConfig = ( PMConfig_T*) GetNVRAddr(NVRH_PMCONFIG, bmcInstId);  
+//       BMCInfo_t *pBMCInfo = &g_BMCInfo[bmcInstId];
+//	uint8_t EthIndex = GetEthIndex(channelNumber & 0x0F, bmcInstId);  
+//	uint8_t privilege = 0x00;  
+//	
+//	if(0xff == EthIndex) return -1;  
+//	
+//	//Get requested privilege status (enabled or disabled) from PMConfig by channel 
+//	switch (requestedPrivilege)  
+//	{  
+//	case PRIV_CALLBACK:  
+//		privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeCallBack;  
+//		break;  
+//	
+//	case PRIV_USER:  
+//		privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeUser;  
+//		break;  
+//	
+//	case PRIV_OPERATOR:  
+//		privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeOperator;  
+//		break;  
+//	
+//	case PRIV_ADMIN:  
+//		privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeAdmin;  
+//		break;  
+//	
+//	case PRIV_OEM:  
+//		privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeOem;  
+//		break;  
+//	
+//	default:  
+//		return -1;  
+//	} 
+//	
+//	//All bits are 0 that means privilege level is disabled  
+//	return ((privilege != 0x00) ? 0 : -1);  
+//}
+
+/*-------------------------------------
+* ValidateIPMBChksum1
+*-------------------------------------*/
+/* Function to validate IPMB Checksum1 for SendMessage Cmd */
+static int ValidateIPMBChksum1( uint8_t* Data)
+{
+   int i=0;
+   uint8_t chksum=0;
+
+   for (i = 0; i < 3; i++)
+   {
+       chksum += *(Data + i);
+   }
+
+   if (chksum != 0)
+   {
+       return FALSE;
+   }
+   return TRUE;
+
+}
+
+
+///*-------------------------------------
+//* ResetWDT
+//*-------------------------------------*/
+//int
+//ResetWDT ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//    uint8_t	u8ExpirationFlag;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+
+
+//    if (pBMCInfo->Msghndlr.TmrSet == FALSE)
+//    {
+//        *pRes = CC_ATTEMPT_TO_RESET_UNIN_WATCHDOG;
+//        return sizeof (*pRes);
+//    }
+
+//    // save the WDT expiration flag for later use
+//    u8ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
+
+
+//    /* Reset of Watchdog should not happen once
+//        once pretimeout interrupt interval is reached*/
+//    if(pBMCInfo->WDTPreTmtStat == TRUE)
+//    {
+//        *pRes = CC_PARAM_NOT_SUP_IN_CUR_STATE;
+//        return sizeof (*pRes);
+//    }
+
+//    g_WDTTmrMgr.TmrPresent  = TRUE;
+//    g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown;
+//    g_WDTTmrMgr.PreTimeOutInterval = SEC_TO_MS * pBMCInfo->WDTConfig.PreTimeOutInterval;
+
+//    /* if the pre-timeout interrupt is not configured, adjust the pre-timeout interrupt
+//        timeout value beyound the regular WDT timeout value so that it won't get triggered
+//        before the WDT timeout. */
+//    if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
+//    {
+//        g_WDTTmrMgr.PreTimeOutInterval = g_WDTTmrMgr.TmrInterval+ 1;
+//    }
+
+//    _fmemcpy (&g_WDTTmrMgr.WDTTmr, &pBMCInfo->WDTConfig, sizeof (WDTConfig_T));
+
+//    // restore the WDT expiration flag, don't use the one from the flash
+//    g_WDTTmrMgr.WDTTmr.ExpirationFlag = u8ExpirationFlag;
+
+//    // clear WDT sensor event history
+//    if( g_corefeatures.internal_sensor == ENABLED )
+//        RestartWD2Sensor(BMCInst);
+
+//    if(g_corefeatures.wdt_flush_support == ENABLED )
+//    {
+//        FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
+//                       sizeof(WDTConfig_T),BMCInst);
+//    }
+
+//    if(BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent == FALSE)
+//    {
+//        LOCK_BMC_SHARED_MEM(BMCInst);
+//        BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=TRUE;
+//        BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent=TRUE;
+//        UNLOCK_BMC_SHARED_MEM(BMCInst);
+//        sem_post(&g_BMCInfo[BMCInst].WDTSem);
+//    }
+//    else
+//    {
+//        LOCK_BMC_SHARED_MEM(BMCInst);
+//        BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=TRUE;
+//        BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent=TRUE;
+//        UNLOCK_BMC_SHARED_MEM(BMCInst);
+//        //Set SetWDTUpdated flag to reload initial countdown value.
+//        g_BMCInfo[BMCInst].SetWDTUpdated = TRUE; 
+//    }
+
+
+//    *pRes = CC_NORMAL;
+
+//    return sizeof (*pRes);
+//}
+
+
+
+///*---------------------------------------
+//* SetWDT
+//*---------------------------------------*/
+//int
+//SetWDT ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      SetWDTReq_T*    pSetWDTReq = ( SetWDTReq_T*)pReq;
+//#if GET_MSG_FLAGS != UNIMPLEMENTED
+//    GetMsgFlagsRes_T   GetMsgFlagsRes;
+//#endif
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+
+//    //Check for Reserved bits
+//     if((pSetWDTReq->TmrUse & (BIT5 | BIT4 | BIT3)) || !(pSetWDTReq->TmrUse & (BIT2 | BIT1 | BIT0)) || ((pSetWDTReq->TmrUse & (BIT1 | BIT2)) == (BIT1 | BIT2)) || 
+//        (pSetWDTReq->TmrActions & (BIT7 |BIT6 | BIT3 | BIT2)) || (pSetWDTReq->ExpirationFlag & (BIT7 | BIT6 | BIT0)))
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//#if NO_WDT_PRETIMEOUT_INTERRUPT == 1
+//    // do not support pre-timeout interrupt
+//    if (pSetWDTReq->TmrActions & 0x70)
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+//#endif
+
+//    pSetWDTReq->InitCountDown = htoipmi_u16(pSetWDTReq->InitCountDown);
+
+//    // error out if the pre-timeout interrupt is greater than the initial countdown value
+//    if (pSetWDTReq->InitCountDown < 10 * pSetWDTReq->PreTimeOutInterval)
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//    // only clear the memory version of the bit(s) when the input bit is set #31175
+//    g_WDTTmrMgr.WDTTmr.ExpirationFlag &= ~pSetWDTReq->ExpirationFlag;
+//    pSetWDTReq->ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
+
+
+//    /* Copy the Timer configuration in NVRAM */
+//    LOCK_BMC_SHARED_MEM(BMCInst);
+//    _fmemset (( uint8_t*)&pBMCInfo->WDTConfig, 0, sizeof (WDTConfig_T));
+//    _fmemcpy (( uint8_t*)&pBMCInfo->WDTConfig, ( uint8_t*)pSetWDTReq, sizeof (SetWDTReq_T));
+//    UNLOCK_BMC_SHARED_MEM(BMCInst);
+
+//    if (TRUE ==BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning)
+//    {
+//        /* To check wheather Dont stop bit is set or not */
+//        if (pSetWDTReq->TmrUse & 0x40)
+//        {
+//            /* Set the count down value to given value */
+//            g_WDTTmrMgr.TmrPresent = TRUE;
+//            LOCK_BMC_SHARED_MEM(BMCInst);
+//            BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =TRUE;
+//            UNLOCK_BMC_SHARED_MEM(BMCInst);
+//            g_WDTTmrMgr.TmrInterval= pSetWDTReq->InitCountDown;
+//            g_WDTTmrMgr.PreTimeOutInterval = (SEC_TO_MS * pSetWDTReq->PreTimeOutInterval);
+
+//            /* If PreTimeOutInt is set, clear it */
+//            if (0 != (pSetWDTReq->TmrActions & 0x70))
+//            {
+//                pSetWDTReq->TmrActions &= ~0x70;
+//            }
+//            else
+//            {
+//                // if the pre-timeout interrupt is not configured, adjust the pre-timeout interrupt
+//                // timeout value beyound the regular WDT timeout value so that it won't get triggered
+//                // before the WDT timeout.
+//                g_WDTTmrMgr.PreTimeOutInterval = pSetWDTReq->InitCountDown + 1;
+//            }
+//            _fmemcpy (&g_WDTTmrMgr.WDTTmr, pSetWDTReq, sizeof (WDTConfig_T ));
+
+//        }
+//        else
+//        {
+//            /* Stop the timer */
+//            g_WDTTmrMgr.TmrPresent = FALSE;
+//            LOCK_BMC_SHARED_MEM(BMCInst);
+//            BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=FALSE;
+//            BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
+//            UNLOCK_BMC_SHARED_MEM(BMCInst);
+//            g_WDTTmrMgr.TmrInterval= pSetWDTReq->InitCountDown;
+//            g_WDTTmrMgr.PreTimeOutInterval = SEC_TO_MS * pSetWDTReq->PreTimeOutInterval;
+//            // clear WDT sensor event history
+//            if( g_corefeatures.internal_sensor == ENABLED)
+//                RestartWD2Sensor(BMCInst);
+//        }
+
+//        /* Clear the  pre-timeout interupt flag */
+//        LOCK_BMC_SHARED_MEM(BMCInst);
+//        pBMCInfo->WDTConfig.PreTimeoutActionTaken = 0x00;
+//        BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x08; /* Clear the flag */
+//#if GET_MSG_FLAGS != UNIMPLEMENTED
+//        // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
+//        GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
+//        TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
+//                GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
+//        if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
+//#else
+//        if((BMC_GET_SHARED_MEM(BMCInst)->MsgFlags & BIT3_BIT0_MASK) == 0)
+//#endif
+//        {
+//            /* Clear the SMS_ATN bit */
+//            if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
+//            {
+//                CLEAR_SMS_ATN (0, BMCInst);
+//            }
+//            if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
+//            {
+//                CLEAR_SMS_ATN (1, BMCInst);
+//            }
+//            if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
+//            {
+//                CLEAR_SMS_ATN (2, BMCInst);
+//            }
+//        }
+//            UNLOCK_BMC_SHARED_MEM(BMCInst);
+
+//        }
+//        else
+//        {
+//            g_WDTTmrMgr.TmrInterval = pSetWDTReq->InitCountDown;
+//            g_WDTTmrMgr.TmrPresent = FALSE;
+//            LOCK_BMC_SHARED_MEM(BMCInst);
+//            BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
+//            UNLOCK_BMC_SHARED_MEM(BMCInst);
+//            // clear WDT sensor event history
+//            if( g_corefeatures.internal_sensor == ENABLED)
+//                RestartWD2Sensor(BMCInst);
+//        }
+
+//    // Modify ARP status to resume the thread
+//    // after receiving set Watchdog Timer command
+//    //BMC_GET_SHARED_MEM(BMCInst)->GratArpStatus = RESUME_ARPS;
+//    
+//    int i = 0; 
+
+//    for (i = 0; i < MAX_LAN_CHANNELS; i++)	
+//    {
+//        if((pBMCInfo->LanIfcConfig[i].Enabled == TRUE)
+//                && (pBMCInfo->LanIfcConfig[i].Up_Status == LAN_IFC_UP))
+//        {
+//            BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[i] = RESUME_ARPS; 	
+//            UpdateArpStatus(pBMCInfo->LanIfcConfig[i].Ethindex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);  
+//        }
+//    }
+//    if(g_corefeatures.wdt_flush_support == ENABLED )
+//    {
+//        FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
+//              sizeof(WDTConfig_T),BMCInst);
+//    }
+//    // set the "Don't Log" bit
+//    g_WDTTmrMgr.WDTTmr.TmrUse &= 0x7F;
+//    g_WDTTmrMgr.WDTTmr.TmrUse |= (pSetWDTReq->TmrUse & 0x80);
+
+//    g_BMCInfo[BMCInst].SetWDTUpdated = TRUE;
+//    g_BMCInfo[BMCInst].Msghndlr.TmrSet = TRUE;
+//    pBMCInfo->WDTPreTmtStat = FALSE;
+//    *pRes = CC_NORMAL;
+
+//    return sizeof (*pRes);
+//}
+
+
+///*---------------------------------------
+//* GetWDT
+//*---------------------------------------*/
+//int
+//GetWDT ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      GetWDTRes_T*    pGetWDTRes = ( GetWDTRes_T*)pRes;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    /* Copy the current settings from the NVRAM */
+//    LOCK_BMC_SHARED_MEM(BMCInst);
+//    _fmemcpy (( uint8_t*)&pGetWDTRes->CurrentSettings,
+//            ( uint8_t*)&pBMCInfo->WDTConfig, sizeof (WDTConfig_T));
+//    UNLOCK_BMC_SHARED_MEM(BMCInst);
+
+//    // get the WDT expiration from the global veriable in memory, not from the flash
+//    pGetWDTRes->CurrentSettings.ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
+
+//    // get the current "Don't Log" bit
+//    pGetWDTRes->CurrentSettings.TmrUse &= 0x7F;
+//    pGetWDTRes->CurrentSettings.TmrUse |= (g_WDTTmrMgr.WDTTmr.TmrUse & 0x80);
+//    if (TRUE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent)
+//    {
+//         // set the WDT running bit #30235/30467
+//        pGetWDTRes->CurrentSettings.TmrUse |= 0x40;
+//        /* Present count down in 1/100 of second */
+//    }
+//    else
+//    {
+//         // clear the WDT running bit #30235/30467  for Timer Use (ie) WatchDog Timer status
+//        pGetWDTRes->CurrentSettings.TmrUse &= ~0x40;
+//        pGetWDTRes->CurrentSettings.ExpirationFlag = (pGetWDTRes->CurrentSettings.ExpirationFlag) & 0x3E;
+//    }
+
+//    pGetWDTRes->PresentCountDown			   = g_WDTTmrMgr.TmrInterval;
+//    pGetWDTRes->CurrentSettings.InitCountDown = htoipmi_u16(pGetWDTRes->CurrentSettings.InitCountDown);
+//    pGetWDTRes->CompletionCode                = CC_NORMAL;
+
+//    return sizeof (GetWDTRes_T);
+//}
+
+
+///*---------------------------------------
+//* SetBMCGlobalEnables
+//*---------------------------------------*/
+//int
+//SetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//    uint8_t GblEnblByte = *pReq;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+//    MsgPkt_T MsgPkt;
+
+//    _fmemset (&MsgPkt, 0, sizeof (MsgPkt_T));
+
+//    /* Check For the reserved bit 4 */
+//    if ( GblEnblByte & BIT4)
+//      {
+//         *pRes = CC_INV_DATA_FIELD;
+//          return sizeof (*pRes);
+//      }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
+//    if (((BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables ^ GblEnblByte)) & 0x20) 
+//    {
+//        /* OEM 0 puts us in ICTS compatibility mode for IPMIv2,
+//         * Send a message to lan process so it can change behavior
+//         */
+//        MsgPkt.Channel    = GetLANChannel(0, BMCInst);
+//        MsgPkt.Param      = LAN_ICTS_MODE;
+//        MsgPkt.Privilege  = PRIV_LOCAL;
+//        if (GblEnblByte & 0x20)
+//            MsgPkt.Cmd = 1;
+//        else
+//            MsgPkt.Cmd = 0;
+//        PostMsg(&MsgPkt,LAN_IFC_Q,BMCInst);
+//    }
+
+//    BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables = GblEnblByte;
+//    *pRes = CC_NORMAL;
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+
+//    return sizeof (*pRes);
+//}
+
+
+///*---------------------------------------
+//* GetBMCGlobalEnables
+//*---------------------------------------*/
+//int
+//GetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      GetBMCGblEnblRes_T* pGetBMCGblEnblRes = ( GetBMCGblEnblRes_T*)pRes;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
+//    pGetBMCGblEnblRes->CompletionCode = CC_NORMAL;
+//    pGetBMCGblEnblRes->BMCGblEnblByte = BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables;
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+
+//    return sizeof (GetBMCGblEnblRes_T);
+//}
+
+
+///*---------------------------------------
+//* ClrMsgFlags
+//*---------------------------------------*/
+//int
+//ClrMsgFlags ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//     ClearMsgsFlagReq_T* pClearMsgsFlagReq = ( ClearMsgsFlagReq_T*)pReq;
+//    uint8_t *kcsifcnum;
+//#if GET_MSG_FLAGS != UNIMPLEMENTED
+//    GetMsgFlagsRes_T   GetMsgFlagsRes;
+//#endif
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    //Check for Reserved bits
+//    if(pClearMsgsFlagReq->Flag & (BIT4 | BIT2))
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//    OS_THREAD_TLS_GET(g_tls.CurKCSIfcNum,kcsifcnum);
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
+//    /* Flush Receive Message Queue */
+//    if (0 != (pClearMsgsFlagReq->Flag & 0x01))
+//    {
+//        while (0 == GetMsg (&m_MsgPkt, &g_RcvMsgQ[*kcsifcnum][0], WAIT_NONE,BMCInst))
+//        {
+//            BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum]--;
+//        }
+
+//        BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x01; /* Clear the flag */
+//    }
+
+//    /* Flush Event Message Buffer */
+//    if (0 != (pClearMsgsFlagReq->Flag & 0x02))
+//    {
+//        OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
+//        while (0 == GetMsg (&m_MsgPkt, EVT_MSG_Q, WAIT_NONE,BMCInst))
+//        {
+//            BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg--;
+//        }
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
+//        BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x02; /* Clear the flag */
+//    }
+
+//    /* Clear WatchdogTimer Interrupt*/
+//    if (0 != (pClearMsgsFlagReq->Flag & 0x08))
+//    {
+//        /* Clear the  pre-timeout interupt flag */
+//        pBMCInfo->WDTConfig.PreTimeoutActionTaken = 0x00;
+//        BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x08; /* Clear the flag */
+//	if(g_corefeatures.wdt_flush_support == ENABLED )
+//    	{
+//            FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
+//                           sizeof(WDTConfig_T),BMCInst);
+//       }
+
+//    }
+
+//#if GET_MSG_FLAGS != UNIMPLEMENTED
+//    // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
+//    GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
+//    TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
+//            GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
+//    if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
+//#else
+//    if((BMC_GET_SHARED_MEM(BMCInst)->MsgFlags & BIT3_BIT0_MASK) == 0)
+//#endif
+//    {
+//        /* Clear the SMS_ATN bit */
+//        if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
+//        {
+//            CLEAR_SMS_ATN (0, BMCInst);
+//        }
+//        if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
+//        {
+//            CLEAR_SMS_ATN (1, BMCInst);
+//        }
+//        if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
+//        {
+//            CLEAR_SMS_ATN (2, BMCInst);
+//        }
+//    }
+
+//    *pRes = CC_NORMAL;
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+
+//    return sizeof (*pRes);
+//}
+
+
+// /*---------------------------------------
+// GetMsgFlags
+// ---------------------------------------*/
+// int
+// GetMsgFlags ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+// {
+//     GetMsgFlagsRes_T*   pGetMsgFlagsRes = ( GetMsgFlagsRes_T*)pRes;
+//     uint8_t *kcsifcnum;
+
+//    /* get the message flags */
+//    pGetMsgFlagsRes->MsgFlags = BMC_GET_SHARED_MEM (BMCInst)->MsgFlags;
+
+//    if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg >= EVT_MSG_BUF_SIZE)
+//    {
+//        /* If Event MessageBuffer is Full set the BIT */
+//        pGetMsgFlagsRes->MsgFlags |= 0x02;
+//    }
+//    else
+//    {
+//        /* else reset the Flag */
+//        pGetMsgFlagsRes->MsgFlags &= ~0x02;
+//    }
+
+//    if(kcsifcnum != NULL && 0 != BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum])
+//    {
+//        /* if any Message in ReceiveMsgQ set the Flag */
+//        pGetMsgFlagsRes->MsgFlags |= 0x01;
+//    }
+//    else
+//    {
+//        /* else reset the Flag */
+//        pGetMsgFlagsRes->MsgFlags &= ~0x01;
+//    }
+
+//    /* get the  Pre-Timeout Bits Value & Set it to Response Data */
+//    //PRETIMEOUT BIT is 3rd bit so changed accordingly
+//    pGetMsgFlagsRes->MsgFlags |= (pBMCInfo->WDTConfig.PreTimeoutActionTaken & 0x08);
+
+//    /* Update the Message flags in shared Mem */
+//    BMC_GET_SHARED_MEM (BMCInst)->MsgFlags |=  pGetMsgFlagsRes->MsgFlags;
+//    pGetMsgFlagsRes->CompletionCode = CC_NORMAL;
+
+//    return sizeof (GetMsgFlagsRes_T);
+// }
+
+
+///*---------------------------------------
+//* EnblMsgChannelRcv
+//*---------------------------------------*/
+//int
+//EnblMsgChannelRcv ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      EnblMsgChRcvReq_T*  pEnblMsgChRcvReq = ( EnblMsgChRcvReq_T*)pReq;
+//      EnblMsgChRcvRes_T*  pEnblMsgChRcvRes = ( EnblMsgChRcvRes_T*)pRes;
+//       ChannelInfo_T*      pChannelInfo;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    //Check for Reserved bits
+//    if(pEnblMsgChRcvReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4))
+//    {
+//        pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+//    pChannelInfo = getChannelInfo (pEnblMsgChRcvReq->ChannelNum & 0x0F, BMCInst);
+
+//    TDBG ("ENBL_MSG_CH_RCV: processing..\n");
+
+//    if (NULL == pChannelInfo)
+//    {
+//        pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        return sizeof (*pRes);
+//    }
+
+//    switch (pEnblMsgChRcvReq->ChannelState)
+//    {
+//        case 0:
+//            /* disable Receive Message Queue for this Channel */
+//            pChannelInfo->ReceiveMsgQ = 0x0;
+//            break;
+
+//        case 1:
+//            /*enable Recevive Message Queue for this Channel */
+//            pChannelInfo->ReceiveMsgQ = 0x1;
+//            break;
+
+//        case 2:
+//            /*get Channel State */
+//            pEnblMsgChRcvRes->ChannelState = pChannelInfo->ReceiveMsgQ;
+//            break;
+
+//        default:
+//            pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//            return sizeof (*pRes);
+//    }
+
+//    pEnblMsgChRcvRes->CompletionCode = CC_NORMAL;
+
+//    /*get Channel Number */
+//    pEnblMsgChRcvRes->ChannelNum = pEnblMsgChRcvReq->ChannelNum & 0x0F;
+
+//    pEnblMsgChRcvRes->ChannelState = pChannelInfo->ReceiveMsgQ;
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+
+//    return sizeof (EnblMsgChRcvRes_T);
+//}
+
+
+/*---------------------------------------
+* GetMessage
+*---------------------------------------*/
+int
+GetMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    GetMsgRes_T*    pGetMsgRes = ( GetMsgRes_T*)pRes;      
+    uint8_t         Index = 0,*kcsifcnum;
+#if GET_MSG_FLAGS != UNIMPLEMENTED
+   GetMsgFlagsRes_T   GetMsgFlagsRes;
+#endif
+   printf("GetMessage!\n");
+
+//    if (0 != GetMsg (&m_MsgPkt, &g_RcvMsgQ[*kcsifcnum][0], WAIT_NONE))
+//    {
+//        /* if Queue is Empty */
+//        pGetMsgRes->CompletionCode = CC_GET_MSG_QUEUE_EMPTY;
+//        return  sizeof (*pRes);
+//    }
+
+// #if GET_MSG_FLAGS != UNIMPLEMENTED
+//    // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
+//    GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
+//    TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
+//            GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
+//    if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
+// #else
+//    if (0 == BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum])
+// #endif
+//    {
+//        /* Clear the SMS_ATN bit */
+//        CLEAR_SMS_ATN (*kcsifcnum,BMCInst);
+//    }
+
+//    /* Completion Code  */
+//    pGetMsgRes->CompletionCode  = CC_NORMAL;
+//    /* Channel number and privilege level */
+//    pGetMsgRes->ChannelNum      = m_MsgPkt.Channel;
+
+//    Index = sizeof (GetMsgRes_T);
+
+//    /* First byte should be session handle */
+//    if(pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)
+//    {
+//        if ((PRIMARY_IPMB_CHANNEL != m_MsgPkt.Channel) && (pBMCInfo->SecondaryIPMBCh != m_MsgPkt.Channel))
+//        {
+//            pGetMsgRes->ChannelNum |= m_MsgPkt.Privilege << 0x04;
+//            pRes [Index++] = m_MsgPkt.Param;
+//        }
+//    }
+//    else
+//    {
+//        if(PRIMARY_IPMB_CHANNEL != m_MsgPkt.Channel)
+//        {
+//                pGetMsgRes->ChannelNum |= m_MsgPkt.Privilege << 0x04;
+//                pRes [Index++] = m_MsgPkt.Param;
+//        }
+//    }
+
+//    /* copy the Message data    */
+//    _fmemcpy (( uint8_t*)&pRes[Index], &m_MsgPkt.Data[1], m_MsgPkt.Size-1);
+
+//    IPMI_DBG_PRINT ("GetMsg: Sending the following data through requested channel\n");
+//    IPMI_DBG_PRINT_BUF (pRes, m_MsgPkt.Size + Index);
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+
+//   return  ((m_MsgPkt.Size-1)+ Index);      /*+ 2 for completion code & channel No. */
+   return 1;
+}
+
+
+/*---------------------------------------
+* SendMessage
+*---------------------------------------*/
+int
+SendMessage ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    SendMsgReq_T* pSendMsgReq = ( SendMsgReq_T*)pReq;
+    SendMsgRes_T* pSendMsgRes = ( SendMsgRes_T*)pRes;
+    IPMIMsgHdr_T* pIPMIMsgHdr;
+    int Queuefd = 0;
+   uint8_t         Tracking;
+   uint8_t         Channel=0,resaddr=0;
+   uint8_t         ResLen = 1;
+   uint8_t         RetVal = 0;
+   uint8_t         Offset = 1;
+   uint8_t         SeqNum = g_BMCInfo.SendMsgSeqNum;
+   uint8_t         PBTbl = PRIMARY_PB_TBL;
+   uint8_t         SrcSessionHndl = 0;
+   ChannelInfo_T*      pChannelInfo;
+   MsgPkt_T ResPkt;
+    SessionInfo_T* pSessionInfo = NULL;
+   uint32_t *CurSesID;
+   uint8_t *curprivlevel,*curchannel,*kcsifcnum;
+
+   *pRes = CC_NORMAL;
+   if (ReqLen < 1)
+   {
+       *pRes = CC_REQ_INV_LEN;
+       return  sizeof (*pRes);
+   }
+
+   if(pSendMsgReq->ChNoTrackReq == 0xC0)
+   {
+       *pRes = CC_INV_DATA_FIELD;
+       return sizeof (*pRes);
+   }
+
+   /* Get the channel number */
+   Channel = pSendMsgReq->ChNoTrackReq & 0x0F;
+
+   /* Get Tracking field */
+   Tracking = pSendMsgReq->ChNoTrackReq >> 6;
+
+   if (Tracking == RESERVED_BITS_SENDMS)
+   {
+       *pRes = CC_INV_DATA_FIELD;
+       return sizeof (*pRes);
+   }
+
+   CurSesID = pthread_getspecific(g_tls.CurSessionID);       
+   curchannel = pthread_getspecific(g_tls.CurChannel);       
+   kcsifcnum = pthread_getspecific(g_tls.CurKCSIfcNum);       
+  
+    m_MsgPkt.Param    = BRIDGING_REQUEST;
+    m_MsgPkt.Channel  = Channel;
+    m_MsgPkt.Size     = ReqLen - 1; /* -1 to skip channel num */
+
+
+    /* Copy the message data */
+    memcpy (m_MsgPkt.Data, &pReq[1], m_MsgPkt.Size);
+    /* Copy the IPMI Message header */
+    pIPMIMsgHdr =  ( IPMIMsgHdr_T*)&m_MsgPkt.Data[Offset - 1];
+    if(ValidateIPMBChksum1(( uint8_t*)pIPMIMsgHdr) == FALSE)
+    {
+       *pRes = CC_INV_DATA_FIELD;
+       printf("Invalid checksum1\n");
+       return  sizeof (*pRes);
+    }
+
+    if(m_MsgPkt.Data[ReqLen - 2] != CalculateCheckSum2 (( uint8_t*)pIPMIMsgHdr, ReqLen - Offset - 1))
+    {
+       *pRes = CC_INV_DATA_FIELD;
+       return  sizeof (*pRes);
+    }
+
+#if 0
+	int z;
+	printf("m_MsgPkt: ");
+   	for(z = 0; z < m_MsgPkt.Size;z++)
+   		printf("%02x ", m_MsgPkt.Data[z]);
+   	printf("\n");
+#endif
+
+    printf("---> curchannel: %d, Channel: %d\n", *curchannel, Channel);
+
+    if((Channel == PRIMARY_IPMB_CHANNEL) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1)
+    {
+     //printf ("SendMsg: To Primary IPMB Interface\n");
+     m_MsgPkt.SrcQ 	= gFd_PrimaryIpmbIfcQ;
+    }
+    else if(( Channel == SECONDARY_IPMB_CHANNEL) && (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 1))
+    {
+     //printf ("SendMsg: To Secondary IPMB Interface\n");
+     m_MsgPkt.SrcQ = gFd_SecondaryIpmbIfcQ;
+    }
+    else
+    {
+     printf ("SendMsg: Invalid Channel\n");
+     *pRes = CC_DEST_UNAVAILABLE;
+     return sizeof (*pRes);
+    }
+
+    if (1 == Tracking)
+    {       
+        ResLen = 0;
+        //printf("---> Tracking, curchannel %d, ", *curchannel);
+       /* Tracking is not required if originator is System ifc */
+       if (SYS_IFC_CHANNEL == (*curchannel & 0xF))
+       {
+           *pRes = CC_INV_DATA_FIELD;
+           return sizeof (*pRes);
+       }
+
+        if(*curchannel == LAN_RMCP_CHANNEL)
+        {
+          pSessionInfo = getSessionInfo (SESSION_ID_INFO,  CurSesID);
+          //printf("SendMEssage/CurSesID %#x, SessionHandle %#x\n", *CurSesID, pSessionInfo->SessionHandle);
+          if (NULL != pSessionInfo)
+          {
+              g_BMCInfo.SessionHandle = pSessionInfo->SessionHandle;
+          }
+          else
+          {
+              printf("Error: Not get valid session!\n");
+              *pRes = CC_UNSPECIFIED_ERR;
+              return sizeof(*pRes);
+          }
+        }
+ 
+       PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
+       //printf("PBTbl %d, g_BMCInfo.SendMsgSeqNum %d, ", PBTbl, g_BMCInfo.SendMsgSeqNum);
+       /* Store in the table for response tracking */
+       while(TRUE)
+       {
+           if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
+           {
+               m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = g_BMCInfo.IpmiConfig.SendMsgTimeout;
+               m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = (*curchannel & 0xF);
+               m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc  = ORIGIN_SENDMSG;
+               g_BMCInfo.SendMsgSeqNum = SeqNum;
+               
+               if (1 != Offset)
+               {
+                  //TODO:这个貌似没用到?
+                   m_PendingBridgedResTbl[PBTbl][SeqNum].DstSessionHandle = pReq[Offset]; /* Session handle */
+               }
+
+               m_PendingBridgedResTbl[PBTbl][SeqNum].SrcSessionHandle = pSessionInfo->SessionHandle;//  SrcSessionHndl;
+               
+               memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pIPMIMsgHdr, sizeof (IPMIMsgHdr_T));
+
+               /* Format the IPMI Msg Hdr */
+               if(Channel == PRIMARY_IPMB_CHANNEL)  
+               {
+                   pIPMIMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr;
+               }
+               else if(Channel == SECONDARY_IPMB_CHANNEL)
+               {
+                   pIPMIMsgHdr->ReqAddr =  g_BMCInfo.SecondaryIPMBAddr;
+               }
+               else
+               {
+                   printf("Invalid channel %d\n", Channel);//pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
+               }
+
+               pIPMIMsgHdr->RqSeqLUN = (g_BMCInfo.SendMsgSeqNum << 2) & 0xFC; /* Seq Num and LUN =00 */
+
+               /* Recalculate the checksum */
+               m_MsgPkt.Data[ReqLen - 2] = CalculateCheckSum2 (( uint8_t*)pIPMIMsgHdr, ReqLen - Offset - 1);
+               if((*curchannel & 0xF) == LAN_RMCP_CHANNEL)
+               {                 
+                   m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFd_LanIfcQ;
+                   
+               }         
+               else if((*curchannel & 0xF) == UDS_CHANNEL)
+               {
+                  m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFdUdsIfc;
+               }         
+               else
+               {
+                  printf("Not support channel! %d\n", *curchannel);
+                  *pRes = CC_PARAM_OUT_OF_RANGE;
+                  return 1;
+               }
+               m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
+               m_PendingBridgedResTbl[PBTbl][SeqNum].SeqNum = SeqNum;
+               m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 0;
+               //printf( "SendMessage SeqNum %d, ", SeqNum);
+              //memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
+
+
+               break;
+           }
+           else
+           {
+               SeqNum = (SeqNum + 1) & 0x3F;
+
+               if (SeqNum == g_BMCInfo.SendMsgSeqNum)   //转了一圈,没有空闲的SeqNum可用。
+               {
+                   /* If not been added to the Pending Bridge table, an error should be reported back.
+                   If not, for internal channel, the thread calling it may end up waiting! */
+                   *pRes = CC_NODE_BUSY;
+                   return  sizeof (*pRes);
+               }
+            }
+       }
+    }
+    else
+    {
+      pSendMsgRes->CompletionCode = 0xff;
+      return 1;
+    }
+
+    // printf ("SendMsgCmd:Posting to interface ");
+    // int y;
+    // for(y=0;y<m_MsgPkt.Size;y++)
+    // 		printf("%#x ", m_MsgPkt.Data[y]);
+    // 	printf("\n");
+
+    m_MsgPkt.Cmd = PAYLOAD_IPMI_MSG;
+    /* Post the message to interface */
+    if (0 != PostMsg (m_MsgPkt.SrcQ, &m_MsgPkt))
+    {
+       printf ("Warning: SendMsg Failed to post message to interface queue\n");
+    }
+
+    pSendMsgRes->CompletionCode = CC_NORMAL;
+   
+    return ResLen;
+}
+
+
+///*---------------------------------------
+//* ReadEvtMsgBuffer
+//*---------------------------------------*/
+//int
+//ReadEvtMsgBuffer ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      ReadEvtMsgBufRes_T* pReadEvtMsgBufRes = ( ReadEvtMsgBufRes_T*)pRes;
+//#if GET_MSG_FLAGS != UNIMPLEMENTED
+//    GetMsgFlagsRes_T   GetMsgFlagsRes;
+//#endif
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
+//    if (-2 == GetMsg(&m_MsgPkt, EVT_MSG_Q, WAIT_NONE, BMCInst))
+//    {
+//        /*If queue is empty */
+//        pReadEvtMsgBufRes->CompletionCode = CC_EVT_MSG_QUEUE_EMPTY;/* Queue is empty    */
+//		OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
+//		OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+//        return  sizeof (*pRes);
+//    }
+
+//    if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg == 0) 
+//    { 
+//        pReadEvtMsgBufRes->CompletionCode = CC_EVT_MSG_QUEUE_EMPTY; 
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
+//		OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+//        return  sizeof (*pRes); 
+//    }
+
+//    BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg--;
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
+
+//#if GET_MSG_FLAGS != UNIMPLEMENTED
+//    // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
+//    GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
+//    TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
+//            GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
+//    if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
+//#else
+//    if (0 == BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg)
+//#endif
+//    {
+//        /* if there is no messssage in buffer reset SMS/EVT ATN bit */
+//        //       CLEAR_SMS_ATN ();
+//        if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
+//        {
+//            CLEAR_SMS_ATN (0, BMCInst);
+//        }
+//        if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
+//        {
+//            CLEAR_SMS_ATN (1, BMCInst);
+//        }
+//        if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
+//        {
+//            CLEAR_SMS_ATN (2, BMCInst);
+//        }
+//    }
+
+//    /* clear EventMessageBuffer full flag */
+//    BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x02;
+
+//    pReadEvtMsgBufRes->CompletionCode = CC_NORMAL; /* Completion Code   */
+
+//    /* copy the Message data */
+//    _fmemcpy (pReadEvtMsgBufRes->ResData, m_MsgPkt.Data, m_MsgPkt.Size);
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
+
+//    return sizeof (ReadEvtMsgBufRes_T);
+//}
+
+
+///*---------------------------------------
+//* GetBTIfcCap
+//*---------------------------------------*/
+//int
+//GetBTIfcCap ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      GetBTIfcCapRes_T* pGetBTIfcCapRes = ( GetBTIfcCapRes_T*)pRes;
+
+//    pGetBTIfcCapRes->CompletionCode     = CC_NORMAL;
+//    pGetBTIfcCapRes->NumReqSupported    = 2;
+//    pGetBTIfcCapRes->InputBufSize       = MAX_BT_PKT_LEN;
+//    pGetBTIfcCapRes->OutputBufSize      = MAX_BT_PKT_LEN;
+//    pGetBTIfcCapRes->RespTime           = 1;
+//    pGetBTIfcCapRes->Retries            = 0;
+
+//    return sizeof (GetBTIfcCapRes_T);
+//}
+
+
+///*---------------------------------------
+//* GetSystemGUID
+//*---------------------------------------*/
+//int
+//GetSystemGUID ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//     GetSysGUIDRes_T* pGetSysGUIDRes = ( GetSysGUIDRes_T*)pRes;
+
+//    pGetSysGUIDRes->CompletionCode  = CC_NORMAL;
+//    LOCK_BMC_SHARED_MEM (BMCInst);
+//    _fmemcpy (&pGetSysGUIDRes->Node, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
+//    UNLOCK_BMC_SHARED_MEM (BMCInst);
+
+//    return sizeof (GetSysGUIDRes_T);
+//}
+
+
+#define SUPPORT_IPMI20  0x02
+#define SUPPORT_IPMI15  0x01
+/*---------------------------------------
+* GetChAuthCap
+*---------------------------------------*/
+int
+GetChAuthCap ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	//TODO: dummy data
+//    GetChAuthCapReq_T*   pGetChAuthCapReq = ( GetChAuthCapReq_T*)pReq;
+    GetChAuthCapRes_T*   pGetChAuthCapRes = ( GetChAuthCapRes_T*)pRes;
+
+	pGetChAuthCapRes->CompletionCode	=	CC_NORMAL;
+	pGetChAuthCapRes->ChannelNum		=	LAN_RMCP_CHANNEL;
+	pGetChAuthCapRes->AuthType			=	0x36;
+	pGetChAuthCapRes->PerMsgUserAuthLoginStatus	=	0x04;
+	pGetChAuthCapRes->ExtCap			=	0;
+	pGetChAuthCapRes->OEMID[0]			=	0;
+	pGetChAuthCapRes->OEMID[1]			=	0;
+	pGetChAuthCapRes->OEMID[2]			=	0;
+	pGetChAuthCapRes->OEMAuxData		=	0;
+	
+    return sizeof (GetChAuthCapRes_T);
+}
+
+
+/*---------------------------------------
+* GetSessionChallenge
+* Create session in this function
+*---------------------------------------*/
+int
+GetSessionChallenge ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	GetSesChallengeReq_T* pGetSesChalReq = ( GetSesChallengeReq_T*)pReq;
+	GetSesChallengeRes_T* pGetSesChalRes = ( GetSesChallengeRes_T*)pRes;
+  uint8_t                 Index;
+  uint8_t                 ChallengeString[CHALLENGE_STR_LEN];
+	UserInfo_T			*pUserInfo;
+  uint32_t                TempSessId;
+  SessionInfo_T         SessionInfo;
+  uint8_t         *curchannel;
+  uint32_t        TempRandom;
+
+	if(pGetSesChalReq->UserName[0] == 0)
+	{
+		pGetSesChalRes->CompletionCode = 0x82;
+        return sizeof (*pRes);
+	}
+	
+	g_BMCInfo.pUserInfo = NULL;
+	pUserInfo = getUserNameInfo(pGetSesChalReq->UserName);
+	if((pUserInfo == NULL) || (TRUE != pUserInfo->UserStatus))
+	{
+		pGetSesChalRes->CompletionCode = 0x81;
+        return sizeof (*pRes);
+	}
+
+  curchannel = pthread_getspecific(g_tls.CurChannel);   
+
+  do
+  {
+      /*generate 32 bit temp session Id*/
+      TempSessId = stm32_generate_random32bit();
+  } while ((NULL != getSessionInfo (SESSION_ID_INFO, &TempSessId)) || (0 == TempSessId));
+
+  SessionInfo.UserId       = (uint8_t)pUserInfo->UserId;
+  /*Activated in ActivateSession Command*/
+  SessionInfo.Activated    = FALSE;
+  SessionInfo.AuthType     = pGetSesChalReq->AuthType;
+  SessionInfo.Channel      = *curchannel & 0xF;
+  SessionInfo.SessionID    = TempSessId;
+	SessionInfo.TimeOutValue = g_BMCInfo.IpmiConfig.SessionTimeOut; 
+
+  if(GetNumOfUsedSessions() >= g_BMCInfo.IpmiConfig.MaxSession)
+  {
+      CleanSession();
+  }
+  /* Add Session information in Table */
+  AddSession (&SessionInfo);
+
+
+	g_BMCInfo.pUserInfo = pUserInfo;
+	
+	pGetSesChalRes->CompletionCode = CC_NORMAL;
+  pGetSesChalRes->TempSessionID  = TempSessId;
+
+	/* generate Randam Challenge String */
+  for(Index=0;Index < CHALLENGE_STR_LEN;Index+=4)
+  {
+      TempRandom = stm32_generate_random32bit();
+//      printf("TempRandom: %#lx\n", TempRandom);
+      ChallengeString[Index] = TempRandom&0xff;
+      ChallengeString[Index+1] = TempRandom>>8;
+      ChallengeString[Index+2] = TempRandom>>16;
+      ChallengeString[Index+3] = TempRandom>>24;
+  }
+  memcpy(pGetSesChalRes->ChallengeString, ChallengeString, CHALLENGE_STR_LEN);
+
+  return sizeof (GetSesChallengeRes_T);
+}
+
+/*---------------------------------------
+* ActivateSession
+*---------------------------------------*/
+int
+ActivateSession ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	//TODO: dummy data
+	ActivateSesReq_T*   pAcvtSesReq = ( ActivateSesReq_T*)pReq;
+	ActivateSesRes_T*   pAcvtSesRes = ( ActivateSesRes_T*)pRes;
+  uint32_t *CurSesID,*curchannel;
+  SessionInfo_T*      pSessInfo;
+
+    /* Initial Outbound Sequence Number cannot be null */  
+    if (pAcvtSesReq->OutboundSeq == 0)  
+    {  
+        pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_SEQ_OUT_OF_RANGE;  
+        return sizeof(*pRes);  
+    }
+
+    CurSesID = pthread_getspecific(g_tls.CurSessionID);  
+    curchannel = pthread_getspecific(g_tls.CurChannel);  
+    
+    pSessInfo = getSessionInfo (SESSION_ID_INFO, CurSesID);
+    if(pSessInfo == NULL)
+    {
+        pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_INVALID_SESSION_ID;
+        return sizeof (*pRes);
+    }
+
+    pSessInfo->Activated    = TRUE;
+    pSessInfo->Channel      = (*curchannel & 0xF);
+    /* set the Max Privilege allowed for the Session*/
+    pSessInfo->MaxPrivilege = pAcvtSesReq->Privilege;
+    /* set the Out bound sequensce Number */
+    pSessInfo->OutboundSeq  = (pAcvtSesReq->OutboundSeq);
+
+    g_BMCInfo.SessionHandle += 1;
+    pSessInfo->SessionHandle = g_BMCInfo.SessionHandle;
+
+
+
+    pAcvtSesRes->CompletionCode = CC_NORMAL;
+    pAcvtSesRes->AuthType = (pSessInfo->AuthType & 0x0F);
+    pAcvtSesRes->SessionID = pSessInfo->SessionID;
+    pAcvtSesRes->InboundSeq = stm32_generate_random32bit();
+    pAcvtSesRes->Privilege = 0x04;
+
+    pSessInfo->InboundRecv = 0xFF;
+    pSessInfo->InboundSeq = (pAcvtSesRes->InboundSeq -1);
+
+    return sizeof (ActivateSesRes_T);
+}
+
+
+/*---------------------------------------
+* SetSessionPrivLevel
+*---------------------------------------*/
+int
+SetSessionPrivLevel ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	SetSesPrivLevelReq_T*   pSetSesPrivLevelReq = ( SetSesPrivLevelReq_T*)pReq;
+	SetSesPrivLevelRes_T*   pSetSesPrivLevelRes = ( SetSesPrivLevelRes_T*)pRes;
+
+    //Check for Reserved bits
+    if((pSetSesPrivLevelReq->Privilege == PRIV_LEVEL_CALLBACK) || (pSetSesPrivLevelReq->Privilege > PRIV_LEVEL_PROPRIETARY))
+    {
+        pSetSesPrivLevelRes->CompletionCode = CC_INV_DATA_FIELD;
+        return sizeof(SetSesPrivLevelRes_T);
+    }
+ 
+    /* According to the IPMI 2.0 Priv Level =1 is reserved */
+    if((PRIV_USER      != pSetSesPrivLevelReq->Privilege) &&
+       (PRIV_OPERATOR  != pSetSesPrivLevelReq->Privilege) &&
+       (PRIV_ADMIN     != pSetSesPrivLevelReq->Privilege) &&
+       (PRIV_OEM     != pSetSesPrivLevelReq->Privilege))
+    {
+        /*Requested Privilege exceeds ChannelPrivilege Limit */
+        pSetSesPrivLevelRes->CompletionCode = CC_INV_DATA_FIELD;
+         return sizeof (*pRes);
+    }
+
+    pSetSesPrivLevelRes->CompletionCode = CC_NORMAL;
+    pSetSesPrivLevelRes->Privilege      = pSetSesPrivLevelReq->Privilege;
+
+    return sizeof (SetSesPrivLevelRes_T);
+}
+
+
+/*---------------------------------------
+* CloseSession
+*---------------------------------------*/
+int
+CloseSession ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    CloseSesReq_T*  pCloseSesReq = (CloseSesReq_T*)pReq;
+	  SessionInfo_T*  pSessInfo;
+    uint32_t          SessionID;
+
+    *pRes = CC_REQ_INV_LEN;
+
+    if ((4 != ReqLen) && (5 != ReqLen))
+    {
+        return sizeof (*pRes);
+    }
+
+    if (0 == pCloseSesReq->SessionID)
+    {
+        if (5 != ReqLen)
+        {
+            return sizeof (*pRes);
+        }
+        SessionID = (uint32_t)pCloseSesReq->SessionHandle;
+        *pRes = CC_CLOSE_INVALID_SESSION_ID_HANDLE;
+        pSessInfo = getSessionInfo (SESSION_HANDLE_INFO, &SessionID);
+    }
+    else
+    {
+        if (4 != ReqLen)
+        {
+            return sizeof (*pRes);
+        }
+        SessionID = pCloseSesReq->SessionID;
+        *pRes = CC_CLOSE_INVALID_SESSION_ID;
+        pSessInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
+    }
+
+    if ((NULL == pSessInfo) || (0 == pSessInfo->Activated))
+    {
+        return sizeof (*pRes);
+    }
+
+    /* The SessionInfo is deleted form session table  from interface */
+    DeleteSession(pSessInfo);
+    *pRes = CC_NORMAL;
+    return sizeof (*pRes);
+}
+
+//#if GET_SESSION_INFO != UNIMPLEMENTED
+///*---------------------------------------
+//* GetSessionInfo
+//*---------------------------------------*/
+//int
+//GetSessionInfo ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      GetSesInfoReq_T* pGetSesInfoReq = ( GetSesInfoReq_T*)pReq;
+//      GetSesInfoRes_T* pGetSesInfoRes = ( GetSesInfoRes_T*)pRes;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//    LANSesInfoRes_T     LANSesInfo;
+//    LANIPv6SesInfoRes_T     LANIPv6SesInfo;
+//       SessionInfo_T*   pSessInfo;
+//       ChannelInfo_T*   pChannelInfo;
+//       void*            SessionArg;
+//    uint8_t 	     SessionArgAlign[4];
+//    uint8_t            SessionArgType,EthIndex, netindex = 0xFF;
+//    char    IfcName[IFNAMSIZ];
+//    uint32_t *CurSesID,*curchannel;
+//    int i;
+
+//    *pRes = CC_REQ_INV_LEN;
+
+//    switch (pGetSesInfoReq->SessionIndex)
+//    {
+//        case 0:
+//            /* Get session information for this session */
+//            if (1 != ReqLen)
+//            {
+//                return sizeof (*pRes);
+//            }
+//            SessionArgType  = SESSION_ID_INFO;
+//            OS_THREAD_TLS_GET(g_tls.CurSessionID,CurSesID);
+//            SessionArg      = CurSesID;
+//            break;
+
+//        case 0xFF:
+//            if (5 != ReqLen)
+//            {
+//                return sizeof (*pRes);
+//            }
+//            SessionArgType  = SESSION_ID_INFO;
+
+//            SessionArgAlign[0]      = pGetSesInfoReq->SessionHandleOrID[0];
+//            SessionArgAlign[1]      = pGetSesInfoReq->SessionHandleOrID[1];
+//            SessionArgAlign[2]      = pGetSesInfoReq->SessionHandleOrID[2];
+//            SessionArgAlign[3]      = pGetSesInfoReq->SessionHandleOrID[3];
+//            SessionArg = SessionArgAlign;
+//            break;
+
+//        case 0xFE:
+//            if (2 != ReqLen)
+//            {
+//                return sizeof (*pRes);
+//            }
+//            if (pGetSesInfoReq->SessionHandleOrID[0] == 0)
+//            {
+//                *pRes=CC_INV_DATA_FIELD;
+//                return sizeof (*pRes);
+//            }
+//            SessionArgType  = SESSION_HANDLE_INFO;
+//            SessionArgAlign[0]      = pGetSesInfoReq->SessionHandleOrID[0];
+//            SessionArgAlign[1]      = pGetSesInfoReq->SessionHandleOrID[1];
+//            SessionArgAlign[2]      = pGetSesInfoReq->SessionHandleOrID[2];
+//            SessionArgAlign[3]      = pGetSesInfoReq->SessionHandleOrID[3];
+//            SessionArg = SessionArgAlign;
+//            break;
+
+//        default:
+//            if (1 != ReqLen)
+//            {
+//                return sizeof (*pRes);
+//            }
+//            SessionArgType  = SESSION_INDEX_INFO;
+//            SessionArg      = &pGetSesInfoReq->SessionIndex;
+//            break;
+//    }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
+//    pSessInfo = getSessionInfo (SessionArgType, SessionArg, BMCInst);
+//    if (NULL == pSessInfo)
+//    {
+//        TDBG ("GetSessionInfo: pSessInfo is NULL\n");
+//        /* if there is no active channel for the current session Index
+//        * return the following bytes
+//        */
+
+//        OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
+//        pChannelInfo = getChannelInfo (*curchannel & 0xF, BMCInst);
+//        if(NULL == pChannelInfo)
+//        {
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//            pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//            return	sizeof (*pRes);
+//        }
+
+//        pGetSesInfoRes->CompletionCode          = CC_NORMAL;
+//        pGetSesInfoRes->SessionHandle           = BMC_GET_SHARED_MEM (BMCInst)->SessionHandle;
+//        pGetSesInfoRes->NumPossibleActiveSession=  pBMCInfo->IpmiConfig.MaxSession;
+//        pGetSesInfoRes->NumActiveSession        = GetNumOfActiveSessions (BMCInst);
+
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//        return (sizeof (GetSesInfoRes_T) - sizeof (ActiveSesInfo_T) - sizeof (SessionInfoRes_T));
+//    }
+
+//    memset (pGetSesInfoRes,0,sizeof(GetSesInfoRes_T));
+//    pChannelInfo = getChannelInfo (pSessInfo->Channel, BMCInst);
+//    if(NULL == pChannelInfo)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//        pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return	sizeof (*pRes);
+//    }
+//    pGetSesInfoRes->CompletionCode              = CC_NORMAL;
+//    pGetSesInfoRes->SessionHandle               = pSessInfo->SessionHandle;
+//    pGetSesInfoRes->NumPossibleActiveSession    = pBMCInfo->IpmiConfig.MaxSession;
+//    pGetSesInfoRes->NumActiveSession            = GetNumOfActiveSessions (BMCInst);
+//    pGetSesInfoRes->ActiveSesinfo.UserID        = pSessInfo->UserId & 0x3F;
+//    pGetSesInfoRes->ActiveSesinfo.Privilege     = pSessInfo->Privilege & 0x0F;
+//    /* Set protocol bit as per Auth Type, bit4 must be 1 for IPMIv2.0 RMCP, 0 for IPMIv1.5 */
+//    if( AUTHTYPE_RMCP_PLUS_FORMAT == pSessInfo->AuthType )
+//    {
+//        pGetSesInfoRes->ActiveSesinfo.ChannelNum    = (pSessInfo->Channel & 0x0F) | 0x10;
+//    }else
+//    {
+//        pGetSesInfoRes->ActiveSesinfo.ChannelNum    = pSessInfo->Channel & 0x0F;
+//    }
+//    EthIndex= GetEthIndex(pSessInfo->Channel & 0x0F, BMCInst);
+//    if(0xff == EthIndex)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//       *pRes = CC_INV_DATA_FIELD;
+//       DeleteSession (pSessInfo,BMCInst);
+//       return sizeof (uint8_t);
+//    }
+//    memset(IfcName,0,sizeof(IfcName));
+//    /*Get the EthIndex*/
+//    if(GetIfcName(EthIndex,IfcName, BMCInst) == -1)
+//    {
+//       TCRIT("Error in Getting Ifc name\n");
+//       OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//       *pRes = CC_INV_DATA_FIELD;
+//       return sizeof (uint8_t);
+//    }
+
+//    for(i=0;i<sizeof(Ifcnametable)/sizeof(IfcName_T);i++)
+//    {
+//       if(strcmp(Ifcnametable[i].Ifcname,IfcName) == 0)
+//       {
+//           netindex= Ifcnametable[i].Index;
+//           break;
+//       }
+//    }
+
+//    if(netindex == 0xFF)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//       *pRes = CC_INV_DATA_FIELD;
+//       return sizeof (uint8_t);
+//    }
+//    if (IsLANChannel( pSessInfo->Channel, BMCInst))
+//    {
+//        if(g_corefeatures.global_ipv6  == ENABLED)
+//        {
+//            if(GetIPAdrressType(&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[0])==4) 
+//            {
+//                memset(&LANSesInfo,0,sizeof(LANSesInfo));
+//                /* IP Address */
+//                _fmemcpy (&(LANSesInfo.IPAddress),
+//                                    &pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[sizeof(struct in6_addr)-sizeof(struct in_addr)],
+//                                    sizeof(struct in_addr));
+//                /* MAC Address */
+//                if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
+//                nwGetSrcCacheMacAddr((uint8_t*)&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[12],
+//                                                        netindex, pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
+
+//                _fmemcpy(LANSesInfo.MACAddress, pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
+//                /* Port number */
+//                LANSesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
+
+//                _fmemcpy ((pRes+sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)),&LANSesInfo, sizeof (LANSesInfoRes_T));
+//                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//                return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)+sizeof (LANSesInfoRes_T));
+//                }
+//            else
+//            {
+//                /* IP Address */
+//                memset(&LANIPv6SesInfo,0,sizeof(LANIPv6SesInfo));
+//                _fmemcpy (&(LANIPv6SesInfo.IPv6Address),
+//                		pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr,
+//                		sizeof(struct in6_addr));
+//                /* MAC Address */
+//                if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
+//                    nwGetSrcMacAddr_IPV6((uint8_t*)&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr,
+//                                        pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
+
+//                _fmemcpy(LANIPv6SesInfo.MACAddress, pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
+//                /* Port number */
+//                LANIPv6SesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
+
+//                _fmemcpy ((pRes+sizeof (GetSesInfoRes_T) - sizeof(SessionInfoRes_T)),&LANIPv6SesInfo, sizeof (LANIPv6SesInfoRes_T));
+//                OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//                return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)+sizeof (LANIPv6SesInfoRes_T));
+//                }
+//        }
+//        else
+//        {
+
+//            /* IP Address */
+//            _fmemcpy (pGetSesInfoRes->SesInfo.LANSesInfo.IPAddress,
+//            		pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr,
+//            		sizeof (pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr));
+//            /* MAC Address */
+//            if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
+//                nwGetSrcCacheMacAddr((uint8_t*)pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr, netindex, 
+//                                pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
+//            _fmemcpy(pGetSesInfoRes->SesInfo.LANSesInfo.MACAddress, 
+//                    pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
+//            /* Port number */
+//            pGetSesInfoRes->SesInfo.LANSesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//            return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T) + sizeof (LANSesInfoRes_T));
+//        }
+//    }
+//    else if (pBMCInfo->IpmiConfig.SerialIfcSupport == 1 && pBMCInfo->SERIALch== pSessInfo->Channel)
+//    {
+
+//        pChannelInfo = getChannelInfo (pBMCInfo->SERIALch, BMCInst);
+//        if(NULL == pChannelInfo)
+//        {
+//            pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//            return	sizeof (*pRes);
+//        }
+
+//        pGetSesInfoRes->SesInfo.SerialSesInfo.SessionActivityType = 0;
+//        pGetSesInfoRes->SesInfo.SerialSesInfo.DestinationSelector = 0;
+
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//        return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T) + sizeof (SerialSesInfoRes_T));
+//    }
+//    else
+//    {
+//        pChannelInfo = getChannelInfo(pSessInfo->Channel, BMCInst);
+//        if(NULL == pChannelInfo)
+//        {
+//            pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//            return sizeof (*pRes);
+//        }
+
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
+//        return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T));
+//    }
+//}
+//#endif
+
+
+///**
+// * @fn GetAuthCodeForTypeV15
+// * @brief This function will use the encryption technique supported 
+// * 			in IPMI V1.5 in order to produce Auth Code.
+// * @param[in] pUserInfo - Pointer to User info structure.
+// * @param[in] pGetAuthCodeReq - Pointer to the structure of request data
+// * @param[out] pGetAuthCodeRes - Pointer to the resultant data.
+// * @retval size of the result data.
+// */
+//static int
+//GetAuthCodeForTypeV15 (UserInfo_T* pUserInfo,
+//        GetAuthCodeReq_T* pGetAuthCodeReq,
+//        GetAuthCodeRes_T* pGetAuthCodeRes )
+//{
+//    uint8_t   AuthCode;
+//    uint8_t   InBuffer[2*IPMI15_MAX_PASSWORD_LEN + HASH_DATA_LENGTH];
+//    char    UserPswd[MAX_PASSWD_LEN];
+//    uint8_t   PwdEncKey[MAX_SIZE_KEY + 1] = {0};
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    memset(&(pGetAuthCodeRes->AuthCode), 0, AUTH_CODE_HASH_LEN);
+//    AuthCode = pGetAuthCodeReq->AuthType & AUTH_CODE_V15_MASK;
+//    if((pGetAuthCodeReq->AuthType & (BIT5 | BIT4)) ||
+//       (AuthCode == AUTHTYPE_RESERVED) || (AuthCode == AUTHTYPE_NONE) ||
+//       (AuthCode == AUTHTYPE_STRAIGHT_PASSWORD) ||
+//       (AuthCode > AUTHTYPE_OEM_PROPRIETARY))
+//    {
+//        pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return (sizeof (GetAuthCodeRes_T) - 4);
+//    }
+
+//    if (g_corefeatures.userpswd_encryption == ENABLED)
+//    {
+//        /* Get Encryption Key from the MBMCInfo_t structure */
+//        LOCK_BMC_SHARED_MEM(BMCInst);
+//            memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
+//        UNLOCK_BMC_SHARED_MEM(BMCInst);
+
+//        if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
+//        {
+//            TCRIT("Error in decrypting the IPMI User password for User ID:%d.\n", pUserInfo->UserId);
+//            pGetAuthCodeRes->CompletionCode = CC_UNSPECIFIED_ERR;
+//            return sizeof(*pGetAuthCodeRes);
+//        }
+//    	memcpy(&InBuffer[0],UserPswd,IPMI15_MAX_PASSWORD_LEN);
+//    }
+//    else
+//    {
+//    	memcpy(&InBuffer[0],pUserInfo->UserPassword,IPMI15_MAX_PASSWORD_LEN);
+//    }
+
+//    LOCK_BMC_SHARED_MEM(BMCInst);
+//    switch (AuthCode)
+//    {
+//        #if 0 // As per IPMIv2 Markup E4, Straight Password key is Reserved
+//        case AUTH_TYPE_PASSWORD: /* Straight password */
+//            if (0 == _fmemcmp (pUserInfo->UserPassword,pGetAuthCodeReq->HashData,IPMI15_MAX_PASSWORD_LEN))
+//            {
+//                _fmemcpy (pGetAuthCodeRes->AuthCode, "OK", 2);
+//            }
+//            else
+//            {
+//                pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//            }
+//            break;
+//        #endif
+
+//        case AUTH_TYPE_MD2: /* MD2 */
+//            _fmemcpy (&InBuffer[IPMI15_MAX_PASSWORD_LEN],
+//                    pGetAuthCodeReq->HashData, HASH_DATA_LENGTH);
+//            if (g_corefeatures.userpswd_encryption == ENABLED)
+//            {
+//            	_fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
+//                    UserPswd, IPMI15_MAX_PASSWORD_LEN);
+//            }
+//            else
+//            {
+//            	_fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
+//                    pUserInfo->UserPassword, IPMI15_MAX_PASSWORD_LEN);
+//            }
+
+//            AuthCodeCalMD2 (InBuffer, pGetAuthCodeRes->AuthCode, sizeof (InBuffer));
+//            break;
+
+//        case AUTH_TYPE_MD5: /* MD5 */
+//            _fmemcpy (&InBuffer[IPMI15_MAX_PASSWORD_LEN],
+//                    pGetAuthCodeReq->HashData, HASH_DATA_LENGTH);
+//            if (g_corefeatures.userpswd_encryption == ENABLED)
+//            {
+//            	_fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
+//                    UserPswd,IPMI15_MAX_PASSWORD_LEN);
+//            }
+//            else
+//            {
+//            	_fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
+//                    pUserInfo->UserPassword,IPMI15_MAX_PASSWORD_LEN);
+//            }
+//            AuthCodeCalMD5 (InBuffer, pGetAuthCodeRes->AuthCode, sizeof (InBuffer));
+//            break;
+
+//        default:
+//            pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//    }
+
+//    UNLOCK_BMC_SHARED_MEM(BMCInst);
+//    // IPMI V1.5 AuthCode is only 16 byte.
+//    return (sizeof (GetAuthCodeRes_T) - 4);
+//}
+
+///**
+// * @fn GetAuthCodeForTypeV20
+// * @brief This function will use the encryption technique supported 
+// * 			in IPMI V2.0 in order to produce Auth Code.
+// * @param[in] pUserInfo - Pointer to User info structure.
+// * @param[in] pGetAuthCodeReq - Pointer to the structure of request data
+// * @param[out] pGetAuthCodeRes - Pointer to the resultant data.
+// * @retval size of the result data.
+// */
+//static int
+//GetAuthCodeForTypeV20 (UserInfo_T* pUserInfo,
+//        GetAuthCodeReq_T* pGetAuthCodeReq,
+//        GetAuthCodeRes_T* pGetAuthCodeRes )
+//{
+//    uint8_t   AuthCode;
+//    uint8_t   UserPasswdLen=0;
+//    uint8_t   DecVal = 0;
+//     uint8_t m_SIK [SESSION_INTEGRITY_KEY_SIZE];
+//    char   UserPswd[MAX_PASSWD_LEN];
+//    unsigned char PwdEncKey[MAX_SIZE_KEY + 1] = {0};
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    if (g_corefeatures.userpswd_encryption == ENABLED)
+//    {
+//        /* Get Encryption Key from the MBMCInfo_t structure */
+//        LOCK_BMC_SHARED_MEM(BMCInst);
+//            memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
+//        UNLOCK_BMC_SHARED_MEM(BMCInst);
+
+//        if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
+//        {
+//            TCRIT("\nError in decrypting the IPMI User password for user with ID:%d.\n", pUserInfo->UserId);
+//            pGetAuthCodeRes->CompletionCode = CC_UNSPECIFIED_ERR;
+//            return sizeof (*pGetAuthCodeRes);
+//        }
+//    }
+//    else
+//    {
+//        memcpy(&UserPswd, pUserInfo->UserPassword, MAX_PASSWD_LEN);
+//    }
+
+//    /* Calculate password length */
+//    UserPasswdLen = _fstrlen (( char*)UserPswd);
+//    UserPasswdLen = (UserPasswdLen > MAX_PASSWORD_LEN) ?
+//            MAX_PASSWORD_LEN : UserPasswdLen;
+
+//    memset(&(pGetAuthCodeRes->AuthCode), 0, AUTH_CODE_HASH_LEN);
+//    AuthCode = pGetAuthCodeReq->AuthType & AUTH_CODE_V20_MASK;
+//    /* Validate the Auth Code */
+//    if ((AuthCode > MIN_AUTH_CODE_V20) && (AuthCode < MAX_AUTH_CODE_V20))
+//    {
+//        pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return sizeof(GetAuthCodeRes_T);
+//    }
+
+//    LOCK_BMC_SHARED_MEM(BMCInst);
+//    switch(AuthCode)
+//    {
+//        case AUTH_NONE: /* none */
+//            TDBG ("\nInside AUTH_NONE in GetAuthCode");
+//            pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//            break;
+
+//        case AUTH_HMAC_SHA1_96: /* HMAC-SHA1-96 */
+//            TDBG ("\nInside AUTH_HMAC_SHA1_96 in GetAuthCode");
+//            hmac_sha1 ((uint8_t *)UserPswd, UserPasswdLen,
+//                    (uint8_t *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//                    (uint8_t *)m_SIK, SESSION_INTEGRITY_KEY_SIZE);
+
+//            hmac_sha1 ((uint8_t *)m_SIK, SESSION_INTEGRITY_KEY_SIZE,
+//                    (uint8_t *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//                    (uint8_t *)&(pGetAuthCodeRes->AuthCode), HMAC_SHA1_96_LEN);
+
+//            DecVal = AUTH_CODE_HASH_LEN - HMAC_SHA1_96_LEN;
+//            break;
+
+//        case AUTH_HMAC_MD5_128: /* HMAC-MD5-128 */
+//            TDBG ("\nInside AUTH_HMAC_MD5_128 in GetAuthCode");
+//            hmac_md5 ((unsigned char*)UserPswd, UserPasswdLen,
+//                    pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//                    m_SIK, SESSION_HMAC_MD5_I_KEY_SIZE);
+
+//            hmac_md5 (m_SIK, SESSION_HMAC_MD5_I_KEY_SIZE,
+//                    pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//                    (unsigned char *)&(pGetAuthCodeRes->AuthCode), 
+//                    SESSION_HMAC_MD5_I_KEY_SIZE);
+//            DecVal = AUTH_CODE_HASH_LEN - SESSION_HMAC_MD5_I_KEY_SIZE;
+//            break;
+
+//        case AUTH_MD5_128: /* MD5-128 */
+//            TDBG ("\nInside AUTH_MD5_128 in GetAuthCode");
+//            MD5_128 ((char *)UserPswd, UserPasswdLen,
+//                    (char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//                    (char *)m_SIK, SESSION_MD5_KEY_SIZE);
+
+//            MD5_128 ((char *)m_SIK, SESSION_INTEGRITY_KEY_SIZE,
+//                    (char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//                    (char *)&(pGetAuthCodeRes->AuthCode), SESSION_MD5_KEY_SIZE);
+//            DecVal = AUTH_CODE_HASH_LEN - SESSION_MD5_KEY_SIZE;
+//            break;
+
+//        case AUTH_HMAC_SHA256_128: /* HMAC-SHA256-128 */
+//            TDBG ("\nInside AUTH_HMAC_SHA256_128 in GetAuthCode");
+//            hmac_sha256 ((unsigned char *)UserPswd, UserPasswdLen, 
+//    				(unsigned char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//    				(unsigned char *)m_SIK, SHA2_HASH_KEY_SIZE);
+
+//			hmac_sha256 (m_SIK, SHA2_HASH_KEY_SIZE,  
+//    				(unsigned char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
+//    				(unsigned char *)&(pGetAuthCodeRes->AuthCode), HMAC_SHA256_128_LEN);    		
+//            DecVal = AUTH_CODE_HASH_LEN - HMAC_SHA256_128_LEN;
+//            break;            
+
+//            //! TODO: Need support in openssl.
+//        default: /* OEM or Reserved */
+//            pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//    }
+
+//    UNLOCK_BMC_SHARED_MEM(BMCInst);
+//    if (DecVal > sizeof(GetAuthCodeRes_T))
+//        return sizeof(GetAuthCodeRes_T);
+//    else
+//        return (sizeof(GetAuthCodeRes_T) - DecVal);
+//}
+
+///**
+// * @fn GetAuthCode
+// * @brief This function will encrypt the given 16 byte data with
+// *          the algorithm given and return Auth Code.
+// * @param[in] pReq - Request data.
+// * @param[in] ReqLen - Length of the request data.
+// * @param[out] pRes - Result data
+// * @retval size of the result data.
+// */
+//int
+//GetAuthCode ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes )
+//{
+//      GetAuthCodeReq_T*   pGetAuthCodeReq = ( GetAuthCodeReq_T*)pReq;
+//      GetAuthCodeRes_T*   pGetAuthCodeRes = ( GetAuthCodeRes_T*)pRes;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+//       UserInfo_T*         pUserInfo;
+//    uint8_t               AuthType,*curchannel;
+//       ChannelInfo_T*      pChannelInfo;
+//    int nRetSize = 0;
+
+//    /* Check for Reserved Bits */
+//    if((pGetAuthCodeReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4)) ||
+//            (pGetAuthCodeReq->UserID & (BIT7 | BIT6)))
+//    {
+//        pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+//    /* Validate the channel number given */
+//    if (CURRENT_CHANNEL_NUM == pGetAuthCodeReq->ChannelNum)
+//    {
+//        OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
+//        pChannelInfo = getChannelInfo(*curchannel & 0xF,BMCInst);
+//    }
+//    else
+//        pChannelInfo = getChannelInfo(pGetAuthCodeReq->ChannelNum,BMCInst);
+
+//    if (NULL == pChannelInfo)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        *pRes = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//    /* Get the user information for the given userID */
+//    pUserInfo = getUserIdInfo (pGetAuthCodeReq->UserID,BMCInst);
+//    if (NULL == pUserInfo)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        TDBG ("AppDevice.c : GetAuthCode - Invalid user Id\n");
+//        pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return sizeof (*pRes);
+//    }
+
+//    AuthType = pGetAuthCodeReq->AuthType & GET_AUTH_TYPE_MASK;
+//    pGetAuthCodeRes->CompletionCode = CC_NORMAL;
+
+//    switch(AuthType)
+//    {
+//        case AUTH_TYPE_V15: /* IPMI v1.5 AuthCode Algorithms */
+//            nRetSize = GetAuthCodeForTypeV15(pUserInfo, pGetAuthCodeReq, pGetAuthCodeRes,BMCInst);
+//            break;
+
+//        case AUTH_TYPE_V20: /* IPMI v2.0/RMCP+ Algorithm Number */
+//            nRetSize = GetAuthCodeForTypeV20(pUserInfo, pGetAuthCodeReq, pGetAuthCodeRes,BMCInst);
+//            break;
+
+//        default:
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//            pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
+//            return sizeof(*pRes);
+//    }
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//    return nRetSize;
+//}
+
+
+///*---------------------------------------
+//* SetChAccess
+//*---------------------------------------*/
+//int
+//SetChAccess ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      SetChAccessReq_T*   pSetChAccessReq = ( SetChAccessReq_T*)pReq;
+//            uint8_t               ChannelNum, AccessMode;
+//       ChannelInfo_T*      pNvrChInfo;
+//       ChannelInfo_T*      pChannelInfo;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//    uint8_t AccessFlags = 0,i=0,*curchannel;
+////    char ChFilename[MAX_CHFILE_NAME];
+
+//    /* Reserve Bit Checking for Set Channel Acces */
+//    for(i=0;i<ReqLen;i++)
+//    {
+//        if( 0 != (pReq[i] & m_Set_ChReserveBit[i]))
+//        {
+//            *pRes = CC_INV_DATA_FIELD;
+//            return	sizeof (*pRes);
+//        }
+//    }
+//    /* Reserve Value checking */
+
+//    if((pReq[1] & 0xC0)== 0xC0 || (pReq[2] & 0xC0) == 0xC0)
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//        return	sizeof (*pRes);
+//    }
+
+//    ChannelNum = pSetChAccessReq->ChannelNum & 0x0F;
+//    if (CURRENT_CHANNEL_NUM == ChannelNum)
+//    {
+//        OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
+//        ChannelNum = *curchannel & 0xF;
+//    }
+
+//    if (((GetBits (pSetChAccessReq->Privilege, 0x0F)) < PRIV_LEVEL_CALLBACK) ||
+//        ((GetBits (pSetChAccessReq->Privilege, 0x0F)) > PRIV_LEVEL_PROPRIETARY))
+//    {
+//        IPMI_DBG_PRINT_1 ("Invalid Channel Privilege = 0x%x\n", pSetChAccessReq->Privilege);
+//        *pRes = CC_INV_DATA_FIELD;
+//        return  sizeof (*pRes);
+//    }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+//    pChannelInfo = getChannelInfo(ChannelNum, BMCInst);
+//    if (NULL == pChannelInfo)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        *pRes = CC_INV_DATA_FIELD;
+//        return  sizeof (*pRes);
+//    }
+
+//    /*point to NVRAM ChannelInfo */
+//    pNvrChInfo = GetNVRChConfigs(pChannelInfo,BMCInst);
+
+//    if (SESSIONLESS_CHANNEL == pChannelInfo->SessionSupport)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        /* Channel is sessionless channel this command is not supported */
+//        *pRes = CC_SET_CH_COMMAND_NOT_SUPPORTED;
+//        return  sizeof (*pRes);
+//    }
+
+
+//    AccessMode = pSetChAccessReq->ChannelAccess & 0x07;
+//    if(ChannelNum == pBMCInfo->SERIALch)
+//    {
+//        if( NULL != g_PDKHandle[PDK_SWITCHMUX])
+//        {
+//            ((void(*)(uint8_t, int))(g_PDKHandle[PDK_SWITCHMUX]))(AccessMode ,BMCInst);
+//        }
+//     }
+
+//    /* if the requested access mode is supported for the given channel */
+//    if (0 == (pChannelInfo->AccessModeSupported & (1 << AccessMode)))
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        *pRes = CC_SET_CH_ACCES_MODE_NOT_SUPPORTED;
+//        return  sizeof (*pRes);
+//    }
+
+//    AccessFlags = GetBits (pSetChAccessReq->ChannelAccess, 0xC0);
+
+//    switch (AccessFlags)
+//    {
+//        case 0:
+//            /* dont set channel access */
+//            break;
+
+//        case 1:
+//            /*set in  Non volatile Memory and in voatile Memory */
+//            pNvrChInfo->Alerting        = GetBits (pSetChAccessReq->ChannelAccess , 0x20);
+//            pNvrChInfo->PerMessageAuth  = GetBits (pSetChAccessReq->ChannelAccess , 0x10);
+//            pNvrChInfo->UserLevelAuth   = GetBits (pSetChAccessReq->ChannelAccess , 0x08);
+//            pNvrChInfo->AccessMode = AccessMode;
+//            /* write to NVRAM   */
+//            FlushChConfigs((uint8_t*)pNvrChInfo,pNvrChInfo->ChannelNumber,BMCInst);
+//            pChannelInfo->Alerting      = pNvrChInfo->Alerting;
+//            pChannelInfo->PerMessageAuth= pNvrChInfo->PerMessageAuth;
+//            pChannelInfo->UserLevelAuth = pNvrChInfo->UserLevelAuth;
+//            pChannelInfo->AccessMode = AccessMode;
+//            break;
+
+//        case 2:
+//            /*set in volatile Memmory only      */
+//            pChannelInfo->Alerting      = GetBits (pSetChAccessReq->ChannelAccess, 0x20);
+//            pChannelInfo->PerMessageAuth= GetBits (pSetChAccessReq->ChannelAccess, 0x10);
+//            pChannelInfo->UserLevelAuth = GetBits (pSetChAccessReq->ChannelAccess, 0x08);
+//            pChannelInfo->AccessMode = AccessMode;
+//    }
+
+//    switch (GetBits (pSetChAccessReq->Privilege, 0xC0))
+//    {
+//        case 0:
+//            /* dont set prilivege level */
+//            break;
+
+//        case 1:
+//            /* set in non volatile mem  and volatile  memeory*/ /*set privilege*/
+//            pNvrChInfo->MaxPrivilege = GetBits (pSetChAccessReq->Privilege, 0x0F);
+//            pChannelInfo->MaxPrivilege = pNvrChInfo->MaxPrivilege;
+//            break;
+
+//        case 2:
+//            /*set privilege*/
+//            /*  set in volatile memeory only    */
+//            pChannelInfo->MaxPrivilege = GetBits (pSetChAccessReq->Privilege, 0x0F);
+//    }
+
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//    *pRes = CC_NORMAL;
+
+//    return sizeof (*pRes);
+//}
+
+
+///*---------------------------------------
+//* GetChAccess
+//*---------------------------------------*/
+//int
+//GetChAccess ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      GetChAccessReq_T*   pGetChAccessReq = ( GetChAccessReq_T*)pReq;
+//      GetChAccessRes_T*   pGetChAccessRes = ( GetChAccessRes_T*)pRes;
+//       ChannelInfo_T*      pChannelInfo;
+//       ChannelInfo_T*      pNvrChInfo;
+//    uint8_t               ChannelNum,AccessFlag,*curchannel;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    /* Check for reserved bits */
+//    if((0 != (pGetChAccessReq->ChannelNum & 0xf0)) ||
+//        (0 != (pGetChAccessReq->	AccessFlag & 0x3f)))
+//    {
+//        pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return  sizeof (*pRes);
+//    }
+
+//    ChannelNum = pGetChAccessReq->ChannelNum & 0x0F;
+//    if (CURRENT_CHANNEL_NUM == ChannelNum)
+//    {
+//        OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
+//        ChannelNum = *curchannel & 0xF;
+//    }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+//    pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
+
+//    if (NULL == pChannelInfo)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return  sizeof (*pRes);
+//    }
+
+//    if (SESSIONLESS_CHANNEL == pChannelInfo->SessionSupport)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        /* Channel is sessionless channel this command is not supported */
+//        pGetChAccessRes->CompletionCode = CC_GET_CH_COMMAND_NOT_SUPPORTED;
+//        return  sizeof (*pRes);
+//    }
+
+//    AccessFlag = GetBits (pGetChAccessReq->AccessFlag, 0xC0);
+
+//    pGetChAccessRes->CompletionCode = CC_NORMAL;
+
+//    switch (AccessFlag)
+//    {
+//        case 1:
+//            /*  Get Channel Information from NVRAM */
+//            pNvrChInfo = GetNVRChConfigs(pChannelInfo,BMCInst);
+
+//            pGetChAccessRes->ChannelAccess  = SetBits (0x20, pNvrChInfo->Alerting);
+//            pGetChAccessRes->ChannelAccess |= SetBits (0x10, pNvrChInfo->PerMessageAuth);
+//            pGetChAccessRes->ChannelAccess |= SetBits (0x08, pNvrChInfo->UserLevelAuth);
+//            pGetChAccessRes->ChannelAccess |= SetBits (0x07, pNvrChInfo->AccessMode);
+//            pGetChAccessRes->Privilege      = SetBits (0x0F, pNvrChInfo->MaxPrivilege);
+//            break;
+
+//        case 2:
+//            /*  Get  Channel Information from  Volatile RAM */
+//            pGetChAccessRes->ChannelAccess  = SetBits (0x20, pChannelInfo->Alerting);
+//            pGetChAccessRes->ChannelAccess |= SetBits (0x10, pChannelInfo->PerMessageAuth);
+//            pGetChAccessRes->ChannelAccess |= SetBits (0x08, pChannelInfo->UserLevelAuth);
+//            pGetChAccessRes->ChannelAccess |= SetBits (0x07, pChannelInfo->AccessMode);
+//            pGetChAccessRes->Privilege      = SetBits (0x0F, pChannelInfo->MaxPrivilege);
+//            break;
+
+//        default:
+//            OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//            pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
+//            return  sizeof (*pRes);
+//    }
+
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//    return sizeof (GetChAccessRes_T);
+//}
+
+
+///*---------------------------------------
+//* GetChInfo
+//*---------------------------------------*/
+//int
+//GetChInfo ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//      GetChInfoReq_T*     pGetChInfoReq = ( GetChInfoReq_T*)pReq;
+//      GetChInfoRes_T*     pGetChInfoRes = ( GetChInfoRes_T*)pRes;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+//       ChannelInfo_T*      pChannelInfo;
+//    uint8_t               ChannelNum,*curchannel;
+
+//    if(pGetChInfoReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4)) //Check for Reserved bits
+//    {
+//        pGetChInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return sizeof(*pRes);
+//    }
+
+//    ChannelNum = pGetChInfoReq->ChannelNum;
+//    if (CURRENT_CHANNEL_NUM == ChannelNum)
+//    {
+//        OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
+//        ChannelNum = *curchannel & 0xF;
+//        
+//        /* UDS, not being a physical channel, will hold LAN properties */ 
+//        if(UDS_CHANNEL == ChannelNum)
+//        {
+//        	ChannelNum = LAN_RMCP_CHANNEL1_TYPE;
+//        }
+//    }
+
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
+//    pChannelInfo = getChannelInfo(ChannelNum, BMCInst);
+//    if (NULL == pChannelInfo)
+//    {
+//        OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+//        pGetChInfoRes->CompletionCode = CC_INV_DATA_FIELD ;
+//        return  sizeof (*pRes);
+//    }
+
+//    pGetChInfoRes->CompletionCode        = CC_NORMAL;
+//    pGetChInfoRes->ChannelNum            = ChannelNum;
+//    pGetChInfoRes->ChannelMedium         = pChannelInfo->ChannelMedium;
+//    pGetChInfoRes->ChannelProtocol       = pChannelInfo->ChannelProtocol;
+//    pGetChInfoRes->SessionActiveSupport  = pChannelInfo->SessionSupport << 6;
+//    pGetChInfoRes->SessionActiveSupport |= pChannelInfo->ActiveSession;
+
+//    _fmemcpy (pGetChInfoRes->VendorID, pChannelInfo->ProtocolVendorId,
+//                sizeof (pGetChInfoRes->VendorID));
+//    _fmemcpy (pGetChInfoRes->AuxiliaryInfo, pChannelInfo->AuxiliaryInfo,
+//                sizeof (pGetChInfoRes->AuxiliaryInfo));
+
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
+
+//    return sizeof (GetChInfoRes_T);
+//}
+
+///*---------------------------------------
+//* IsChannelSuppGroups
+//*---------------------------------------*/
+//uint8_t  IsChannelSuppGroups(uint8_t ChannelNum )
+//{
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//       ChannelInfo_T*          pChannelInfo;
+//    if(IsLANChannel(ChannelNum, BMCInst))
+//    {
+//        
+//        pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
+//        if(pChannelInfo==NULL)
+//            return 0;
+//        if(pChannelInfo->ChannelType==LAN_RMCP_CHANNEL1_TYPE) 
+//        {
+//           return pChannelInfo->ChannelType;
+//        }
+//        else
+//        {
+//            if(pChannelInfo->ChannelType==LAN_RMCP_CHANNEL2_TYPE)
+//            {
+//               return pChannelInfo->ChannelType;
+//            }
+//            else
+//            {
+//                if(pChannelInfo->ChannelType==LAN_RMCP_CHANNEL3_TYPE)
+//                {
+//                   return pChannelInfo->ChannelType;
+//                }
+//                else
+//                    return 0;
+//            }
+//        }
+//        return 0;
+//    }
+//    else
+//    {
+//        if (pBMCInfo->IpmiConfig.SerialIfcSupport == 1 && (pBMCInfo->SERIALch != CH_NOT_USED && ChannelNum == pBMCInfo->SERIALch))
+//        {
+//            pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
+//            if(pChannelInfo==NULL)
+//                return 0;
+//            return pChannelInfo->ChannelType;
+//        }
+//        else 
+//            return 0;
+//    }
+//}
+///*---------------------------------------
+//* ModifyUsrGRP
+//*---------------------------------------*/
+//int
+//ModifyUsrGrp(char * UserName,uint8_t ChannelNum,uint8_t OldAccessLimit, uint8_t NewAccessLimit )
+//{
+
+//    char oldgrp[20]="",newgrp[20]="";
+
+//    if(0 == NewAccessLimit)
+//    {
+//        DeleteUsrFromIPMIGrp(UserName);
+//    }
+
+//    if(PRIV_LEVEL_NO_ACCESS == OldAccessLimit)
+//    {
+//        strcpy(oldgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege].grpname);
+//    }
+//    else if(IGNORE_ADD_OR_REMOVE != OldAccessLimit)
+//    {
+//        strcpy(oldgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege+OldAccessLimit].grpname);
+//    }
+
+//    if(PRIV_LEVEL_NO_ACCESS == NewAccessLimit)
+//    {
+//        strcpy(newgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege].grpname);
+//    }
+//    else if(IGNORE_ADD_OR_REMOVE != NewAccessLimit)
+//    {
+//        strcpy(newgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege+NewAccessLimit].grpname);
+//    }
+
+//    AddIPMIUsrtoChGrp(UserName,(char *)oldgrp,(char *)newgrp);
+//    return 0;
+//}
+
+/*---------------------------------------
+* SetUserAccess
+*---------------------------------------*/
+int
+SetUserAccess ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	SetUserAccessReq_T*     pSetUserAccessReq = ( SetUserAccessReq_T*)pReq;
+	UserInfo_T*             pUserInfo;
+    
+    if (ReqLen == sizeof(SetUserAccessReq_T) - sizeof(pSetUserAccessReq->SessionLimit) )
+    {
+        pSetUserAccessReq->SessionLimit = 0;
+    }
+    else if(ReqLen == sizeof(SetUserAccessReq_T))
+    {
+        if(0 != pSetUserAccessReq->SessionLimit)
+        {
+            *pRes = CC_INV_DATA_FIELD;
+            return  sizeof (*pRes);
+        }
+    }
+    else
+    {
+        *pRes = CC_REQ_INV_LEN;
+        return  sizeof (*pRes);
+    }
+
+    pUserInfo = getUserIdInfo(pSetUserAccessReq->UserID);
+    if (NULL == pUserInfo)
+    {
+        printf ("AppDevice.c : SetUserAccess - Invalid user Id\n");
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof (*pRes);
+    }
+
+    // if (pUserInfo->ID != USER_ID)
+    // {
+    //     printf("Invalid data field\n");
+    //     *pRes = CC_INV_DATA_FIELD;
+    //     return  sizeof (*pRes);
+    // }
+	
+//	pUserInfo->ChannelAccess = (pSetUserAccessReq->ChannelNoUserAccess&0x70) | (pSetUserAccessReq->AccessLimit&0x0f);
+    *pRes = CC_NORMAL;
+
+    return sizeof (*pRes);
+}
+
+/*---------------------------------------
+* GetUserAccess
+*---------------------------------------*/
+int
+GetUserAccess ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	GetUserAccessReq_T*     pGetUserAccessReq = ( GetUserAccessReq_T*)pReq;
+	GetUserAccessRes_T*     pGetUserAccessRes = ( GetUserAccessRes_T*)pRes;
+	UserInfo_T*             pUserInfo;
+
+  pUserInfo = getUserIdInfo (pGetUserAccessReq->UserID);
+
+  if (NULL == pUserInfo)
+	{
+	   pGetUserAccessRes->CompletionCode = CC_INV_DATA_FIELD;
+	   return  sizeof (*pRes);
+	}
+
+  if(FALSE == pUserInfo->UserStatus)
+    pGetUserAccessRes->ChannelAccess  = 0x0F;  
+  else
+    pGetUserAccessRes->ChannelAccess  = 0x34;  
+
+  pGetUserAccessRes->CompletionCode = CC_NORMAL;
+  pGetUserAccessRes->MaxNoUserID    = MAX_USER_NUM;
+  pGetUserAccessRes->CurrentUserID  = g_BMCInfo.CurrentNoUser;
+  pGetUserAccessRes->FixedUserID    = 0;
+	  
+
+    return sizeof (GetUserAccessRes_T);
+}
+
+
+/*---------------------------------------
+* SetUserName
+*---------------------------------------*/
+int
+SetUserName ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)  //default password 123456
+{
+  	SetUserNameReq_T*       pSetUserNameReq = ( SetUserNameReq_T*)pReq;
+  	UserInfo_T*             pUserInfo;
+  	uint8_t                 i;
+  	uint8_t   	UserName[MAX_USERNAME_LEN + 1];   //plus 1 for null terminator
+  	uint8_t 	InvalidChar[]={  ' ' , ',' , '.' , '/' , ':' , ';' , '\\' , '(', ')' , 0x01 ,
+					   0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09, 0x0A ,
+					   0x0B , 0x0C , 0x0D , 0x0E , 0x0F , 0x10 , 0x11 , 0x12, 0x13 ,
+					   0x14 , 0x15 , 0x16 , 0x17 , 0x18 , 0x19 , 0x1A , 0x1B, 0x1C ,
+					   0x1D , 0x1E , 0x1F , 0x7F} ;
+
+
+    // Check for Reserved bits
+    if(pSetUserNameReq->UserID & (BIT7 | BIT6) || (pSetUserNameReq->UserID == 0x00))
+    {
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof(*pRes);
+    }
+
+    /*User Id exceeded the limit or  Cant set NULL User */
+    if (pSetUserNameReq->UserID > MAX_USER_NUM )
+    {
+        *pRes = CC_INV_DATA_FIELD ;
+        return  sizeof (*pRes);
+    }
+
+    
+    
+    /* We should not set the NULL user */
+    if(0== pSetUserNameReq->UserName [0] )
+    {
+        printf("\n Setting the NULL user :%x",pSetUserNameReq->UserID);
+        *pRes = CC_INV_DATA_FIELD ;
+        return	sizeof (*pRes);
+    }
+
+    if((strlen(pSetUserNameReq->UserName) > MAX_USERNAME_LEN) || (strlen(pSetUserNameReq->UserName) == 0))
+    {
+      printf("Invalid username length: %d\n", strlen(pSetUserNameReq->UserName));
+      *pRes = CC_INV_DATA_FIELD;
+      return 1;
+    }
+    pUserInfo = getUserIdInfo(pSetUserNameReq->UserID);
+
+    /* check for numeric first char and special chars */
+    if( (pSetUserNameReq->UserName[0] >= '0') && (pSetUserNameReq->UserName[0] <= '9')  )
+    {
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof(*pRes);
+    }
+    else
+    {
+    		strncpy((char *)UserName,(const char *) pSetUserNameReq->UserName, sizeof(pSetUserNameReq->UserName));
+    		UserName[MAX_USERNAME_LEN] = '\0';
+        for(i=0;i<sizeof(InvalidChar);i++)
+        {
+            if( NULL != strchr((const char *)UserName, InvalidChar[i] ))
+            {
+                *pRes = CC_INV_DATA_FIELD;
+                return sizeof(*pRes);
+            }
+        }
+    }
+    
+    //Don't check duplicated user names for 0xFF, this request is for deleting user
+    if(0xFF != pSetUserNameReq->UserName [0])
+    {
+        //checking for Duplicate user names
+        if(CheckForDuplicateUsers(pSetUserNameReq->UserName)==FALSE)
+        {
+            printf("Duplicate ipmi user!!\n");
+            *pRes = CC_INV_DATA_FIELD;
+            return	sizeof (*pRes);    		
+        }
+    }
+
+    /* If User[0] is 0xFF means the user is requested to delete */
+    if (0xFF == pSetUserNameReq->UserName [0])	//delete user 
+    {
+        if( (g_BMCInfo.CurrentNoUser > 1) && (0 != pUserInfo->UserId))
+        {
+      			if(pUserInfo->UserStatus == TRUE)
+      			{
+      				g_BMCInfo.CurrentNoUser--;
+      			}
+            /* Delete the user both in Volatile & Non Volatile memory*/
+            memset (pUserInfo,    0, sizeof (UserInfo_T));
+        }
+        else
+        {
+            *pRes = CC_INV_DATA_FIELD ;
+            return  sizeof (*pRes);
+        }
+    }
+    else if(0 == pUserInfo->UserId)	//add user
+    {
+        /* If First time-if user ID does not exist  */
+        /* if the user name is set for the first time */
+        pUserInfo->UserId        = pSetUserNameReq->UserID;
+        pUserInfo->UserStatus    = TRUE;
+		    memcpy(pUserInfo->UserName, pSetUserNameReq->UserName, MAX_USERNAME_LEN);
+        strcpy(pUserInfo->UserPassword, "123456");
+        g_BMCInfo.CurrentNoUser++;
+    }
+    else if (0 != pUserInfo->UserId)//modifying users
+    {
+        memcpy (pUserInfo->UserName, pSetUserNameReq->UserName, MAX_USERNAME_LEN);
+	  }
+
+    FlushUserInfoTbl();
+  	*pRes = CC_NORMAL;
+  	return sizeof (*pRes);
+}
+
+
+/*---------------------------------------
+* GetUserName
+*---------------------------------------*/
+int
+GetUserName ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+      GetUserNameReq_T*       pGetUserNameReq = ( GetUserNameReq_T*)pReq;
+      GetUserNameRes_T*       pGetUserNameRes = ( GetUserNameRes_T*)pRes;
+       UserInfo_T*            pUserInfo;
+
+    // Check for Reserved bits
+    if(pGetUserNameReq->UserID & (BIT7 | BIT6) || (pGetUserNameReq->UserID == 0x00))
+    {
+        pGetUserNameRes->CompletionCode = CC_INV_DATA_FIELD ;
+        return sizeof(*pRes);
+    }
+
+    if (pGetUserNameReq->UserID > MAX_USER_NUM)
+    {
+        /*  if user ID exceeded the Max limit */
+        pGetUserNameRes->CompletionCode = CC_INV_DATA_FIELD ;
+        return  sizeof (*pRes);/* Invalied user id */
+    }
+	  pUserInfo = getUserIdInfo(pGetUserNameReq->UserID);
+
+    /* if User is disabled or if User is not created */
+
+    //if user is disabled we dont have to return invalid data field
+    //instead we return everything possible about the user
+    // if pUserInfo is NULL then nothing in the structure at all
+    // pUserInfo being NULL is probably not possible
+    // If the signature doesnt match then the useris not yet configured
+    // so reasonable to return an error
+    if ((NULL == pUserInfo)/* || (pUserInfo->ID != USER_ID)*/)
+    {
+        /* User with given ID is disabled */
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof (*pRes);
+    }
+
+    //if we are here then the user is just disabled
+    if(FALSE == pUserInfo->UserStatus)
+    {
+        *pRes = CC_INV_DATA_FIELD;
+        return sizeof (*pRes);
+    }
+
+    //Err = 0;
+    pGetUserNameRes->CompletionCode = CC_NORMAL;
+    memcpy (pGetUserNameRes->UserName, pUserInfo->UserName, MAX_USERNAME_LEN);
+	return sizeof (GetUserNameRes_T);
+}
+
+
+/*---------------------------------------
+* SetUserPassword
+*---------------------------------------*/
+int
+SetUserPassword ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+  	SetUserPswdReq_T*       pSetUserPswdReq = ( SetUserPswdReq_T*)pReq;
+  	UserInfo_T*             pUserInfo;
+  	uint8_t                 UserId=0, Operation;
+  	uint8_t          i;
+  	uint8_t          UserPassword[ MAX_PASSWORD_LEN + 1 ] = {0};
+    uint8_t InvalidChar[] = {  0x01 , 0x02 , 0x03 , 0x04 ,0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A, 
+                             0x0B , 0x0C , 0x0D , 0x0E , 0x0F , 0x10 , 0x11 , 0x12 , 0x13 , 0x14,
+                             0x15 , 0x16 , 0x17 , 0x18 , 0x19 , 0x1A , 0x1B , 0x1C , 0x1D , 0x1E , 
+                             0x1F , 0x7F };
+
+
+    Operation = pSetUserPswdReq->Operation & 0x03;
+    UserId    = pSetUserPswdReq->UserID & 0x3F;
+
+    /* Reserved bits checking */
+    if((pSetUserPswdReq->UserID & BIT6) || (UserId == 0) || (pSetUserPswdReq->Operation & (BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)))
+    {
+        *pRes = CC_INV_DATA_FIELD;
+        return	sizeof (*pRes);
+    }
+
+    if (ReqLen == IPMI_15_PASSWORD_LEN)
+    {
+        memset (pSetUserPswdReq->Password + 16, 0, 4);
+    }
+    ReqLen -=2;
+
+    if (UserId > MAX_USER_NUM)
+    {
+        *pRes = CC_INV_DATA_FIELD;
+        return  sizeof (*pRes); /*User Id exceeded the limit*/
+    }
+
+    pUserInfo = getUserIdInfo (UserId);
+
+    if ( NULL ==  pUserInfo )
+    {
+        printf ("Invalid User Id \n");
+        *pRes = CC_INV_DATA_FIELD;
+        return  sizeof (*pRes);
+    }
+
+    *pRes = CC_NORMAL;
+
+    switch (Operation)
+    {
+        case DISABLE_USER:            
+          //here we can disable the user
+          if ((pUserInfo->UserStatus == TRUE) && (g_BMCInfo.CurrentNoUser > 1)) 	
+          {
+        		pUserInfo->UserStatus    = FALSE;
+            g_BMCInfo.CurrentNoUser--;
+            FlushUserInfoTbl();
+          }
+          break;
+        case ENABLE_USER:
+            /*enable user   */
+            if ((0 != pUserInfo->UserId) && (0 != pUserInfo->UserName[0]))
+            {
+                /* if for the first time then Increment the Current user No */
+                if ( pUserInfo->UserStatus == FALSE )
+                {
+        					pUserInfo->UserStatus    = TRUE;
+                  g_BMCInfo.CurrentNoUser++;
+                  FlushUserInfoTbl();
+                }
+            }
+            else
+            {
+        				*pRes = CC_UNSPECIFIED_ERR;
+        				return	sizeof (*pRes);
+            }
+            break;
+
+        case SET_PASSWORD:
+            /*set password  */
+            if ((0 != pUserInfo->UserId) && (0 != pUserInfo->UserName[0]))
+            {
+            	 /*check for special characters*/
+        				strncpy((char *)UserPassword,(const char *) pSetUserPswdReq->Password, sizeof(pSetUserPswdReq->Password));
+                for( i = 0 ; i < sizeof(InvalidChar) ; i++ )
+                {
+                     if( NULL != strchr((const char *)UserPassword, InvalidChar[i] ))
+                     {
+                         *pRes = CC_INV_DATA_FIELD;
+                         return sizeof(*pRes);
+                     }
+                }
+
+        				strcpy(pUserInfo->UserPassword, pSetUserPswdReq->Password);
+        				FlushUserInfoTbl();
+            }
+            else
+            {
+                *pRes = CC_INV_DATA_FIELD;
+                return sizeof (*pRes);
+            }
+            break;
+
+        case TEST_PASSWORD:
+            memcpy (UserPassword, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
+    		
+            /*Test Password */
+            if ((FALSE == pUserInfo->UserStatus) ||
+            (0 != memcmp (UserPassword, pSetUserPswdReq->Password, MAX_PASSWORD_LEN)))
+            {
+                *pRes = CC_PASSWORD_TEST_FAILED;
+            }
+            break;
+
+    }
+    return sizeof (*pRes);
+}
+
+
+///*---------------------------------------
+//* MasterWriteRead
+//*---------------------------------------*/
+//int
+//MasterWriteRead ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//     MasterWriteReadReq_T* pMasterWriteReadReq = ( MasterWriteReadReq_T*)pReq;
+//     MasterWriteReadRes_T* pMasterWriteReadRes = ( MasterWriteReadRes_T*)pRes;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//     uint8_t*                OutBuffer;
+//     uint8_t*                InBuffer;
+//    uint8_t                 ChannelNum, BusID, BusType, SlaveAddr, ReadCount, WriteCount;
+//    INT8S	BusName[64];
+//    int retval = 0;
+//    uint8_t OrgReadCount;
+//    uint8_t	I2CBusId=0;
+//    uint8_t DevID = 0;            // This will be '0' by Default... /dev/peci0
+//    uint8_t Target = 0x30;        // This is the Client address. 30h = 48 is Default for CPU0
+//    uint8_t Domain = 0;           // Multi-Domain support. Default is '0'
+//    uint8_t Xmit_Feedback = 0;    // If full response is Desired, enable this. Default is '1'
+//    uint8_t AWFCS = 0;            // Enable AWFCS in the Transmitted packet by Hw. Default is '0'
+//    uint8_t Read_Len = 0;         // Number of bytes of read back Data from PECI Client
+//    uint8_t Write_Len = 0;        // Number of bytes of data, host is sending to client
+//    uint8_t *Write_Data = NULL;   // Pointer to the Data sent by User to the PECI Client
+//    uint8_t *Read_Data = NULL;    // Pointer to the Data received from PECI Client to be sent to user
+//    int ret_val = 0;
+
+//    if(pMasterWriteReadReq->SlaveAddress & BIT0)
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//         return sizeof (*pRes);
+//    }
+
+//    ReadCount     = pMasterWriteReadReq->ReadCount;
+//    ChannelNum    = GetBits (pMasterWriteReadReq->BusTypeChNo, 0xF0);
+//    BusID         = GetBits (pMasterWriteReadReq->BusTypeChNo, 0x0E);
+//    BusType       = GetBits (pMasterWriteReadReq->BusTypeChNo, 0x01);
+//    SlaveAddr     = (pMasterWriteReadReq->SlaveAddress >> 1);
+
+//    if ((BusType == 0x00 && BusID != 0x00) || ((BusType == 0x01) && (BusID == 0x00)))
+//    {
+//        *pRes = CC_INV_DATA_FIELD;
+//        return  sizeof (*pRes);
+//    }
+//    // Command order:
+//    // ipmitool -H <IP> -I lan -U <Username> -P <Password> bus=7 <Slave_Addr> <Read_Len> <Write_Len> <AWFCS> <Domain> <Data>
+//    // <bus=7> : Bus# must be 0x07 for comunicating with PECI over IPMI. Other buses are not for this feature
+//    // <Slave_Addr> : This is the PECI Client target address.
+//    // <Read_Len> : Number of bytes of data to read from the PECI Response
+//    // <Write_Len> : Number of bytes of data being written, as per the PECI Spec. Number of Bytes after Domain.
+//    // <AWFCS> : 0x01 or 0x00 indicates enabling or disabling of AWFCS feature respectively
+//    // <Domain> : 0x01 or 0x00 indicates domain=1 or domain=0 for multi-domain commands respectively
+//    // <Data> : Rest of data like Command, and other params as per the PECI Spec.
+
+//    // If BusType is External (0x01) and BusID is 7, then we consider to communicate with PECI
+//    
+//    if(g_corefeatures.peci_over_ipmi == ENABLED )
+//    {
+//        if ((BusType & 0x01) && (BusID == 0x07))
+//        {
+//            DevID               = 0;
+//            Xmit_Feedback       = 0;
+//            Target              = pMasterWriteReadReq->SlaveAddress;
+//            Read_Len            = ReadCount;
+//            Write_Len           = pMasterWriteReadReq->Data[0];
+//            AWFCS               = pMasterWriteReadReq->Data[1];
+//            Domain              = pMasterWriteReadReq->Data[2];
+//            Write_Data          = &pMasterWriteReadReq->Data[3];
+//            Read_Data           = &pMasterWriteReadRes->Data[0];
+
+//            memset(&pMasterWriteReadRes->Data[0], 0, sizeof(pMasterWriteReadRes->Data));
+//            
+//            // Call the PECI Generic Handler for passing the command to the PECI Controller
+//            if(g_HALPECIHandle[HAL_PECI_COMMAND] != NULL)
+//            {
+//                ret_val = ((int(*)(char, char, char, char, char, char *, char, char *, char))g_HALPECIHandle[HAL_PECI_COMMAND]) (DevID, Target,
+//                                                                                                Domain, Xmit_Feedback, AWFCS,
+//                                                                                                (char *)Write_Data, Write_Len,
+//                                                                                                (char *)Read_Data, Read_Len );
+//            }
+//            else
+//            {
+//                pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
+//                return sizeof (*pRes);
+//            }
+
+//            /* Check if peci issue command operation is success or not */
+//            if (ret_val == -1)
+//            {
+//                pMasterWriteReadRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof (*pRes);
+//            }
+
+//            pMasterWriteReadRes->CompletionCode = CC_NORMAL;
+
+//            return (sizeof (*pRes) + ReadCount);
+//        }
+//    }
+
+//    if(0 ==BusType){
+//        if(PRIMARY_IPMB_CHANNEL == ChannelNum)
+//        {
+//            I2CBusId=pBMCInfo->IpmiConfig.PrimaryIPMBBusNumber;
+//        }
+//        else if((pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)&&(pBMCInfo->SecondaryIPMBCh == ChannelNum))
+//        {
+//            I2CBusId=pBMCInfo->IpmiConfig.SecondaryIPMBBusNumber;
+//        }else{
+//            *pRes = CC_INV_DATA_FIELD;
+//            return  sizeof (*pRes);
+//        }
+//    }
+//    else
+//    {
+//        if(BusID==pBMCInfo->IpmiConfig.PrimaryIPMBBusNumber)
+//        {
+//            *pRes = CC_INV_DATA_FIELD;
+//            return  sizeof (*pRes);
+//        }else if((pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)&&(BusID==pBMCInfo->IpmiConfig.SecondaryIPMBBusNumber))
+//        {
+//            *pRes = CC_INV_DATA_FIELD;
+//            return  sizeof (*pRes);
+//        }else{
+//            I2CBusId=BusID;
+//        }
+//    }
+
+//    if (ReqLen < 3)
+//    {
+//        *pRes = CC_REQ_INV_LEN;
+//        return  sizeof (*pRes);
+//    }
+
+//    /* number of bytes to write
+//    * = pMasterWriteReadReq length - 3 for  Request Data byte -
+//    * BusTypeChNo,SlaveAddr,Readcount + 1 byte for address
+//    */
+//    WriteCount = ReqLen - 3;
+
+//    OutBuffer = (pMasterWriteReadReq->Data);
+//    InBuffer = pMasterWriteReadRes->Data;
+//    sprintf(BusName,"/dev/i2c%d",I2CBusId);
+
+//    // Save original ReadCount in case we need to modify it
+//    OrgReadCount = ReadCount;
+
+//    // If both ReadCount and WriteCount are zero, then force a read of 1 byte.
+//    // If we do not do this, the write command will fail.
+//    // Having both counts 0 is a way of "pinging" the given device to see if it
+//    // is responding to its address.
+//    
+//    if (ReadCount == 0 && WriteCount == 0)
+//    {
+//        ReadCount = 1;
+//    }
+
+//    if (ReadCount > 0 && WriteCount == 0) 
+//    {
+//        if(g_HALI2CHandle[HAL_I2C_MR] != NULL)
+//        {
+//            retval = ((int(*)(char *,u8,u8 *,size_t))g_HALI2CHandle[HAL_I2C_MR]) (BusName, SlaveAddr, InBuffer, ReadCount);
+//            if (retval < 0)
+//            {
+//                 pMasterWriteReadRes->CompletionCode = (retval & MASTER_RW_ERRCODE);
+//                return sizeof (*pRes);
+//            }
+//        }
+//        else
+//        {
+//            pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
+//            return sizeof(*pRes);
+//        }
+
+//        ReadCount = OrgReadCount;
+
+//        /* copy the bytes read  to Response Data */
+//        _fmemcpy (pMasterWriteReadRes->Data, InBuffer, ReadCount);
+//    }
+//    else if(ReadCount > 0 && WriteCount > 0 )
+//    {
+//        if(g_HALI2CHandle[HAL_I2C_RW] != NULL)
+//        {
+//            retval = ((int(*)(char *,u8,u8 *,u8 *,size_t,size_t))g_HALI2CHandle[HAL_I2C_RW]) (BusName, SlaveAddr, OutBuffer, InBuffer, WriteCount, ReadCount);
+//            if (retval < 0)
+//            {
+//                 pMasterWriteReadRes->CompletionCode = (retval & MASTER_RW_ERRCODE);
+//                return sizeof (*pRes);
+//            }
+//        }
+//        else
+//        {
+//            pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
+//            return sizeof(*pRes);
+//        }
+
+//        ReadCount = OrgReadCount;
+
+//        /* copy the bytes read  to Response Data */
+//        _fmemcpy (pMasterWriteReadRes->Data, InBuffer, ReadCount);
+//    }
+//    else
+//    {
+//        /* No data to read so use master write instead,
+//         * otherwise some devices (EEPROM) that have not finished writing
+//         * will fail on the read transaction and possibly corrupt data
+//         */
+//        if(g_HALI2CHandle[HAL_I2C_MW] != NULL)
+//        {
+//            retval= ((ssize_t(*)(char *,u8,u8 *,size_t))g_HALI2CHandle[HAL_I2C_MW]) (BusName, SlaveAddr, OutBuffer, WriteCount);
+//            if(retval < 0)
+//            {
+//                pMasterWriteReadRes->CompletionCode = (retval & MASTER_RW_ERRCODE);
+//                return sizeof (*pRes);
+//            }
+//        }
+//        else
+//        {
+//            pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
+//            return sizeof(*pRes);
+//        }
+//    }
+
+//    pMasterWriteReadRes->CompletionCode = CC_NORMAL;
+
+//    return (sizeof (*pRes) + ReadCount);
+//}
+
+
+//#if 0
+///*-------------------------------------------
+//* ComputeAuthCode
+//*-------------------------------------------*/
+//void
+//ComputeAuthCode ( uint8_t* pPassword,  SessionHdr_T* pSessionHdr,
+//                 IPMIMsgHdr_T* pIPMIMsg,  uint8_t* pAuthCode,
+//                uint8_t ChannelType)
+//{
+//    if (AUTH_TYPE_PASSWORD == pSessionHdr->AuthType)
+//    {
+//        _fmemcpy (pAuthCode, pPassword, MAX_PASSWORD_LEN);
+//    }
+//    else
+//    {
+//        uint8_t   AuthBuf [MAX_AUTH_PARAM_SIZE];
+//        uint16_t  AuthBufLen = 0;
+//        uint8_t   IPMIMsgLen = *(( uint8_t*) pIPMIMsg - 1);
+
+//        /* Password */
+//        _fmemcpy (AuthBuf, pPassword, MAX_PASSWORD_LEN);
+//        AuthBufLen += MAX_PASSWORD_LEN;
+//        /* Session ID */
+//        _fmemcpy (AuthBuf + AuthBufLen, &pSessionHdr->SessionID, sizeof (uint32_t));
+//        AuthBufLen += sizeof (uint32_t);
+//        /* IPMI Response Message */
+//        _fmemcpy (AuthBuf + AuthBufLen, pIPMIMsg, IPMIMsgLen);
+//        AuthBufLen += IPMIMsgLen;
+
+//        if (ChannelType == MULTI_SESSION_CHANNEL)
+//        {
+//            /* Session Sequence Number */
+//            _fmemcpy (AuthBuf + AuthBufLen,
+//                    &pSessionHdr->SessionSeqNum, sizeof (uint32_t));
+//            AuthBufLen += sizeof (uint32_t);
+//        }
+//        /* Password */
+//        _fmemcpy (AuthBuf + AuthBufLen, pPassword, MAX_PASSWORD_LEN);
+//        AuthBufLen += MAX_PASSWORD_LEN;
+
+//        switch (pSessionHdr->AuthType)
+//        {
+//        case AUTH_TYPE_MD2 :
+//            AuthCodeCalMD2 (AuthBuf, pAuthCode, AuthBufLen);
+//            break;
+
+//        case AUTH_TYPE_MD5 :
+//            AuthCodeCalMD5 (AuthBuf, pAuthCode, AuthBufLen);
+//            break;
+
+//        default  :
+//            TDBG ("RMCP: Invalid Authentication Type \n");
+//        }
+//    }
+//}
+//#endif
+
+///*---------------------------------------
+//* GetSystemInfoParam
+//*---------------------------------------*/
+//int
+//GetSystemInfoParam ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+
+//     GetSystemInfoParamReq_T* pGetSysInfoReq = ( GetSystemInfoParamReq_T*)pReq;
+//     GetSystemInfoParamRes_T* pGetSysInfoRes = (  GetSystemInfoParamRes_T* ) pRes ;
+//     GetSystemInfoParamOEMRes_T* pGetSysInfoOEMRes = (  GetSystemInfoParamOEMRes_T* ) pRes ;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+//       SystemInfoConfig_T*	pSysInfoCfg;
+//    uint8_t resSize = sizeof(pGetSysInfoRes->CompletionCode) + sizeof(pGetSysInfoRes->ParamRevision);
+//    uint8_t oem_len;
+//    unsigned long oem_addr;
+
+//    // Check for Reserved bits
+//    if(pGetSysInfoReq->ParamRev & (BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1 | BIT0))
+//    {
+//        pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//        return sizeof(pGetSysInfoRes->CompletionCode);
+//    }
+
+//    pGetSysInfoRes->CompletionCode   = CC_NORMAL;
+
+//    /* Fill the param's older Version and the present version */
+//    pGetSysInfoRes->ParamRevision    = ((PARAM_OLDER_REVISION << 4) & 0xF0 ) | PARAM_PRESENT_REVISION;
+
+//    /* Check for Revision only parameter */
+//    if (pGetSysInfoReq->ParamRev & GET_PARAM_REV_ONLY )
+//    {
+//        if((MAX_APP_CONF_PARAM >= pGetSysInfoReq->ParamSelector))
+//        {
+//            return resSize;
+//        }
+//        else if(( NULL != g_PDKHandle[PDK_GETSYSINFOPARAM]) && 
+//                    ((MIN_SYSINFO_OEM_CONF_PARAM <= pGetSysInfoReq->ParamSelector) && (MAX_SYSINFO_OEM_CONF_PARAM >= pGetSysInfoReq->ParamSelector)))
+//        {
+//            oem_len = ((int(*)(uint8_t, unsigned long*,int))(g_PDKHandle[PDK_GETSYSINFOPARAM]))(pGetSysInfoReq->ParamSelector, &oem_addr ,BMCInst);
+//            if( oem_len == 0)
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
+//                return sizeof(uint8_t);
+//            }
+//            else
+//                return resSize;
+//        }
+//        else
+//        {
+//            *pRes = CC_PARAM_NOT_SUPPORTED;
+//            return sizeof (*pRes);  
+//        }
+//    }
+
+//    /* Get Systen Info parameters from NVRAM */
+//    pSysInfoCfg = &pBMCInfo->SystemInfoConfig;
+
+//    switch(pGetSysInfoReq->ParamSelector)
+//    {
+//        case SET_IN_PROGRESS_PARAM:		/*Parameter 0 volatile*/
+//            if( (0x00 != pGetSysInfoReq->SetSelector) || (0x00 != pGetSysInfoReq->BlockSelector) )
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof(pGetSysInfoRes->CompletionCode);
+//            }
+
+//            LOCK_BMC_SHARED_MEM(BMCInst);
+//            pGetSysInfoRes->SysInfo.SetInProgress = BMC_GET_SHARED_MEM(BMCInst)->m_Sys_SetInProgress;
+//            UNLOCK_BMC_SHARED_MEM(BMCInst);
+//            resSize++;
+//            break;
+
+//        case SYS_FW_VERSION_PARAM:
+//            _fmemset(&pGetSysInfoRes->SysInfo.SysVerInfo,0,sizeof(SysVerInfo_T));
+//            if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)|| (0x00 != pGetSysInfoReq->BlockSelector))
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof(pGetSysInfoRes->CompletionCode);
+//            }
+
+//            pGetSysInfoRes->SysInfo.SysVerInfo.SetSelector = pGetSysInfoReq->SetSelector;
+//            resSize++;
+//            if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
+//            {
+//                pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[0]=pSysInfoCfg->SysFWVersion.TypeOfEncoding;
+//                pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[1]=pSysInfoCfg->SysFWVersion.StringLength;
+//                _fmemcpy(&pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[2], pSysInfoCfg->SysFWVersion.SysFWVersionName,MAX_STRING_LENGTH_COPY);
+//                resSize += MAX_BLOCK_SIZE;
+//            }
+//            else
+//            {
+//               _fmemcpy(&pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[0],
+//                                        &pSysInfoCfg->SysFWVersion.SysFWVersionName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2],MAX_BLOCK_SIZE);
+//                resSize += MAX_BLOCK_SIZE;
+//            }
+//            break;
+
+//        case SYS_NAME_PARAM:
+//            if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)|| (0x00 != pGetSysInfoReq->BlockSelector))
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof(pGetSysInfoRes->CompletionCode);
+//            }
+
+//            pGetSysInfoRes->SysInfo.SysNameInfo.SetSelector = pGetSysInfoReq->SetSelector;
+//            resSize++;
+//            if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
+//            {
+//                pGetSysInfoRes->SysInfo.SysNameInfo.SysName[0]=pSysInfoCfg->SysName.TypeOfEncoding_Sys_Name;
+//                pGetSysInfoRes->SysInfo.SysNameInfo.SysName[1]=pSysInfoCfg->SysName.StringLength_Sys_Name;
+//                _fmemcpy(&pGetSysInfoRes->SysInfo.SysNameInfo.SysName[2],&pSysInfoCfg->SysName.SystemName,MAX_STRING_LENGTH_COPY);
+//                resSize += MAX_BLOCK_SIZE;
+//             }
+//            else
+//            {
+//                _fmemcpy(&pGetSysInfoRes->SysInfo.SysNameInfo.SysName[0],
+//                                &pSysInfoCfg->SysName.SystemName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2], MAX_BLOCK_SIZE);
+//                resSize += MAX_BLOCK_SIZE;
+//            }
+//            break;
+
+//        case PRIM_OS_NAME_PARAM:
+//            if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)|| (0x00 != pGetSysInfoReq->BlockSelector))
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof(pGetSysInfoRes->CompletionCode);
+//            }
+
+//            pGetSysInfoRes->SysInfo.PrimOSInfo.SetSelector  = pGetSysInfoReq->SetSelector;
+//            resSize++;
+//            if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
+//            {
+//                pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[0]=pSysInfoCfg->PrimaryOSName.TypeOfEncoding_PrimaryOSName;
+//                pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[1]=pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName;
+//                _fmemcpy(&pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[2], &pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName, MAX_STRING_LENGTH_COPY);
+//                resSize += MAX_BLOCK_SIZE;
+//             }
+//             else
+//             {
+//                 _fmemcpy(&pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[0],
+//                             &pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2],MAX_BLOCK_SIZE);
+//                 resSize += MAX_BLOCK_SIZE;
+//              }
+//            break;
+
+//        case OS_NAME_PARAM:
+//            /*Parameter 4 volatile*/
+//            _fmemset(&pGetSysInfoRes->SysInfo.OSInfo,0,sizeof(OSInfo_T));
+//            if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)||(0x00 != pGetSysInfoReq->BlockSelector))
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof(pGetSysInfoRes->CompletionCode);
+//            }
+//            pGetSysInfoRes->SysInfo.OSInfo.SetSelector  = pGetSysInfoReq->SetSelector;
+//            resSize++;
+//            if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
+//            {
+//                LOCK_BMC_SHARED_MEM(BMCInst);
+//                pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[0]=BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.TypeOfEncoding_OSName;
+//                pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[1]=BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName;
+//                _fmemcpy(&pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[2], BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName, MAX_STRING_LENGTH_COPY);
+//                UNLOCK_BMC_SHARED_MEM(BMCInst);
+//                resSize += MAX_BLOCK_SIZE;
+//            }
+//            else
+//            {
+//                LOCK_BMC_SHARED_MEM(BMCInst);
+//                _fmemcpy(&pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[0],
+//                    &BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2],MAX_BLOCK_SIZE);
+//                UNLOCK_BMC_SHARED_MEM(BMCInst);
+//                resSize += MAX_BLOCK_SIZE;
+//           }
+//            
+//            break;
+
+//        default:
+//            if(g_PDKHandle[PDK_GETSYSINFOPARAM] != NULL &&
+//            (pGetSysInfoReq->ParamSelector >= 192 && pGetSysInfoReq->ParamSelector <= 255))
+//            {
+//                oem_len = ((int(*)(uint8_t, unsigned long*,int))(g_PDKHandle[PDK_GETSYSINFOPARAM]))(pGetSysInfoReq->ParamSelector, &oem_addr ,BMCInst);
+//                if( oem_len == 0)
+//                {
+//                    pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
+//                    return sizeof(uint8_t);
+//                }
+//                else
+//                {
+//                    //Acquire the OEM parameters
+//                    if( oem_len < MSG_PAYLOAD_SIZE - sizeof(GetLanCCRev_T))
+//                    {
+//                        memcpy((char*)pGetSysInfoOEMRes + sizeof(GetSystemInfoParamOEMRes_T) ,\
+//                                    (unsigned int*)oem_addr , oem_len);
+//                    }
+//                    else
+//                    {
+//                        pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
+//                        return sizeof(uint8_t);
+//                    }
+//                    return sizeof(GetSystemInfoParamOEMRes_T) + oem_len;
+//                }
+//            }
+//            else
+//            {
+//                pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
+//                return sizeof(pGetSysInfoRes->CompletionCode);
+//            }
+//    }
+//    /* return the size of the response */
+//    return resSize;
+//}
+
+//int validatestring(uint8_t* String,int len,uint8_t TOE)
+//{
+//    int i,delimit = 0,strlen = 0;
+
+//    for(i=0;i<len;i++)
+//    {
+//        if(String[i] == 0)
+//        {
+//            delimit++;
+//        }
+//        else
+//        {
+//            if(delimit != 0)
+//            {
+//                if(TOE == UNICODE)
+//                {
+//                    if(delimit == 2)
+//                    {
+//                        strlen = strlen + 2;
+//                    }
+//                    else
+//                    {
+//                        return -1;
+//                    }
+//                }
+//                else
+//                {
+//                    if(delimit == 1)
+//                    {
+//                        strlen = strlen + 1;
+//                    }
+//                    else
+//                    {
+//                        return -1;
+//                    }
+//                }
+//                delimit = 0;
+//            }
+//            strlen++;
+//        }
+//    }
+
+//    return strlen;
+//}
+
+///*---------------------------------------
+//* SetSystemInfoParam
+//*---------------------------------------*/
+//int
+//SetSystemInfoParam ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes, int BMCInst)
+//{
+//     SetSystemInfoParamReq_T*	pSetSysInfoReq = ( SetSystemInfoParamReq_T*)pReq;
+//     SetSystemInfoParamOEMReq_T*	pSetSysInfoOEMReq = ( SetSystemInfoParamOEMReq_T*)pReq;
+//     SetSystemInfoParamRes_T*	pSetSysInfoRes = ( SetSystemInfoParamRes_T*)pRes;
+//    BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
+//     SystemInfoConfig_T*	pSysInfoCfg;
+//    uint8_t *pSetInProgress;
+//    unsigned long oem_addr[2]={0};      // use oem_addr[1] as read-only/write-only flag
+//    int size,strlen,len;
+//    uint8_t OSName[MAX_OS_NAME_LENGTH] = {0};
+
+//    //If the OEM parameter is existing, then skip the length check.
+//    if(g_PDKHandle[PDK_SETSYSINFOPARAM] == NULL && (pSetSysInfoReq->ParamSelector < 192 )){
+//        if( !( (SET_IN_PROGRESS_PARAM == pSetSysInfoReq->ParamSelector && ( ReqLen == ( sizeof(pSetSysInfoReq->ParamSelector) + sizeof(uint8_t) /* for Data */ ) )) ||
+//    ( pSetSysInfoReq->ParamSelector < MAX_PARAM_SELECTOR && ReqLen == ( sizeof(pSetSysInfoReq->ParamSelector) + sizeof(uint8_t) /* for set Selector */ + MAX_BLOCK_SIZE))) )
+//        {
+//            pSetSysInfoRes->CompletionCode = CC_REQ_INV_LEN;
+//            return sizeof(pSetSysInfoRes->CompletionCode);
+//        }
+//    }
+
+//        pSetInProgress = &BMC_GET_SHARED_MEM(BMCInst)->m_Sys_SetInProgress;
+
+//        pSetSysInfoRes->CompletionCode = CC_NORMAL;
+
+//        /*Get NVRAM System Info Configuration parameters */
+//        pSysInfoCfg = &pBMCInfo->SystemInfoConfig;
+
+//    switch (pSetSysInfoReq->ParamSelector)
+//    {
+//        /*Parameter 0 volatile */
+//        case SET_IN_PROGRESS_PARAM:
+//            LOCK_BMC_SHARED_MEM(BMCInst);
+//            /* If Request for Set In progress */
+//            if(( SYS_INFO_SET_IN_PROGRESS == *pSetInProgress ) &&
+//            ( SYS_INFO_SET_IN_PROGRESS == pSetSysInfoReq->SysInfo.SetInProgress ))
+//            {
+//                UNLOCK_BMC_SHARED_MEM(BMCInst);
+//                /* Trying to SetinProgress when already in set*/
+//                pSetSysInfoRes->CompletionCode = CC_SYS_INFO_SET_IN_PROGRESS ;
+//                return sizeof(pSetSysInfoRes->CompletionCode);
+//            } else if( SYS_INFO_COMMIT_WRITE == pSetSysInfoReq->SysInfo.SetInProgress )
+//            {
+//                /* Write SysInfoConfig to NVR */
+//                FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig,
+//                                  pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SystemInfoConfig_T),BMCInst);
+//                /* Write volatile data to the BMC Shared memory */
+//                
+//            } else if ( SYS_INFO_SET_COMPLETE == pSetSysInfoReq->SysInfo.SetInProgress )
+//            {
+//                //PMCONFIG_FILE(BMCInst,PMConfigFile);
+//                /* Set it to set Complete */
+//                *pSetInProgress = pSetSysInfoReq->SysInfo.SetInProgress;
+//                FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig,
+//                                  pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SystemInfoConfig_T),BMCInst);
+//            } else if ( SYS_INFO_SET_IN_PROGRESS != pSetSysInfoReq->SysInfo.SetInProgress )
+//            {
+//                UNLOCK_BMC_SHARED_MEM(BMCInst);
+//                pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                return sizeof(pSetSysInfoRes->CompletionCode);
+//            }
+
+//            *pSetInProgress = pSetSysInfoReq->SysInfo.SetInProgress;
+//            UNLOCK_BMC_SHARED_MEM(BMCInst);
+//            break;
+
+//            case SYS_FW_VERSION_PARAM:
+//                
+//                if(pSetSysInfoReq->SysInfo.SysVerInfo.SetSelector >= MAX_BLOCK_SIZE)
+//                {
+//                    pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                    return sizeof(pSetSysInfoRes->CompletionCode);
+//                }
+//                if(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector==ZERO_SETSELECTOR)
+//                {
+//                     if(pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]> MAX_FW_VER_LENGTH)
+//                     {
+//                        pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                        return sizeof(pSetSysInfoRes->CompletionCode);
+//                     }
+//                     if(pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0] > MAX_TYPE_OF_ENCODING)
+//                     {
+//                         pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                         return sizeof(pSetSysInfoRes->CompletionCode);
+//                     }
+//                     memset(&pSysInfoCfg->SysFWVersion,0,sizeof(pSysInfoCfg->SysFWVersion));
+//                     pSysInfoCfg->SysFWVersion.TypeOfEncoding=pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0];
+//                     pSysInfoCfg->SysFWVersion.StringLength=pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1];
+//                     /*First character should not be a delimiter*/
+//                     if(pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[2] == 0x0 || ((pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0] == UNICODE) && (pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[2] == 0x0 || pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[3] == 0x0)))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                     strlen = validatestring(&pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0]);
+//                     if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]) || ((pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]))
+//                     {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                     }
+//                     if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
+//                     {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                     }
+//                     _fmemcpy(&pSysInfoCfg->SysFWVersion.SysFWVersionName[0],&pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[2], MAX_STRING_LENGTH_COPY);
+//                     FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.SysFWVersion,
+//                                                 pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysFWVersion_T),BMCInst);
+//                }
+//                else
+//                {
+//                    _fmemcpy(&pSysInfoCfg->SysFWVersion.SysFWVersionName[(pSetSysInfoReq->SysInfo.SysVerInfo.SetSelector* MAX_BLOCK_SIZE) - 2], 
+//                                                 &pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0],MAX_BLOCK_SIZE); 
+//                    len = ((pSetSysInfoReq->SysInfo.SysVerInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
+//                    strlen = validatestring(&pSysInfoCfg->SysFWVersion.SysFWVersionName[0],len,pSysInfoCfg->SysFWVersion.TypeOfEncoding);
+//                    if(strlen == -1 || (strlen > pSysInfoCfg->SysFWVersion.StringLength))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                    /*Check the String length*/
+//                    if(((len < pSysInfoCfg->SysFWVersion.StringLength) && (len != strlen)) || ((len > pSysInfoCfg->SysFWVersion.StringLength) && (pSysInfoCfg->SysFWVersion.StringLength != strlen)))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                    if((len == pSysInfoCfg->SysFWVersion.StringLength) && (pSysInfoCfg->SysFWVersion.StringLength != strlen))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+
+//                    FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,
+//                                (uint8_t*)&pBMCInfo->SystemInfoConfig.SysFWVersion,pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysFWVersion_T),BMCInst);
+//                }
+//                break;
+
+//            case SYS_NAME_PARAM:
+//                if(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector >= MAX_BLOCK_SIZE )
+//                {
+//                    pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                    return sizeof(pSetSysInfoRes->CompletionCode);
+//                }
+//                if(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector==ZERO_SETSELECTOR)
+//                {
+//                    if((pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1] > MAX_SYS_NAME_LENGTH))
+//                    {
+//                        pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                        return sizeof(pSetSysInfoRes->CompletionCode);
+//                    }
+//                    if(pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0]>MAX_TYPE_OF_ENCODING)
+//                    {
+//                        pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                        return sizeof(pSetSysInfoRes->CompletionCode);
+//                    }
+//                    memset(&pSysInfoCfg->SysName,0,sizeof(pSysInfoCfg->SysName));
+//                    pSysInfoCfg->SysName.TypeOfEncoding_Sys_Name=pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0];
+//                    pSysInfoCfg->SysName.StringLength_Sys_Name=pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1];
+
+//                     /*First character should not be a delimiter*/
+//                     if(pSetSysInfoReq->SysInfo.SysNameInfo.SysName[2] == 0x0 || ((pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0] == UNICODE) && (pSetSysInfoReq->SysInfo.SysNameInfo.SysName[2] == 0x0 || pSetSysInfoReq->SysInfo.SysNameInfo.SysName[3] == 0x0)))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+
+//                    strlen = validatestring(&pSetSysInfoReq->SysInfo.SysNameInfo.SysName[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0]);
+//                    if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1]) || ((pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1]))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                     if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
+//                     {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                     }
+
+//                    _fmemcpy(&pSysInfoCfg->SysName.SystemName[0], &pSetSysInfoReq->SysInfo.SysNameInfo.SysName[2],MAX_STRING_LENGTH_COPY);
+//                    FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.SysName,
+//                                            pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysName_T),BMCInst);
+//                }
+//                else
+//                {
+//                    _fmemcpy(&pSysInfoCfg->SysName.SystemName[(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector* MAX_BLOCK_SIZE) - 2],
+//                                    &pSetSysInfoReq->SysInfo.SysNameInfo.SysName,MAX_BLOCK_SIZE);
+//                    len = ((pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
+//                    strlen = validatestring(&pSysInfoCfg->SysName.SystemName[0],len,pSysInfoCfg->SysName.TypeOfEncoding_Sys_Name);
+//                    if(strlen == -1 || (strlen > pSysInfoCfg->SysName.StringLength_Sys_Name))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                    /*Check the String length*/
+//                    if(((len < pSysInfoCfg->SysName.StringLength_Sys_Name) && (len != strlen)) || ((len > pSysInfoCfg->SysName.StringLength_Sys_Name) && (pSysInfoCfg->SysName.StringLength_Sys_Name != strlen)))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                    if((len == pSysInfoCfg->SysName.StringLength_Sys_Name) && (pSysInfoCfg->SysName.StringLength_Sys_Name != strlen))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+
+//                    FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.SysName, 
+//                                pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysName_T),BMCInst);
+//                }
+//                break;
+
+//            case PRIM_OS_NAME_PARAM:
+//                if(pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector >= MAX_BLOCK_SIZE )
+//                {
+//                    pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
+//                    return sizeof(pSetSysInfoRes->CompletionCode);
+//                }
+//                if(pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector==ZERO_SETSELECTOR)
+//                {
+//                    if((pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1] > MAX_PRIM_OS_NAME_LENGTH))
+//                    {
+//                        pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                        return sizeof(pSetSysInfoRes->CompletionCode);
+//                        
+//                    }
+//                    if(pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0]>MAX_TYPE_OF_ENCODING)
+//                    {
+//                        pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                        return sizeof(pSetSysInfoRes->CompletionCode);
+//                    }
+//                    memset(&pSysInfoCfg->PrimaryOSName,0,sizeof(pSysInfoCfg->PrimaryOSName));
+//                    pSysInfoCfg->PrimaryOSName.TypeOfEncoding_PrimaryOSName=pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0];
+//                    pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName=pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1];
+
+//                     /*First character should not be a delimiter*/
+//                     if(pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[2] == 0x0 || ((pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0] == UNICODE) && (pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[2] == 0x0 || pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[3] == 0x0)))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+
+//                    strlen = validatestring(&pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0]);
+//                    if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1]) || ((pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1]))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                     if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
+//                     {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                     }
+
+//                    _fmemcpy(&pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[0], &pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[2], MAX_STRING_LENGTH_COPY);
+//                    FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.PrimaryOSName,
+//                                                    pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(PrimaryOSName_T),BMCInst);
+//                }
+//                else
+//                {
+//                    _fmemcpy(&pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[(pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector * MAX_BLOCK_SIZE) - 2],
+//                                            &pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName, MAX_BLOCK_SIZE);
+//                    len = ((pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
+//                    strlen = validatestring(&pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[0],len,pSysInfoCfg->PrimaryOSName.TypeOfEncoding_PrimaryOSName);
+//                    if(strlen == -1 || (strlen > pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                    /*Check the String length*/
+//                    if(((len < pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName) && (len != strlen)) || ((len > pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName) && (pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName != strlen)))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+//                    if((len == pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName) && (pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName != strlen))
+//                    {
+//                        *pRes = CC_INV_DATA_FIELD;
+//                        return sizeof(uint8_t);
+//                    }
+
+//                    FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,
+//                                (uint8_t*)&pBMCInfo->SystemInfoConfig.PrimaryOSName,pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(PrimaryOSName_T),BMCInst);
+//                }
+//                break;
+
+//        case OS_NAME_PARAM:		
+//            /*Parameter 4 volatile*/
+//            if(pSetSysInfoReq->SysInfo.OSInfo.SetSelector >= MAX_BLOCK_SIZE )
+//            {
+//                pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                return sizeof(pSetSysInfoRes->CompletionCode);
+//            }
+//            if(pSetSysInfoReq->SysInfo.OSInfo.SetSelector==ZERO_SETSELECTOR)
+//            {
+//                if(pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1] > MAX_OS_NAME_LENGTH)
+//                {
+//                    pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                    return sizeof(pSetSysInfoRes->CompletionCode);
+//                }
+//                if(pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0] > MAX_TYPE_OF_ENCODING)
+//                {
+//                    pSetSysInfoRes->CompletionCode	= CC_INV_DATA_FIELD;
+//                    return sizeof(pSetSysInfoRes->CompletionCode);
+//                }
+
+//                 /*First character should not be a delimiter*/
+//                 if(pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[2] == 0x0 || ((pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0] == UNICODE) && (pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[2] == 0x0 || pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[3] == 0x0)))
+//                {
+//                    *pRes = CC_INV_DATA_FIELD;
+//                    return sizeof(uint8_t);
+//                }
+
+//                strlen = validatestring(&pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0]);
+//                if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1]) || ((pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1]))
+//                {
+//                    *pRes = CC_INV_DATA_FIELD;
+//                    return sizeof(uint8_t);
+//                }
+//                 if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
+//                 {
+//                    *pRes = CC_INV_DATA_FIELD;
+//                    return sizeof(uint8_t);
+//                 }
+
+//                memset(&BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName,0,sizeof(OSName_T));
+//                LOCK_BMC_SHARED_MEM(BMCInst);
+//                BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.TypeOfEncoding_OSName=pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0];
+//                BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName=pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1];
+//                _fmemcpy(&BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName, &pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[2], 
+//                                                      MAX_STRING_LENGTH_COPY);
+//                UNLOCK_BMC_SHARED_MEM (BMCInst);
+//            }
+//            else
+//            {
+//                LOCK_BMC_SHARED_MEM(BMCInst);
+//                _fmemcpy(&OSName[0],&BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName[0],MAX_OS_NAME_LENGTH);
+//                _fmemcpy(&OSName[(pSetSysInfoReq->SysInfo.OSInfo.SetSelector * MAX_BLOCK_SIZE) - 2],&pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName,MAX_BLOCK_SIZE);
+//                len = ((pSetSysInfoReq->SysInfo.OSInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
+//                strlen = validatestring(&OSName[0],len,BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.TypeOfEncoding_OSName);
+//                if(strlen == -1 || (strlen > BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName))
+//                {
+//                    *pRes = CC_INV_DATA_FIELD;
+//                    UNLOCK_BMC_SHARED_MEM(BMCInst);
+//                    return sizeof(uint8_t);
+//                }
+//                /*Check the String length*/
+//                if(((len < BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName) && (len != strlen)) || ((len > BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName) && (BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName != strlen)))
+//                {
+//                    *pRes = CC_INV_DATA_FIELD;
+//                    return sizeof(uint8_t);
+//                }
+//                if((len == BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName) && (BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName != strlen))
+//                {
+//                    *pRes = CC_INV_DATA_FIELD;
+//                    return sizeof(uint8_t);
+//                }
+
+//                _fmemcpy(&(BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName[(pSetSysInfoReq->SysInfo.OSInfo.SetSelector * MAX_BLOCK_SIZE) - 2]),
+//                                                                &pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName,MAX_BLOCK_SIZE);
+//                UNLOCK_BMC_SHARED_MEM (BMCInst);
+//            }
+//            break;
+
+//        default:
+//            if(g_PDKHandle[PDK_SETSYSINFOPARAM] != NULL &&
+//               (pSetSysInfoReq->ParamSelector >= 192 && pSetSysInfoReq->ParamSelector <= 255))
+//            {
+//                oem_addr[0] = (unsigned long)((char*)pSetSysInfoOEMReq + sizeof(SetSystemInfoParamOEMReq_T));
+//                size = ((int(*)(uint8_t, unsigned long*,int))(g_PDKHandle[PDK_SETSYSINFOPARAM]))(pSetSysInfoReq->ParamSelector, oem_addr ,BMCInst);
+//                if(size <= 0)
+//               {
+//                    switch (oem_addr[1]) {
+//                    case CC_SYS_INFO_READ_ONLY_PARAM:
+//                        pSetSysInfoRes->CompletionCode = CC_SYS_INFO_READ_ONLY_PARAM;
+//                        break;
+//                    default:
+//                        pSetSysInfoRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
+//                    }
+//                }
+//                else
+//                {
+//                    pSetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
+//                    return sizeof(pSetSysInfoRes->CompletionCode);
+//                }
+//            }
+//    }
+//    return sizeof(pSetSysInfoRes->CompletionCode);
+//}
+
+#endif  /* APP_DEVICE */

+ 417 - 0
app/bmc/msghndlr/App/AppDevice/WDT.c

@@ -0,0 +1,417 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * WDT.c
+ * WadtchDog TimeOut function
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+
+#include "WDT.h"
+#include "com_IPMIDefs.h"
+#include "ChassisDevice.h"
+#include <stdio.h>
+
+
+/*** Local macro definitions ***/
+#define PRE_TIMEOUT             1
+#define WDT_TIMEOUT             2
+#define PRETIMEOUT_ACTION_TAKEN 0x08
+
+#define TIMEOUT_NO_ACTION_TAKEN         0x00
+#define TIMEOUT_ACTION_HARD_RESET       0x01
+#define TIMEOUT_ACTION_POWER_DOWN       0x02
+#define TIMEOUT_ACTION_POWER_CYCLE      0x03
+
+#define PRE_TIMEOUT_SMI                 0x10
+#define PRE_TIMEOUT_NMI_DIAG            0x20
+#define PRE_TIMEOUT_MESSAGING_INTR      0x30
+
+/*** Global variables **/
+ WDTTmrMgr_T   g_WDTTmrMgr;
+
+/*----------------------------------------------------------------
+ * WatchDog2 Event Offsets
+ *---------------------------------------------------------------*/
+#define IPMI_WDT_TIMER_EXPIRED			0x00   //Watch Dog Expired Status only offset 
+#define IPMI_WDT_HARD_RESET				0x01
+#define IPMI_WDT_POWER_DOWN				0x02
+#define IPMI_WDT_POWER_CYCLE			0x03
+#define IPMI_WDT_TIMER_INTERRUPT		0x08
+
+#define MAX_WDT_MS_VALUE(Hertz)     (0xFFFFFFFF * 1000)/Hertz
+
+/*** Function Prototypes ***/
+//static void WDTTmrAction (uint8_t TmrAction, int BMCInst);
+
+/* Declare Thread Mutex */
+//OS_THREAD_MUTEX_DECLARE(hWDTSharedMemMutex);
+
+
+/**
+ * WDTTimerTask
+ **/
+void WDTTimerTask (void *pArg)
+{
+//    int *inst = (int*) pArg;
+//    int BMCInst = *inst;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+//    uint32_t WDTInterval = 0,WDTPreInterval = 0,jiffycmp = 0;
+//    long long jiffyvalue=0,jiffystart = 0;
+//    unsigned long Hertz = sysconf(_SC_CLK_TCK);
+//    prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
+
+//    /* Get the Shared memory mutex handle */
+//    OS_THREAD_MUTEX_INIT(pBMCInfo->hWDTSharedMemMutex, PTHREAD_MUTEX_RECURSIVE);
+
+//    while(TRUE)
+//    {
+//        /* Will be waiting till the Watchdog timer is armed*/
+//        sem_wait(&pBMCInfo->WDTSem);
+
+//        /* If no timer to process return */
+//        if (FALSE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent)
+//        {
+//            continue;
+//        }
+
+//        WDTInterval = pBMCInfo->WDTConfig.InitCountDown * WDT_COUNT_MS;
+//        if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
+//        {
+//            WDTPreInterval = WDTInterval+1;
+//        }
+//        else
+//        {
+//            WDTPreInterval = 1000 * pBMCInfo->WDTConfig.PreTimeOutInterval;
+//        }
+
+//        if(GetJiffySysCtlvalue(JIFFY_VALUE,&jiffyvalue) == 1)
+//        {
+//            IPMI_ERROR("Error in getting Jiffy value \n");
+//            return 0;
+//        }
+
+//        jiffystart = jiffyvalue;
+
+//        while(1)
+//        {
+
+//            if(GetJiffySysCtlvalue(JIFFY_VALUE,&jiffyvalue) == 1)
+//            {
+//                IPMI_ERROR("Error in getting Jiffy value \n");
+//                return 0;
+//            }
+
+//            if (pBMCInfo->HostOFFStopWDT == TRUE)
+//            {
+//                pBMCInfo->HostOFFStopWDT = FALSE;			
+//                break;
+//            }
+
+//            if(pBMCInfo->SetWDTUpdated == TRUE && (TRUE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent))
+//            {
+//                jiffystart = jiffyvalue;
+//                WDTInterval = pBMCInfo->WDTConfig.InitCountDown * WDT_COUNT_MS;
+//                if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
+//                {
+//                    WDTPreInterval = WDTInterval+1;
+//                    
+//                }
+//                else
+//                {
+//                    WDTPreInterval = 1000 * pBMCInfo->WDTConfig.PreTimeOutInterval;
+//                }
+//                pBMCInfo->SetWDTUpdated = FALSE;
+//            }
+//            else if(pBMCInfo->SetWDTUpdated == TRUE && (FALSE== BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent))
+//            {
+//                /* Restore Initial countdown value */
+//                g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown;
+//                break;
+//            }
+
+//            if(jiffyvalue < jiffystart)
+//            {
+//                /* To handle Jiffy Overflow condition */
+//                jiffycmp = (MAX_WDT_MS_VALUE(Hertz) -jiffystart) + jiffyvalue;
+//            }
+//            else
+//            {
+//                jiffycmp = jiffyvalue - jiffystart;
+//            }
+
+//            if((jiffycmp > WDTInterval) ||(jiffycmp > (WDTInterval-WDTPreInterval)))
+//            {
+//                if((jiffycmp > (WDTInterval-WDTPreInterval)) && (pBMCInfo->WDTPreTmtStat == FALSE)
+//                    && ((pBMCInfo->WDTConfig.TmrActions & 0x70) != 0))
+//                {
+//                    /* take pretimeout actions */
+//                    if(pBMCInfo->TriggerEvent.WDTTimeExpire)
+//                    {
+//                        if(0 == send_signal_by_name("Adviserd",SIGUSR2))
+//                        {
+//                             TDBG("Signal Sent successfully to adviser to start recording video\n");
+//                        }
+//                        else
+//                        {
+//                             TDBG("Cannot Send Signal to adviser to start recording video\n");
+//                        }
+//                    }
+//                    WDTTmrAction (g_WDTTmrMgr.WDTTmr.TmrActions & 0x70, BMCInst);
+//                    pBMCInfo->WDTPreTmtStat = TRUE;
+//                }
+//                else if(jiffycmp > WDTInterval)
+//                {
+//                    g_WDTTmrMgr.TmrPresent = FALSE;
+//                    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->hWDTSharedMemMutex, WAIT_INFINITE)
+//                    BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=FALSE;
+//                    BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
+//                    // Modify ARP status to resume the thread
+//                    // after receiving set Watchdog Timer command
+//                    //BMC_GET_SHARED_MEM(BMCInst)->GratArpStatus = RESUME_ARPS;
+//                    
+//                    uint8_t i = 0;
+
+//                    for (i = 0; i < MAX_LAN_CHANNELS; i++)
+//                    {
+//                        if((pBMCInfo->LanIfcConfig[i].Enabled == TRUE)
+//                            && (pBMCInfo->LanIfcConfig[i].Up_Status == LAN_IFC_UP))
+//                        {
+//                            BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[i] = RESUME_ARPS;
+//                            UpdateArpStatus(pBMCInfo->LanIfcConfig[i].Ethindex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);
+//                        }
+//                    }
+//                    
+//                    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->hWDTSharedMemMutex);
+//                    /* Take WDT timeout Actions */
+//                    pBMCInfo->WDTPreTmtStat = FALSE;
+//                    g_WDTTmrMgr.TmrInterval = 0;
+//                    if(pBMCInfo->TriggerEvent.WDTTimeExpire)
+//                    {
+//                        if(0 == send_signal_by_name("Adviserd",SIGUSR2))
+//                        {
+//                            TDBG("Signal Sent successfully to adviser to start recording video\n");
+//                        }
+//                        else
+//                        {
+//                            TDBG("Cannot Send Signal to adviser to start recording video\n");
+//                        }
+//                    }
+//                    WDTTmrAction (g_WDTTmrMgr.WDTTmr.TmrActions & 0x07, BMCInst);
+//                    break;
+//                 }
+//                
+//            }
+
+//            if((jiffycmp -WDTInterval) > 20)
+//            {
+//                /* Made to sleep for 100ms to reduce CPU Usage */
+//                usleep(WDT_SLEEP_TIME);
+//                g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown - (jiffycmp/WDT_COUNT_MS);
+//            }
+//        }
+//    }
+
+}
+
+///**
+// * @brief Takes action depending on the argument.
+// * @param TmrAction Timeout action.
+// **/
+//static void
+//WDTTmrAction (uint8_t TmrAction, int BMCInst)
+//{
+//	log("WDTTmrAction not implement\r\n");
+//    int i = 0;
+//    uint8_t  u8EventOffset;
+//    uint8_t  readFlags = 0;
+//     BMCInfo_t* pBMCInfo = &g_BMCInfo;
+//     SensorInfo_T*        pSensorInfo;    
+//    SensorSharedMem_T*    pSMSharedMem;
+
+//    if(IsCardInFlashMode()){    	
+//    	return;
+//    }
+//    
+//    if (TmrAction & 0x70)
+//    {
+//        pBMCInfo->WDTConfig.PreTimeoutActionTaken = g_WDTTmrMgr.WDTTmr.PreTimeoutActionTaken = PRETIMEOUT_ACTION_TAKEN;
+//        if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
+//        {
+//            SET_SMS_ATN (0, BMCInst);
+//            if(g_corefeatures.kcs_obf_bit == ENABLED)
+//            {
+//                SET_OBF (0, BMCInst);
+//            }
+//        }
+
+//        if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
+//        {
+//            SET_SMS_ATN (1, BMCInst);
+//            if(g_corefeatures.kcs_obf_bit == ENABLED)
+//            {
+//                SET_OBF (1, BMCInst);
+//            }
+//        }
+
+//        if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
+//        {
+//            SET_SMS_ATN (2, BMCInst);
+//            if(g_corefeatures.kcs_obf_bit == ENABLED)
+//            {
+//                SET_OBF (2, BMCInst);
+//            }
+//        }
+//    }
+//    else
+//    {
+//        pBMCInfo->WDTConfig.ExpirationFlag |=  0x1 << (pBMCInfo->WDTConfig.TmrUse & 0x07);
+
+//        // Based on the IPMI spec 27.7, the WDT expiration flag should not be preserved on any AC cycle.
+//        // update the WDT expiration flag in the global memory pool, not persistant in the flash
+//        g_WDTTmrMgr.WDTTmr.ExpirationFlag |=  0x1 << (pBMCInfo->WDTConfig.TmrUse & 0x07);
+//    }
+//    // setup sensor event offset
+//    u8EventOffset = TmrAction;
+
+//    if(g_corefeatures.wdt_flush_support == ENABLED )
+//    {
+//        FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
+//                       sizeof(WDTConfig_T),BMCInst);
+//    }
+
+//    if(g_PDKHandle[PDK_BEFOREWATCHDOGACTION] != NULL)
+//    {
+//        if( (((int(*)(uint8_t,WDTTmrMgr_T*,int))g_PDKHandle[PDK_BEFOREWATCHDOGACTION]) (TmrAction, &g_WDTTmrMgr,BMCInst)) != 0)
+//        {
+//            return;
+//        }
+//    }
+//    else
+//    {
+//    	if (g_PDKHandle[PDK_PREWATCHDOGACTION] != NULL)
+//	{
+//        	if( (((int(*)(uint8_t*, WDTTmrMgr_T*, int))g_PDKHandle[PDK_PREWATCHDOGACTION]) (&TmrAction, &g_WDTTmrMgr,BMCInst)) != 0)
+//        	{
+//            		return;
+//        	}
+//    	}
+//    }
+
+//    switch (TmrAction)
+//    {
+//        case TIMEOUT_NO_ACTION_TAKEN:
+//            break;
+
+//        case TIMEOUT_ACTION_HARD_RESET:
+//            //Added for GetSystem RestartCause //
+//            pBMCInfo->ChassisConfig.SysRestartCause = RESTART_CAUSE_WDT_EXPIRATION;
+//            //API_OnSetRestartCause(RESTART_CAUSE_WDT_EXPIRATION, TRUE);
+//            OnSetRestartCause(pBMCInfo->ChassisConfig.SysRestartCause, TRUE,BMCInst);
+
+//            // perform the chassis control action
+//            Platform_HostColdReset (BMCInst);
+//            break;
+
+//        case TIMEOUT_ACTION_POWER_DOWN:
+//            //Added for GetSystem RestartCause //
+//            pBMCInfo->ChassisConfig.SysRestartCause = RESTART_CAUSE_WDT_EXPIRATION;
+//            //API_OnSetRestartCause(RESTART_CAUSE_WDT_EXPIRATION, TRUE);
+//            OnSetRestartCause(pBMCInfo->ChassisConfig.SysRestartCause, TRUE,BMCInst);
+
+//            // perform the chassis control action
+//            Platform_HostPowerOff (BMCInst);
+//            break;
+
+//        case TIMEOUT_ACTION_POWER_CYCLE:
+//            //Added for GetSystem RestartCause //
+//            pBMCInfo->ChassisConfig.SysRestartCause = RESTART_CAUSE_WDT_EXPIRATION;
+//            //API_OnSetRestartCause(RESTART_CAUSE_WDT_EXPIRATION, TRUE);
+//            OnSetRestartCause(pBMCInfo->ChassisConfig.SysRestartCause, TRUE,BMCInst);
+
+//            // perform the chassis control action
+//            Platform_HostPowerCycle (BMCInst);
+//            break;
+
+//        case PRE_TIMEOUT_NMI_DIAG:
+//            // perform the NMI
+//            Platform_HostDiagInt (BMCInst);
+
+//            // fall through
+
+//        case PRE_TIMEOUT_SMI:
+//        case PRE_TIMEOUT_MESSAGING_INTR:
+//            // setup sensor event offset to be the timer interrupt (08h)
+//            u8EventOffset = IPMI_WDT_TIMER_INTERRUPT;				
+//            break;
+//        default:
+//            IPMI_ERROR("Invalid Timer Action for watchdog.\n");
+//            break;
+//    }
+//    // save the system restart cause even if there is no change
+//    FlushIPMI((uint8_t*)&pBMCInfo->ChassisConfig,(uint8_t*)&pBMCInfo->ChassisConfig,pBMCInfo->IPMIConfLoc.ChassisConfigAddr,sizeof(ChassisConfig_T),BMCInst);
+//    // pass the WDT event offset
+//    if(g_corefeatures.internal_sensor == ENABLED)
+//    {
+//        SetWD2SensorReading((1 << u8EventOffset), g_WDTTmrMgr.WDTTmr.TmrUse,g_WDTTmrMgr.WDTTmr.TmrActions,BMCInst);
+//	
+//	/* Get the Sensor Shared Memory */
+//	pSMSharedMem = ( SensorSharedMem_T*)&pBMCInfo->SensorSharedMem;
+//	for (i = 0; i < pBMCInfo->SenConfig.ValidSensorCnt; i++)
+//	{	
+//	    /* When the SensorType is WatchDog, calling WD2EventLog here to create EventLog instead through SensorMonitor */    
+//	    if(pSMSharedMem->SensorInfo[pBMCInfo->SenConfig.ValidSensorList [i]].SensorTypeCode == SENSOR_TYPE_WATCHDOG2)
+//	    {
+//		pSensorInfo = (SensorInfo_T*)&pSMSharedMem->SensorInfo[pBMCInfo->SenConfig.ValidSensorList [i]];
+//		WD2EventLog(pSensorInfo,&readFlags,BMCInst);
+//	    }
+//	}
+//    }
+
+//    if(g_PDKHandle[PDK_WATCHDOGACTION] != NULL)
+//    {
+//        ((void(*)(uint8_t,WDTTmrMgr_T*,int))g_PDKHandle[PDK_WATCHDOGACTION]) (TmrAction,&g_WDTTmrMgr,BMCInst);
+//    }
+
+//    /* Clearing don't log bit after Watchdog timeout */
+//    g_WDTTmrMgr.WDTTmr.TmrUse &= 0x7F;
+
+//}
+
+
+/*-----------------------------------------------------------------
+ * @fn StopWDTTimer
+ *
+ * @brief This is provided to stop Watchdog Timer.
+ *
+ * @return None.
+ *-----------------------------------------------------------------*/
+void
+StopWDTTimer ()
+{
+	printf("StopWDTTimer not implement\r\n");
+//    BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
+
+//    g_WDTTmrMgr.TmrPresent = FALSE;
+//    OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->hWDTSharedMemMutex, WAIT_INFINITE);
+//    BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning = FALSE;
+//    BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent = FALSE;
+//    OS_THREAD_MUTEX_RELEASE(&pBMCInfo->hWDTSharedMemMutex);
+}
+

+ 304 - 0
app/bmc/msghndlr/App/IPMDevice/Firewall.c

@@ -0,0 +1,304 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * Firewall.c
+ * Firewall Commands Handler
+ *
+ * Author: Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+
+#include "Firewall.h"
+#include "MsgHndlrTask.h"
+#include "Support.h"
+#include "com_IPMIDefs.h"
+#include "com_IPMI_Firewall.h"
+
+/* Reserved bit macro definitions */
+#define RESERVED_BITS_GETNETFNSUP                       0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
+
+#define RESERVED_BITS_GETCMDSUP_CH                      0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
+#define RESERVED_BITS_GETCMDSUP_LUN                     0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+#define RESERVED_BITS_GETCMDSUP_NETFUN					0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)
+
+#define RESERVED_BITS_GETSUBFNSUP_CH                    0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
+#define RESERVED_BITS_GETSUBFNSUP_NETFN                 0xC0 //(BIT7 | BIT6)
+#define RESERVED_BITS_GETSUBFNSUP_LUN                   0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+
+#define RESERVED_BITS_GETCFGCMDS_CH                     0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
+#define RESERVED_BITS_GETCFGCMDS_LUN                    0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+#define RESERVED_BITS_GETCFGCMDS_NETFUN					0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)
+
+#define RESERVED_BITS_GETCFGSUBFNS_CH                   0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
+#define RESERVED_BITS_GETCFGSUBFNS_NETFN                0xC0 //(BIT7 | BIT6)
+#define RESERVED_BITS_GETCFGSUBFNS_LUN                  0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+
+#define RESERVED_BITS_SETCMDEN_CH                       0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
+#define RESERVED_BITS_SETCMDEN_LUN                      0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+#define RESERVED_BITS_SETCMDEN_NETFUN                	0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)
+
+#define RESERVED_BITS_GETCMDEN_CH                       0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
+#define RESERVED_BITS_GETCMDEN_LUN                      0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+#define RESERVED_BITS_GETCMDEN_NETFUN                	0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)
+
+#define RESERVED_BITS_SETSUBFNEN_CH                     0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
+#define RESERVED_BITS_SETSUBFNEN_NETFN                  0xC0 //(BIT7 | BIT6)
+#define RESERVED_BITS_SETSUBFNEN_LUN                    0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+
+#define RESERVED_BITS_GETSUBFNEN_CH                     0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
+#define RESERVED_BITS_GETSUBFNEN_NETFN                  0xC0 //(BIT7 | BIT6)
+#define RESERVED_BITS_GETSUBFNEN_LUN                    0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
+
+#define RESERVED_BITS_GETOEMNETFNIANASUPPORT_CH         0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
+#define RESERVED_BITS_GETOEMNETFNIANASUPPORT_NETFN      0xC0 //(BIT7 | BIT6)
+#define RESERVED_BITS_GETOEMNETFNIANASUPPORT_LISTINDEX  0xC0 //(BIT7 | BIT6)
+#if IPM_DEVICE == 1
+
+//static int GetRequiredLength (uint8_t NetFn, uint8_t CmdReqSize);
+//static int ValidateFFNetFnData (uint8_t NetFn, NetFnParams_T* pNetFnParams ,BMCInfo_t *pBMCInfo);
+/*** Local Macro definitions ***/
+#define LUN_NO_CMD_SUPPORT          0x00
+#define LUN_NO_RESTRICTION_SUPPORT  0x01
+#define LUN_RESTRICTION_SUPPORT     0x02
+
+#define LUN_00                      LUN_RESTRICTION_SUPPORT
+#define LUN_01                      LUN_NO_CMD_SUPPORT << 2
+#define LUN_10                      LUN_NO_CMD_SUPPORT << 4
+#define LUN_11                      LUN_NO_CMD_SUPPORT << 6
+
+#define DMTF_DEFINING_BODY    0x01
+
+//Group Extension codes
+#define GROUPEXTNCODE_PICMG     0x00
+#define GROUPEXTNCODE_DMTF      0x01
+#define GROUPEXTNCODE_SSI       0x02
+#define GROUPEXTNCODE_VSO       0x03
+#define GROUPEXTNCODE_DCMI      0xDC
+#define Max_GROUPEXTNCODE        5
+
+
+/* Add IANA No's to the Array */
+IANA_T m_IANAList[] = {			/* LS byte first */
+   {{0xFF,0xFF,0xFF}}, /* Reserved Oem IANA */
+#ifdef IANA_OEM_LIST
+   IANA_OEM_LIST
+#endif   
+};
+uint8_t GroupExtnCode[Max_GROUPEXTNCODE]={
+    GROUPEXTNCODE_PICMG,
+    GROUPEXTNCODE_DMTF,
+    GROUPEXTNCODE_SSI,
+    GROUPEXTNCODE_VSO,
+    GROUPEXTNCODE_DCMI,
+    };
+
+
+#if GET_NETFN_SUP != UNIMPLEMENTED
+/*---------------------------------------
+ * GetNetFnSup
+ *---------------------------------------*/
+int
+GetNetFnSup ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    printf("GetNetFnSup not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* GET_NETFN_SUP != UNIMPLEMENTED */
+
+
+#if GET_CMD_SUP != UNIMPLEMENTED
+/*---------------------------------------
+ * GetCmdSup
+ *---------------------------------------*/
+int
+GetCmdSup ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+   printf("GetCmdSup not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* GET_CMD_SUP != UNIMPLEMENTED */
+
+
+#if GET_SUBFN_SUP != UNIMPLEMENTED
+/*---------------------------------------
+ * GetSubFnSup
+ *---------------------------------------*/
+int
+GetSubFnSup ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     printf("GetSubFnSup not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* GET_SUBFN_SUP != UNIMPLEMENTED */
+
+
+#if GET_CONFIG_CMDS != UNIMPLEMENTED
+/*---------------------------------------
+ * GetConfigCmds
+ *---------------------------------------*/
+int
+GetConfigCmds ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     printf("GetConfigCmds not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* GET_CONFIG_CMDS != UNIMPLEMENTED */
+
+
+#if GET_CONFIG_SUB_FNS != UNIMPLEMENTED
+/*---------------------------------------
+ * GetConfigSubFns
+ *---------------------------------------*/
+int
+GetConfigSubFns ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	printf("GetConfigSubFns not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* GET_CONFIG_SUB_FNS != UNIMPLEMENTED */
+
+
+#if SET_CMD_ENABLES != UNIMPLEMENTED
+/*---------------------------------------
+ * SetCmdEnables
+ *---------------------------------------*/
+int
+SetCmdEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     printf("SetCmdEnables not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* SET_CMD_ENABLES != UNIMPLEMENTED */
+
+
+#if GET_CMD_ENABLES != UNIMPLEMENTED
+/*---------------------------------------
+ * GetCmdEnables
+ *---------------------------------------*/
+int
+GetCmdEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    printf("GetCmdEnables not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* GET_CMD_ENABLES != UNIMPLEMENTED */
+
+
+#if SET_SUBFN_ENABLES != UNIMPLEMENTED
+/*---------------------------------------
+ * SetSubFnEnables
+ *---------------------------------------*/
+int
+SetSubFnEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     printf("SetSubFnEnables not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+#endif  /* SET_SUBFN_ENABLES != UNIMPLEMENTED */
+
+
+#if GET_SUBFN_ENABLES != UNIMPLEMENTED
+/*---------------------------------------
+ * GetSubFnEnables
+ *---------------------------------------*/
+int
+GetSubFnEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     printf("GetSubFnEnables not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+
+#endif  /* GET_SUBFN_ENABLES != UNIMPLEMENTED */
+
+#if GET_OEM_NETFN_IANA_SUPPORT != UNIMPLEMENTED
+/*---------------------------------------
+ * GetOEMNetFnIANASupport
+ *---------------------------------------*/
+int
+GetOEMNetFnIANASupport ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     printf("GetOEMNetFnIANASupport not implement\r\n");
+        *pRes = CC_INV_CMD;
+        return sizeof(*pRes);
+}
+
+#endif	//GET_OEM_NETFN_IANA_SUPPORT != UNIMPLEMENTED
+
+//static int GetRequiredLength(uint8_t NetFn, uint8_t CmdReqSize)
+//{
+//    uint8_t    RequiredLength;
+
+//    switch (NetFn)
+//    {
+//        case NETFN_OEM:
+//            RequiredLength = CmdReqSize;
+//            break;
+//        case NETFN_AMI:
+//            RequiredLength = CmdReqSize - sizeof(NetFnParams_T) + 1;
+//            break;
+//        case NETFN_PICMG:
+//            RequiredLength = CmdReqSize - sizeof(NetFnParams_T) + 1;
+//            break;
+//        default:
+//            RequiredLength = CmdReqSize - sizeof(NetFnParams_T);
+//            break;
+//    }
+
+//    return RequiredLength;
+//}
+
+//static int ValidateFFNetFnData (uint8_t NetFn, NetFnParams_T* pNetFnParams , BMCInfo_t *pBMCInfo)
+//{
+//    uint8_t i;
+//    
+//    // If NetFn is 0x2C, check for Defining Body code
+//    if (NETFN_PICMG == NetFn )
+//    {
+//        for (i = 0; i < sizeof (pBMCInfo->GroupExtnMsgHndlrTbl) / sizeof (pBMCInfo->GroupExtnMsgHndlrTbl [0]); i++)
+//        {
+//            if (pBMCInfo->GroupExtnMsgHndlrTbl [i].NetFn == NetFn) 
+//                return (pBMCInfo->GroupExtnMsgHndlrTbl [i].GroupExtnCode != pNetFnParams->DefBodyCode);
+//        }
+//    }
+//    else if (NETFN_OEM == NetFn) 	// If NetFn is 0x2E, check for OEM IANA
+//    {
+//        for (i=0; i <(sizeof(m_IANAList)/ sizeof(m_IANAList[0])); i++)
+//        {
+//            if (0 == _fmemcmp( pNetFnParams->IANA, m_IANAList[i].IANA, sizeof(IANA_T)))
+//            {
+//                break;
+//            }
+//        }
+
+//        if (i >= (sizeof(m_IANAList)/ sizeof(m_IANAList[0])))
+//        {
+//            // Given IANA in Req is not matching any of the IANA in the IANA list
+//            return  1;
+//        }
+//    }
+//    return 0;
+//}
+
+#endif  /* IPM_DEVICE */

+ 53 - 0
app/bmc/msghndlr/App/IPMDevice/Firewall.h

@@ -0,0 +1,53 @@
+/*****************************************************************
+ *****************************************************************
+ ***                                                            **
+ ***    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ ***                                                            **
+ ***            All Rights Reserved.                            **
+ ***                                                            **
+ ***        6145-F, Northbelt Parkway, Norcross,                **
+ ***                                                            **
+ ***        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ ***                                                            **
+ *****************************************************************
+ ******************************************************************
+ * 
+ * Firewall.h
+ * IPMI firmware firewall commands
+ *
+ *  Author: Ravinder Reddy <bakkar@ami.com>
+ *          Basavaraj Astekar <basavaraja@ami.com>
+ *          
+ ******************************************************************/
+#ifndef FIREWALL_H
+#define FIREWALL_H
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+
+#pragma pack(1)
+typedef struct{
+  uint8_t IANA[3];
+} IANA_T;
+#pragma pack()
+/*** Function Prototypes ***/
+
+// /**
+//  * @defgroup apcf5 Firmware Firewall Commands
+//  * @ingroup apcf
+//  * IPMI IPM Device Command Handlers. Invoked by the message handler
+//  * (IPMI 2.0 feature)
+//  * @{
+//  **/
+// extern int GetNetFnSup      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetCmdSup        ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetSubFnSup      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetConfigCmds    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetConfigSubFns  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int SetCmdEnables    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetCmdEnables    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int SetSubFnEnables  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetSubFnEnables  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// extern int GetOEMNetFnIANASupport  ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+// /** @} */
+
+#endif /* FIREWALL_H */

+ 222 - 0
app/bmc/msghndlr/App/IPMDevice/IPMDevice.c

@@ -0,0 +1,222 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+*****************************************************************
+ *
+ * IPMdevice.c
+ * IPMDevice Commands Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com>
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ *
+ *****************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+#include "IPMDevice.h"
+#include "MsgHndlr.h"
+#include "Support.h"
+#include "com_IPMIDefs.h"
+#include "com_IPMI_IPM.h"
+#include "Sensor.h"
+#include "main.h"
+#include "WDT.h"
+//#include "IPMIDef.h"
+#include "ChassisTimerTask.h"
+#include "com_IPMI_App.h"
+
+
+#if IPM_DEVICE == 1
+
+/*** Local macro definitions ***/
+#define ACPI_SET_SYS_PWR_STATE          0x80
+#define ACPI_SET_DEV_PWR_STATE          0x80
+#define ACPI_SYS_PWR_STATE_MASK         0x7F
+#define ACPI_DEV_PWR_STATE_MASK         0x7F
+#define ACPI_MAX_SYS_PWR_STATE			16
+#define ACPI_MAX_DEV_PWR_STATE			7
+#define ACPI_FLAG_SET					1
+#define ACPI_FLAG_UNSET					0
+
+
+/*** Global Variables ***/
+
+extern  WDTTmrMgr_T   g_WDTTmrMgr;
+
+
+
+//To get the data across the processes added in Shared memory structure in SharedMem.h
+// uint8_t     g_ACPISysPwrState;
+// uint8_t     g_ACPIDevPwrState;
+
+/*** Module Variables ***/
+
+#define WORKING_STATE 0x0
+#define S1_SLEEPING_STATE  0x1
+
+//notice
+static uint8_t  MfgID[]       = {0x12,0x34,0x56};//     /**< Contains Manufacturer ID */
+static uint16_t g_ProdID      = 0xaabb;
+
+
+static void GetFirmwareVersion(unsigned int* Major,unsigned int* Minor,unsigned int* Rev)
+{
+	*Major = g_BMCInfo.FwMajorVer;
+	*Minor = g_BMCInfo.FwMinorVer;
+	*Rev	= 0;
+}
+
+/*---------------------------------------
+ * GetDevID
+ *---------------------------------------*/
+int
+GetDevID ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     GetDevIDRes_T*  pGetDevIDRes = ( GetDevIDRes_T*) pRes;
+    static unsigned int Major,Minor,Rev;
+    static unsigned char MinorBCD;
+    static int firsttime = 1;
+
+    if(firsttime == 1)
+    {
+        //	printf("Calling get firmware version only for first time\n");
+        GetFirmwareVersion(&Major,&Minor,&Rev);
+        MinorBCD = ((Minor/10)<<4)+(Minor%10);
+        firsttime = 0;
+    }
+
+    pGetDevIDRes->CompletionCode      = CC_NORMAL;
+    pGetDevIDRes->DeviceID            = DEVICE_ID;
+    pGetDevIDRes->DevRevision         = IPMI_DEV_REVISION;
+    pGetDevIDRes->FirmwareRevision1   = Major ;
+    pGetDevIDRes->FirmwareRevision2   = MinorBCD;  //DO NOT CHANGE THIS ASSIGNMENT. INSTEAD SET THE VALUE OF THE VARIABLE Minor IN THE FIRSTTIME LOOP
+    pGetDevIDRes->IPMIVersion         = IPMI_VERSION;
+    pGetDevIDRes->DevSupport          = DEV_SUPPORT;
+    pGetDevIDRes->ProdID              =  (g_ProdID);
+    pGetDevIDRes->AuxFirmwareRevision = Rev;
+    memcpy (pGetDevIDRes->MfgID, MfgID, sizeof (MfgID));
+
+    return sizeof (GetDevIDRes_T);
+}
+
+
+/*---------------------------------------
+ * ColdReset
+ *---------------------------------------*/
+int
+ColdReset ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	MsgPkt_T MsgPkt;
+	MsgPkt.Param = PARAM_MC;
+	MsgPkt.NetFnLUN = NETFN_APP<<2; 
+	MsgPkt.Cmd = CMD_COLD_RESET;
+	
+	PostMsg(gPendActionIfc, &MsgPkt);
+    *pRes = CC_NORMAL;
+    return sizeof (*pRes);
+}
+
+
+/*---------------------------------------
+ * WarmReset
+ *---------------------------------------*/
+int
+WarmReset ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	MsgPkt_T MsgPkt;
+	MsgPkt.Param = PARAM_MC;
+	MsgPkt.NetFnLUN = NETFN_APP<<2; 
+	MsgPkt.Cmd = CMD_WARM_RESET;
+	
+	PostMsg(gPendActionIfc, &MsgPkt);
+	*pRes = CC_NORMAL;
+	return sizeof (*pRes);
+}
+
+
+/*---------------------------------------
+ * GetSelfTestResults
+ *---------------------------------------*/
+int
+GetSelfTestResults ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+     GetSelfTestRes_T*  pGetSelfTest = ( GetSelfTestRes_T*) pRes;
+
+    pGetSelfTest->CompletionCode  = CC_NORMAL;
+    pGetSelfTest->TestResultByte1 = ( 0 == g_BMCInfo.SelfTestByte ) ?
+                                     GST_NO_ERROR: GST_CORRUPTED_DEVICES;
+    pGetSelfTest->TestResultByte2 = g_BMCInfo.SelfTestByte;
+
+    return sizeof (GetSelfTestRes_T);
+}
+
+
+/*---------------------------------------
+ * MfgTestOn
+ *---------------------------------------*/
+int
+MfgTestOn ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+	printf("MfgTestOn not implement\r\n");
+
+    *pRes = CC_NORMAL;
+    return sizeof (*pRes);
+}
+
+
+/*---------------------------------------
+ * SetACPIPwrState
+ *---------------------------------------*/
+int
+SetACPIPwrState ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    printf("SetACPIPwrState not implement\r\n");
+
+    *pRes = CC_NORMAL;
+    return sizeof (*pRes);
+}
+
+
+/*---------------------------------------
+ * GetACPIPwrState
+ *---------------------------------------*/
+int
+GetACPIPwrState ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    GetACPIPwrStateRes_T*  pGetACPIRes = ( GetACPIPwrStateRes_T*) pRes;
+
+	printf("GetACPIPwrState not implement\r\n");
+    pGetACPIRes->CompletionCode  = CC_NORMAL;
+    pGetACPIRes->ACPISysPwrState = 0;//BMC_GET_SHARED_MEM (BMCInst)-> m_ACPISysPwrState;
+    pGetACPIRes->ACPIDevPwrState = 0;//BMC_GET_SHARED_MEM (BMCInst)->m_ACPIDevPwrState;
+  
+    return sizeof (GetACPIPwrStateRes_T);
+}
+
+
+/*---------------------------------------
+ * GetDevGUID
+ *---------------------------------------*/
+int
+GetDevGUID ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
+{
+    GetDevGUIDRes_T*  pGetDevGUIDRes = ( GetDevGUIDRes_T*) pRes;
+
+    pGetDevGUIDRes->CompletionCode  = CC_NORMAL;
+    memcpy (pGetDevGUIDRes->Node, g_BMCInfo.DeviceGUID, 16);
+  
+    return sizeof (GetDevGUIDRes_T);
+}
+
+#endif  /* IPM_DEVICE */

+ 72 - 0
app/bmc/msghndlr/App/IPMDevice/IPMDevice.h

@@ -0,0 +1,72 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ *****************************************************************
+ *
+ * IPMDevice.h
+ * IPMDevice Commands Handler
+ *
+ * Author: Govind Kothandapani <govindk@ami.com> 
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ * 
+ *****************************************************************/
+#ifndef IPMDEVICE_H
+#define IPMDEVICE_H
+#include "com_BmcType.h"
+
+/*** Extern Declaration ***/
+
+
+
+
+/**
+ * @var _FAR_ uint8_t g_ACPISysPwrState
+ * @brief Contains System ACPI state.
+ * @warning Should not be accessed from task other than Message Handler
+ **/
+
+ /*Commented it inorder to access the data across the processes and moved it to the
+ shared memory structure BMCSharedMem_T in SharedMem.h file*/
+
+//extern _FAR_ uint8_t      g_ACPISysPwrState;
+
+/**
+ * @var _FAR_ uint8_t g_ACPIDevPwrState
+ * @brief Contains Device ACPI state.
+ * @warning Should not be accessed from task other than Message Handler
+ **/
+
+ /*Commented it inorder to access the data across the processes and moved it to the
+ shared memory structure BMCSharedMem_T in SharedMem.h file*/
+
+//	extern _FAR_ uint8_t      g_ACPIDevPwrState;
+
+/*** Function Prototypes ***/
+/**
+ * @defgroup apcf1 IPM Device Commands
+ * @ingroup apcf
+ * IPMI IPM Device Command Handlers. Invoked by the message handler
+ * @{
+ **/
+extern int GetDevID             ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int ColdReset            ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int WarmReset            ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int GetSelfTestResults   ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int MfgTestOn            ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int SetACPIPwrState      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int GetACPIPwrState      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+extern int GetDevGUID           ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
+/** @} */
+
+#endif  /* IPMDEVICE_H */

+ 77 - 0
app/bmc/msghndlr/App/WDT.h

@@ -0,0 +1,77 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+ ****************************************************************/
+/*****************************************************************
+ *
+ * WDT.h
+ * 
+ * 
+ * Author: Govind Kothandapani <govindk@ami.com> 
+ *       : Rama Bisa <ramab@ami.com>
+ *       : Basavaraj Astekar <basavaraja@ami.com>
+ *       : Bakka Ravinder Reddy <bakkar@ami.com>
+ * 
+ *****************************************************************/
+#ifndef WDTMGR_H
+#define WDTMGR_H
+
+#include "com_BmcType.h"
+#include "com_IPMIDefs.h"
+#include "PMConfig.h"
+
+#pragma pack( 1 )
+
+/*** Type definitions ***/
+// Resume ARP Thread 
+#define RESUME_ARPS     0x00 
+#define WDT_SLEEP_TIME 	100000
+#define WDT_COUNT_MS 	100
+#define SEC_TO_MS 		1000
+
+/**
+ * @struct  WDTTmrMgr_T
+ * @brief   Watchdog Timer table
+**/
+typedef struct
+{
+    uint8_t       TmrPresent;         /**< Flag to indicate timer is present or not */
+    uint16_t      TmrInterval;        /**< Timer interval */
+    uint16_t      PreTimeOutInterval; /**< Pre Timeout interval */
+    WDTConfig_T   WDTTmr;             /**< Watchdog timer configurations */
+
+}   WDTTmrMgr_T;
+
+#pragma pack( )
+
+/**
+ * @var  WDTTmrMgr_T g_WDTTmrMgr
+ * @brief   Watchdog Timer table
+ * @warning Should not be used from task other than Message Handler
+**/
+extern  WDTTmrMgr_T g_WDTTmrMgr;
+
+/**
+ * @brief Watchdog timer task invoked every second from timer task
+ **/
+extern void WDTTimerTask (void*Arg);
+
+ /*-----------------------------------------------------------------
+ * @fn StopWDTTimer
+ *
+ * @brief This is provided to stop Watchdog Timer.
+ *
+ * @return None.
+ *-----------------------------------------------------------------*/
+extern void StopWDTTimer (void);
+
+#endif /* WDTMGR_H */

+ 73 - 0
app/bmc/msghndlr/Bridge/Bridge.c

@@ -0,0 +1,73 @@
+/****************************************************************
+ ****************************************************************
+ **                                                            **
+ **    (C)Copyright 2005-2006, American Megatrends Inc.        **
+ **                                                            **
+ **            All Rights Reserved.                            **
+ **                                                            **
+ **        6145-F, Northbelt Parkway, Norcross,                **
+ **                                                            **
+ **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
+ **                                                            **
+ ****************************************************************
+*****************************************************************
+ *
+ * Bridge.c
+ * Bridge Command Handler
+ *
+ * Author: Gowtham.M.S <gowthamms@amiindia.co.in>
+ *
+ *****************************************************************/
+#define UNIMPLEMENTED_AS_FUNC
+//#include "Support.h"
+//#include "Bridge.h"
+//#include "BridgeMgmt.h"
+//#include "Bridging.h"
+//#include "BridgeDiscovery.h"
+//#include "BridgeEvt.h"
+//#include "Storlead_BMC_LIb.h"
+#include "Support.h"
+#include "MsgHndlr.h"
+/**
+ * @brief Bridge Command Handler Map.
+**/
+const CmdHndlrMap_T g_Bridge_CmdHndlr [] =
+{
+#if BRIDGE_DEVICE == 1
+/*----------------------- Bridge Management Commands --------------------------------*/
+    { CMD_GET_BRIDGE_STATE,     PRIV_USER,      GET_BRIDGE_STATE,       0x00,   0xAAAA  ,0xFFFF},
+    { CMD_SET_BRIDGE_STATE,     PRIV_OPERATOR,  SET_BRIDGE_STATE,       sizeof(SetBridgeStateReq_T),    0xAAAA  ,0xFFFF},
+    { CMD_GET_ICMB_ADDR,        PRIV_USER,      GET_ICMB_ADDR,          0x00,   0xAAAA  ,0xFFFF},
+    { CMD_SET_ICMB_ADDR,        PRIV_OPERATOR,  SET_ICMB_ADDR,          sizeof(SetICMBAddrReq_T),   0xAAAA  ,0xFFFF},
+    { CMD_SET_BRIDGE_PROXY_ADDR,PRIV_OPERATOR,  SET_BRIDGE_PROXY_ADDR,      0xff,   0xAAAA  ,0xFFFF}, //sizeof(SetBrProxyAddrReq_T)
+    { CMD_GET_BRIDGE_STATISTICS,PRIV_USER,      GET_BRIDGE_STATISTICS,      sizeof(GetBrStatisticsReq_T),   0xAAAA  ,0xFFFF},
+    { CMD_GET_ICMB_CAPABILITIES,PRIV_USER,      GET_ICMB_CAPABILITIES,      0x00,   0xAAAA  ,0xFFFF},
+    { CMD_CLEAR_BRIDGE_STATISTICS,PRIV_OPERATOR,CLEAR_BRIDGE_STATISTICS,    0x00,   0xAAAA  ,0xFFFF},
+    { CMD_GET_BRIDGE_PROXY_ADDR,PRIV_USER,      GET_BRIDGE_PROXY_ADDR,      0x00,   0xAAAA  ,0xFFFF},
+    { CMD_GET_ICMB_CONNECTOR_INFO,PRIV_USER,    GET_ICMB_CONNECTOR_INFO,    sizeof(GetICMBConnInfoReq_T),   0xAAAA  ,0xFFFF},
+    { CMD_GET_ICMB_CONNECTION_ID,PRIV_USER,     GET_ICMB_CONNECTION_ID,     0xff,   0xAAAA  ,0xFFFF},
+    { CMD_SEND_ICMB_CONNECTION_ID,PRIV_USER,    SEND_ICMB_CONNECTION_ID,    0x00,   0xAAAA  ,0xFFFF},
+
+/*---------------------- Bridge Discovery Commands -----------------------------------*/
+    { CMD_PREPARE_FOR_DISCOVERY,  PRIV_OPERATOR, PREPARE_FOR_DISCOVERY, 0x00,   0xAAAA  ,0xFFFF},
+    { CMD_GET_ADDRESSES,          PRIV_USER,     GET_ADDRESSES,         0x00,   0xAAAA  ,0xFFFF},
+    { CMD_SET_DISCOVERED,         PRIV_OPERATOR, SET_DISCOVERED,        0x00,   0xAAAA  ,0xFFFF},
+    { CMD_GET_CHASSIS_DEVICE_ID,  PRIV_USER,     GET_CHASSIS_DEVICE_ID, 0x00,   0xAAAA  ,0xFFFF},
+    { CMD_SET_CHASSIS_DEVICE_ID,  PRIV_OPERATOR, SET_CHASSIS_DEVICE_ID, sizeof(INT8U),  0xAAAA  ,0xFFFF},
+
+/*----------------------- Bridging Commands ------------------------------------------*/
+    { CMD_BRIDGE_REQUEST,       PRIV_OPERATOR,  BRIDGE_REQUEST,         0xff,   0xAAAA  ,0xFFFF},
+    { CMD_BRIDGE_MESSAGE,       PRIV_OPERATOR,  BRIDGE_MESSAGE,         0xff,   0xAAAA  ,0xFFFF},
+
+/*---------------------- Bridge Event Commands ---------------------------------------*/
+    { CMD_GET_EVENT_COUNT,          PRIV_USER,      GET_EVENT_COUNT,            0x00,   0xAAAA  ,0xFFFF},
+    { CMD_SET_EVENT_DESTINATION,    PRIV_OPERATOR,  SET_EVENT_DESTINATION,      sizeof(SetEvtDestReq_T),    0xAAAA  ,0xFFFF},
+    { CMD_SET_EVENT_RECEPTION_STATE,PRIV_OPERATOR,  SET_EVENT_RECEPTION_STATE,  sizeof(SetEvtRecpStateReq_T),   0xAAAA  ,0xFFFF},
+    { CMD_SEND_ICMB_EVENT_MESSAGE,  PRIV_OPERATOR,  SEND_ICMB_EVENT_MESSAGE,    0xff,   0xAAAA  ,0xFFFF}, //sizeof(SendICMBEvtMsgReq_T)
+    { CMD_GET_EVENT_DESTINATION,    PRIV_USER,      GET_EVENT_DESTINATION,      0x00,   0xAAAA  ,0xFFFF},
+    { CMD_GET_EVENT_RECEPTION_STATE,PRIV_USER,      GET_EVENT_RECEPTION_STATE,  0x00,   0xAAAA  ,0xFFFF},
+#endif  /*BRIDGE_DEVICE*/
+
+    { 0x00,                     0x00,           0x00,                 0x00, 0x0000           ,0x0000}   
+};
+

+ 20 - 0
app/bmc/msghndlr/Bridge/Bridge.h

@@ -0,0 +1,20 @@
+/*
+* Brief:	The header file of MsgHndlr_Bridge packet.
+* Author:	Jimbo_Zhang@outlook.com
+* Date:		2019-9-16
+*/
+
+#ifndef __MSG_HNDLR_BRIDGE_H__
+#define __MSG_HNDLR_BRIDGE_H__
+
+#include "com_BmcType.h"
+#include "MsgHndlr.h"
+
+
+/**
+ * @var g_Bridge_CmdHndlr
+ * @brief Bridge Command Hanlder Map.
+**/
+extern const CmdHndlrMap_T  g_Bridge_CmdHndlr [];
+
+#endif /* __MSG_HNDLR_BRIDGE_H__ */

Some files were not shown because too many files changed in this diff