AppDevice.c 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631
  1. /****************************************************************
  2. ****************************************************************
  3. ** **
  4. ** (C)Copyright 2005-2006, American Megatrends Inc. **
  5. ** **
  6. ** All Rights Reserved. **
  7. ** **
  8. ** 6145-F, Northbelt Parkway, Norcross, **
  9. ** **
  10. ** Georgia - 30071, USA. Phone-(770)-246-8600. **
  11. ** **
  12. ****************************************************************
  13. ****************************************************************/
  14. /*****************************************************************
  15. *
  16. * AppDevice.c
  17. * AppDevice Commands Handler
  18. *
  19. * Author: Govind Kothandapani <govindk@ami.com>
  20. * : Rama Bisa <ramab@ami.com>
  21. * : Basavaraj Astekar <basavaraja@ami.com>
  22. * : Bakka Ravinder Reddy <bakkar@ami.com>
  23. *
  24. *****************************************************************/
  25. #include "com_BmcType.h"
  26. #include "Support.h"
  27. #include "com_IPMIDefs.h"
  28. #include "com_IPMI_IPM.h"
  29. #include "com_IPMI_AppDevice.h"
  30. #include "AppDevice.h"
  31. #include "RMCP.h"
  32. #include "Session.h"
  33. #include "PMConfig.h"
  34. #include "main.h"
  35. #include <string.h>
  36. #define USER_ID_ENABLED 0x01
  37. #define USER_ID_DISABLED 0x02
  38. #define OP_USERID_ONLY_LENGTH 2
  39. #define OP_ENABLE_USER_ID 1
  40. #define OP_DISABLE_USER_ID 0
  41. #define BIT3_BIT0_MASK 0xf
  42. #define GET_AUTH_TYPE_MASK 0xc0
  43. #define AUTH_TYPE_V15 0x0
  44. #define AUTH_TYPE_V20 0x40
  45. #define AUTH_CODE_V15_MASK 0x0f
  46. #define AUTH_CODE_V15_1 0x1
  47. #define AUTH_CODE_V15_2 0x2
  48. #define AUTH_CODE_V15_3 0x5
  49. #define AUTH_CODE_V20_MASK 0x3f
  50. #define MIN_AUTH_CODE_V20 0x04
  51. #define MAX_AUTH_CODE_V20 0xc0
  52. #define NULL_USER 1
  53. #define ZERO_SETSELECTOR 0x00
  54. #define MAX_TYPE_OF_ENCODING 0x02
  55. #define MAX_STRING_LENGTH_COPY 14
  56. #define ASCII_LATIN1 0x00
  57. #define UTF_8 0x01
  58. #define UNICODE 0x02
  59. /* Reserved bit macro definitions */
  60. #define RESERVED_BITS_SENDMS 0x03 //(BIT1 | BIT0)
  61. /* Auth code length */
  62. #define HMAC_SHA1_96_LEN 12
  63. #if APP_DEVICE == 1
  64. #define COUNT_INCREASE 1
  65. #define COUNT_DECREASE -1
  66. #define MAX_BT_PKT_LEN 255
  67. /*macro definitions for set user password options*/
  68. #define DISABLE_USER 0
  69. #define ENABLE_USER 1
  70. #define SET_PASSWORD 2
  71. #define TEST_PASSWORD 3
  72. #define MAX_LAN_CHANNELS 1
  73. #define LAN_RMCP_CHANNEL1_TYPE 0x01
  74. #define LAN_RMCP_CHANNEL2_TYPE 0x02
  75. #define LAN_RMCP_CHANNEL3_TYPE 0x03
  76. /*** Global variables ***/
  77. uint8_t g_TmrRunning;
  78. /*** Module variables ***/
  79. static MsgPkt_T m_MsgPkt; /**< Message Packet for posting and retrieving messaged to/from queue */
  80. static uint8_t m_Set_ChReserveBit[] ={0xF0,0x0,0x30};
  81. //extern IfcName_T Ifcnametable[MAX_LAN_CHANNELS];
  82. //static void UpdateCurrentEnabledUserCount(int value, int bmcInstId)
  83. //{
  84. // if (value == 0) return;
  85. // ChannelInfo_T* pChannelInfo = NULL;
  86. // ChannelInfo_T* pNvrChannelInfo = NULL;
  87. // BMCInfo_t* pBMCInfo = &g_BMCInfo[bmcInstId];
  88. // uint8_t maxUserCount = pBMCInfo->IpmiConfig.MaxChUsers;
  89. // uint8_t channelIndex = 0;
  90. // for (channelIndex = 0; channelIndex < MAX_NUM_CHANNELS; channelIndex++)
  91. // {
  92. // if (pBMCInfo->ChConfig[channelIndex].ChType == 0xff) continue;
  93. // pChannelInfo = (ChannelInfo_T*)&pBMCInfo->ChConfig[channelIndex].ChannelInfo;
  94. // if (((value > 0) && ((pChannelInfo->NoCurrentUser + value) > maxUserCount)) ||
  95. // ((value < 0) && ((pChannelInfo->NoCurrentUser + value) < 0)))
  96. // {
  97. // continue;
  98. // }
  99. // pNvrChannelInfo = GetNVRChConfigs(pChannelInfo, bmcInstId);
  100. // pChannelInfo->NoCurrentUser+=value;
  101. // pNvrChannelInfo->NoCurrentUser+=value;
  102. // FlushChConfigs((uint8_t*)pNvrChannelInfo,pNvrChannelInfo->ChannelNumber,bmcInstId);
  103. //}
  104. //}
  105. //static int IsPrivilegeAvailable(uint8_t requestedPrivilege, uint8_t channelNumber, int bmcInstId)
  106. //{
  107. // // PMConfig_T* pPMConfig = ( PMConfig_T*) GetNVRAddr(NVRH_PMCONFIG, bmcInstId);
  108. // BMCInfo_t *pBMCInfo = &g_BMCInfo[bmcInstId];
  109. // uint8_t EthIndex = GetEthIndex(channelNumber & 0x0F, bmcInstId);
  110. // uint8_t privilege = 0x00;
  111. //
  112. // if(0xff == EthIndex) return -1;
  113. //
  114. // //Get requested privilege status (enabled or disabled) from PMConfig by channel
  115. // switch (requestedPrivilege)
  116. // {
  117. // case PRIV_CALLBACK:
  118. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeCallBack;
  119. // break;
  120. //
  121. // case PRIV_USER:
  122. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeUser;
  123. // break;
  124. //
  125. // case PRIV_OPERATOR:
  126. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeOperator;
  127. // break;
  128. //
  129. // case PRIV_ADMIN:
  130. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeAdmin;
  131. // break;
  132. //
  133. // case PRIV_OEM:
  134. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeOem;
  135. // break;
  136. //
  137. // default:
  138. // return -1;
  139. // }
  140. //
  141. // //All bits are 0 that means privilege level is disabled
  142. // return ((privilege != 0x00) ? 0 : -1);
  143. //}
  144. /*-------------------------------------
  145. * ValidateIPMBChksum1
  146. *-------------------------------------*/
  147. /* Function to validate IPMB Checksum1 for SendMessage Cmd */
  148. static int ValidateIPMBChksum1( uint8_t* Data)
  149. {
  150. int i=0;
  151. uint8_t chksum=0;
  152. for (i = 0; i < 3; i++)
  153. {
  154. chksum += *(Data + i);
  155. }
  156. if (chksum != 0)
  157. {
  158. return FALSE;
  159. }
  160. return TRUE;
  161. }
  162. ///*-------------------------------------
  163. //* ResetWDT
  164. //*-------------------------------------*/
  165. //int
  166. //ResetWDT ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  167. //{
  168. // uint8_t u8ExpirationFlag;
  169. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  170. // if (pBMCInfo->Msghndlr.TmrSet == FALSE)
  171. // {
  172. // *pRes = CC_ATTEMPT_TO_RESET_UNIN_WATCHDOG;
  173. // return sizeof (*pRes);
  174. // }
  175. // // save the WDT expiration flag for later use
  176. // u8ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
  177. // /* Reset of Watchdog should not happen once
  178. // once pretimeout interrupt interval is reached*/
  179. // if(pBMCInfo->WDTPreTmtStat == TRUE)
  180. // {
  181. // *pRes = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  182. // return sizeof (*pRes);
  183. // }
  184. // g_WDTTmrMgr.TmrPresent = TRUE;
  185. // g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown;
  186. // g_WDTTmrMgr.PreTimeOutInterval = SEC_TO_MS * pBMCInfo->WDTConfig.PreTimeOutInterval;
  187. // /* if the pre-timeout interrupt is not configured, adjust the pre-timeout interrupt
  188. // timeout value beyound the regular WDT timeout value so that it won't get triggered
  189. // before the WDT timeout. */
  190. // if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
  191. // {
  192. // g_WDTTmrMgr.PreTimeOutInterval = g_WDTTmrMgr.TmrInterval+ 1;
  193. // }
  194. // _fmemcpy (&g_WDTTmrMgr.WDTTmr, &pBMCInfo->WDTConfig, sizeof (WDTConfig_T));
  195. // // restore the WDT expiration flag, don't use the one from the flash
  196. // g_WDTTmrMgr.WDTTmr.ExpirationFlag = u8ExpirationFlag;
  197. // // clear WDT sensor event history
  198. // if( g_corefeatures.internal_sensor == ENABLED )
  199. // RestartWD2Sensor(BMCInst);
  200. // if(g_corefeatures.wdt_flush_support == ENABLED )
  201. // {
  202. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  203. // sizeof(WDTConfig_T),BMCInst);
  204. // }
  205. // if(BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent == FALSE)
  206. // {
  207. // LOCK_BMC_SHARED_MEM(BMCInst);
  208. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=TRUE;
  209. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent=TRUE;
  210. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  211. // sem_post(&g_BMCInfo[BMCInst].WDTSem);
  212. // }
  213. // else
  214. // {
  215. // LOCK_BMC_SHARED_MEM(BMCInst);
  216. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=TRUE;
  217. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent=TRUE;
  218. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  219. // //Set SetWDTUpdated flag to reload initial countdown value.
  220. // g_BMCInfo[BMCInst].SetWDTUpdated = TRUE;
  221. // }
  222. // *pRes = CC_NORMAL;
  223. // return sizeof (*pRes);
  224. //}
  225. ///*---------------------------------------
  226. //* SetWDT
  227. //*---------------------------------------*/
  228. //int
  229. //SetWDT ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  230. //{
  231. // SetWDTReq_T* pSetWDTReq = ( SetWDTReq_T*)pReq;
  232. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  233. // GetMsgFlagsRes_T GetMsgFlagsRes;
  234. //#endif
  235. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  236. // //Check for Reserved bits
  237. // if((pSetWDTReq->TmrUse & (BIT5 | BIT4 | BIT3)) || !(pSetWDTReq->TmrUse & (BIT2 | BIT1 | BIT0)) || ((pSetWDTReq->TmrUse & (BIT1 | BIT2)) == (BIT1 | BIT2)) ||
  238. // (pSetWDTReq->TmrActions & (BIT7 |BIT6 | BIT3 | BIT2)) || (pSetWDTReq->ExpirationFlag & (BIT7 | BIT6 | BIT0)))
  239. // {
  240. // *pRes = CC_INV_DATA_FIELD;
  241. // return sizeof(*pRes);
  242. // }
  243. //#if NO_WDT_PRETIMEOUT_INTERRUPT == 1
  244. // // do not support pre-timeout interrupt
  245. // if (pSetWDTReq->TmrActions & 0x70)
  246. // {
  247. // *pRes = CC_INV_DATA_FIELD;
  248. // return sizeof(*pRes);
  249. // }
  250. //#endif
  251. // pSetWDTReq->InitCountDown = htoipmi_u16(pSetWDTReq->InitCountDown);
  252. // // error out if the pre-timeout interrupt is greater than the initial countdown value
  253. // if (pSetWDTReq->InitCountDown < 10 * pSetWDTReq->PreTimeOutInterval)
  254. // {
  255. // *pRes = CC_INV_DATA_FIELD;
  256. // return sizeof(*pRes);
  257. // }
  258. // // only clear the memory version of the bit(s) when the input bit is set #31175
  259. // g_WDTTmrMgr.WDTTmr.ExpirationFlag &= ~pSetWDTReq->ExpirationFlag;
  260. // pSetWDTReq->ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
  261. // /* Copy the Timer configuration in NVRAM */
  262. // LOCK_BMC_SHARED_MEM(BMCInst);
  263. // _fmemset (( uint8_t*)&pBMCInfo->WDTConfig, 0, sizeof (WDTConfig_T));
  264. // _fmemcpy (( uint8_t*)&pBMCInfo->WDTConfig, ( uint8_t*)pSetWDTReq, sizeof (SetWDTReq_T));
  265. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  266. // if (TRUE ==BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning)
  267. // {
  268. // /* To check wheather Dont stop bit is set or not */
  269. // if (pSetWDTReq->TmrUse & 0x40)
  270. // {
  271. // /* Set the count down value to given value */
  272. // g_WDTTmrMgr.TmrPresent = TRUE;
  273. // LOCK_BMC_SHARED_MEM(BMCInst);
  274. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =TRUE;
  275. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  276. // g_WDTTmrMgr.TmrInterval= pSetWDTReq->InitCountDown;
  277. // g_WDTTmrMgr.PreTimeOutInterval = (SEC_TO_MS * pSetWDTReq->PreTimeOutInterval);
  278. // /* If PreTimeOutInt is set, clear it */
  279. // if (0 != (pSetWDTReq->TmrActions & 0x70))
  280. // {
  281. // pSetWDTReq->TmrActions &= ~0x70;
  282. // }
  283. // else
  284. // {
  285. // // if the pre-timeout interrupt is not configured, adjust the pre-timeout interrupt
  286. // // timeout value beyound the regular WDT timeout value so that it won't get triggered
  287. // // before the WDT timeout.
  288. // g_WDTTmrMgr.PreTimeOutInterval = pSetWDTReq->InitCountDown + 1;
  289. // }
  290. // _fmemcpy (&g_WDTTmrMgr.WDTTmr, pSetWDTReq, sizeof (WDTConfig_T ));
  291. // }
  292. // else
  293. // {
  294. // /* Stop the timer */
  295. // g_WDTTmrMgr.TmrPresent = FALSE;
  296. // LOCK_BMC_SHARED_MEM(BMCInst);
  297. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=FALSE;
  298. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
  299. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  300. // g_WDTTmrMgr.TmrInterval= pSetWDTReq->InitCountDown;
  301. // g_WDTTmrMgr.PreTimeOutInterval = SEC_TO_MS * pSetWDTReq->PreTimeOutInterval;
  302. // // clear WDT sensor event history
  303. // if( g_corefeatures.internal_sensor == ENABLED)
  304. // RestartWD2Sensor(BMCInst);
  305. // }
  306. // /* Clear the pre-timeout interupt flag */
  307. // LOCK_BMC_SHARED_MEM(BMCInst);
  308. // pBMCInfo->WDTConfig.PreTimeoutActionTaken = 0x00;
  309. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x08; /* Clear the flag */
  310. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  311. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  312. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  313. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  314. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  315. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  316. //#else
  317. // if((BMC_GET_SHARED_MEM(BMCInst)->MsgFlags & BIT3_BIT0_MASK) == 0)
  318. //#endif
  319. // {
  320. // /* Clear the SMS_ATN bit */
  321. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  322. // {
  323. // CLEAR_SMS_ATN (0, BMCInst);
  324. // }
  325. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  326. // {
  327. // CLEAR_SMS_ATN (1, BMCInst);
  328. // }
  329. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  330. // {
  331. // CLEAR_SMS_ATN (2, BMCInst);
  332. // }
  333. // }
  334. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  335. // }
  336. // else
  337. // {
  338. // g_WDTTmrMgr.TmrInterval = pSetWDTReq->InitCountDown;
  339. // g_WDTTmrMgr.TmrPresent = FALSE;
  340. // LOCK_BMC_SHARED_MEM(BMCInst);
  341. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
  342. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  343. // // clear WDT sensor event history
  344. // if( g_corefeatures.internal_sensor == ENABLED)
  345. // RestartWD2Sensor(BMCInst);
  346. // }
  347. // // Modify ARP status to resume the thread
  348. // // after receiving set Watchdog Timer command
  349. // //BMC_GET_SHARED_MEM(BMCInst)->GratArpStatus = RESUME_ARPS;
  350. //
  351. // int i = 0;
  352. // for (i = 0; i < MAX_LAN_CHANNELS; i++)
  353. // {
  354. // if((pBMCInfo->LanIfcConfig[i].Enabled == TRUE)
  355. // && (pBMCInfo->LanIfcConfig[i].Up_Status == LAN_IFC_UP))
  356. // {
  357. // BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[i] = RESUME_ARPS;
  358. // UpdateArpStatus(pBMCInfo->LanIfcConfig[i].Ethindex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);
  359. // }
  360. // }
  361. // if(g_corefeatures.wdt_flush_support == ENABLED )
  362. // {
  363. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  364. // sizeof(WDTConfig_T),BMCInst);
  365. // }
  366. // // set the "Don't Log" bit
  367. // g_WDTTmrMgr.WDTTmr.TmrUse &= 0x7F;
  368. // g_WDTTmrMgr.WDTTmr.TmrUse |= (pSetWDTReq->TmrUse & 0x80);
  369. // g_BMCInfo[BMCInst].SetWDTUpdated = TRUE;
  370. // g_BMCInfo[BMCInst].Msghndlr.TmrSet = TRUE;
  371. // pBMCInfo->WDTPreTmtStat = FALSE;
  372. // *pRes = CC_NORMAL;
  373. // return sizeof (*pRes);
  374. //}
  375. ///*---------------------------------------
  376. //* GetWDT
  377. //*---------------------------------------*/
  378. //int
  379. //GetWDT ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  380. //{
  381. // GetWDTRes_T* pGetWDTRes = ( GetWDTRes_T*)pRes;
  382. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  383. // /* Copy the current settings from the NVRAM */
  384. // LOCK_BMC_SHARED_MEM(BMCInst);
  385. // _fmemcpy (( uint8_t*)&pGetWDTRes->CurrentSettings,
  386. // ( uint8_t*)&pBMCInfo->WDTConfig, sizeof (WDTConfig_T));
  387. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  388. // // get the WDT expiration from the global veriable in memory, not from the flash
  389. // pGetWDTRes->CurrentSettings.ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
  390. // // get the current "Don't Log" bit
  391. // pGetWDTRes->CurrentSettings.TmrUse &= 0x7F;
  392. // pGetWDTRes->CurrentSettings.TmrUse |= (g_WDTTmrMgr.WDTTmr.TmrUse & 0x80);
  393. // if (TRUE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent)
  394. // {
  395. // // set the WDT running bit #30235/30467
  396. // pGetWDTRes->CurrentSettings.TmrUse |= 0x40;
  397. // /* Present count down in 1/100 of second */
  398. // }
  399. // else
  400. // {
  401. // // clear the WDT running bit #30235/30467 for Timer Use (ie) WatchDog Timer status
  402. // pGetWDTRes->CurrentSettings.TmrUse &= ~0x40;
  403. // pGetWDTRes->CurrentSettings.ExpirationFlag = (pGetWDTRes->CurrentSettings.ExpirationFlag) & 0x3E;
  404. // }
  405. // pGetWDTRes->PresentCountDown = g_WDTTmrMgr.TmrInterval;
  406. // pGetWDTRes->CurrentSettings.InitCountDown = htoipmi_u16(pGetWDTRes->CurrentSettings.InitCountDown);
  407. // pGetWDTRes->CompletionCode = CC_NORMAL;
  408. // return sizeof (GetWDTRes_T);
  409. //}
  410. ///*---------------------------------------
  411. //* SetBMCGlobalEnables
  412. //*---------------------------------------*/
  413. //int
  414. //SetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  415. //{
  416. // uint8_t GblEnblByte = *pReq;
  417. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  418. // MsgPkt_T MsgPkt;
  419. // _fmemset (&MsgPkt, 0, sizeof (MsgPkt_T));
  420. // /* Check For the reserved bit 4 */
  421. // if ( GblEnblByte & BIT4)
  422. // {
  423. // *pRes = CC_INV_DATA_FIELD;
  424. // return sizeof (*pRes);
  425. // }
  426. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  427. // if (((BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables ^ GblEnblByte)) & 0x20)
  428. // {
  429. // /* OEM 0 puts us in ICTS compatibility mode for IPMIv2,
  430. // * Send a message to lan process so it can change behavior
  431. // */
  432. // MsgPkt.Channel = GetLANChannel(0, BMCInst);
  433. // MsgPkt.Param = LAN_ICTS_MODE;
  434. // MsgPkt.Privilege = PRIV_LOCAL;
  435. // if (GblEnblByte & 0x20)
  436. // MsgPkt.Cmd = 1;
  437. // else
  438. // MsgPkt.Cmd = 0;
  439. // PostMsg(&MsgPkt,LAN_IFC_Q,BMCInst);
  440. // }
  441. // BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables = GblEnblByte;
  442. // *pRes = CC_NORMAL;
  443. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  444. // return sizeof (*pRes);
  445. //}
  446. ///*---------------------------------------
  447. //* GetBMCGlobalEnables
  448. //*---------------------------------------*/
  449. //int
  450. //GetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  451. //{
  452. // GetBMCGblEnblRes_T* pGetBMCGblEnblRes = ( GetBMCGblEnblRes_T*)pRes;
  453. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  454. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  455. // pGetBMCGblEnblRes->CompletionCode = CC_NORMAL;
  456. // pGetBMCGblEnblRes->BMCGblEnblByte = BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables;
  457. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  458. // return sizeof (GetBMCGblEnblRes_T);
  459. //}
  460. ///*---------------------------------------
  461. //* ClrMsgFlags
  462. //*---------------------------------------*/
  463. //int
  464. //ClrMsgFlags ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  465. //{
  466. // ClearMsgsFlagReq_T* pClearMsgsFlagReq = ( ClearMsgsFlagReq_T*)pReq;
  467. // uint8_t *kcsifcnum;
  468. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  469. // GetMsgFlagsRes_T GetMsgFlagsRes;
  470. //#endif
  471. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  472. // //Check for Reserved bits
  473. // if(pClearMsgsFlagReq->Flag & (BIT4 | BIT2))
  474. // {
  475. // *pRes = CC_INV_DATA_FIELD;
  476. // return sizeof(*pRes);
  477. // }
  478. // OS_THREAD_TLS_GET(g_tls.CurKCSIfcNum,kcsifcnum);
  479. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  480. // /* Flush Receive Message Queue */
  481. // if (0 != (pClearMsgsFlagReq->Flag & 0x01))
  482. // {
  483. // while (0 == GetMsg (&m_MsgPkt, &g_RcvMsgQ[*kcsifcnum][0], WAIT_NONE,BMCInst))
  484. // {
  485. // BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum]--;
  486. // }
  487. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x01; /* Clear the flag */
  488. // }
  489. // /* Flush Event Message Buffer */
  490. // if (0 != (pClearMsgsFlagReq->Flag & 0x02))
  491. // {
  492. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
  493. // while (0 == GetMsg (&m_MsgPkt, EVT_MSG_Q, WAIT_NONE,BMCInst))
  494. // {
  495. // BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg--;
  496. // }
  497. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  498. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x02; /* Clear the flag */
  499. // }
  500. // /* Clear WatchdogTimer Interrupt*/
  501. // if (0 != (pClearMsgsFlagReq->Flag & 0x08))
  502. // {
  503. // /* Clear the pre-timeout interupt flag */
  504. // pBMCInfo->WDTConfig.PreTimeoutActionTaken = 0x00;
  505. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x08; /* Clear the flag */
  506. // if(g_corefeatures.wdt_flush_support == ENABLED )
  507. // {
  508. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  509. // sizeof(WDTConfig_T),BMCInst);
  510. // }
  511. // }
  512. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  513. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  514. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  515. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  516. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  517. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  518. //#else
  519. // if((BMC_GET_SHARED_MEM(BMCInst)->MsgFlags & BIT3_BIT0_MASK) == 0)
  520. //#endif
  521. // {
  522. // /* Clear the SMS_ATN bit */
  523. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  524. // {
  525. // CLEAR_SMS_ATN (0, BMCInst);
  526. // }
  527. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  528. // {
  529. // CLEAR_SMS_ATN (1, BMCInst);
  530. // }
  531. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  532. // {
  533. // CLEAR_SMS_ATN (2, BMCInst);
  534. // }
  535. // }
  536. // *pRes = CC_NORMAL;
  537. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  538. // return sizeof (*pRes);
  539. //}
  540. // /*---------------------------------------
  541. // GetMsgFlags
  542. // ---------------------------------------*/
  543. // int
  544. // GetMsgFlags ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  545. // {
  546. // GetMsgFlagsRes_T* pGetMsgFlagsRes = ( GetMsgFlagsRes_T*)pRes;
  547. // uint8_t *kcsifcnum;
  548. // /* get the message flags */
  549. // pGetMsgFlagsRes->MsgFlags = BMC_GET_SHARED_MEM (BMCInst)->MsgFlags;
  550. // if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg >= EVT_MSG_BUF_SIZE)
  551. // {
  552. // /* If Event MessageBuffer is Full set the BIT */
  553. // pGetMsgFlagsRes->MsgFlags |= 0x02;
  554. // }
  555. // else
  556. // {
  557. // /* else reset the Flag */
  558. // pGetMsgFlagsRes->MsgFlags &= ~0x02;
  559. // }
  560. // if(kcsifcnum != NULL && 0 != BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum])
  561. // {
  562. // /* if any Message in ReceiveMsgQ set the Flag */
  563. // pGetMsgFlagsRes->MsgFlags |= 0x01;
  564. // }
  565. // else
  566. // {
  567. // /* else reset the Flag */
  568. // pGetMsgFlagsRes->MsgFlags &= ~0x01;
  569. // }
  570. // /* get the Pre-Timeout Bits Value & Set it to Response Data */
  571. // //PRETIMEOUT BIT is 3rd bit so changed accordingly
  572. // pGetMsgFlagsRes->MsgFlags |= (pBMCInfo->WDTConfig.PreTimeoutActionTaken & 0x08);
  573. // /* Update the Message flags in shared Mem */
  574. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags |= pGetMsgFlagsRes->MsgFlags;
  575. // pGetMsgFlagsRes->CompletionCode = CC_NORMAL;
  576. // return sizeof (GetMsgFlagsRes_T);
  577. // }
  578. ///*---------------------------------------
  579. //* EnblMsgChannelRcv
  580. //*---------------------------------------*/
  581. //int
  582. //EnblMsgChannelRcv ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  583. //{
  584. // EnblMsgChRcvReq_T* pEnblMsgChRcvReq = ( EnblMsgChRcvReq_T*)pReq;
  585. // EnblMsgChRcvRes_T* pEnblMsgChRcvRes = ( EnblMsgChRcvRes_T*)pRes;
  586. // ChannelInfo_T* pChannelInfo;
  587. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  588. // //Check for Reserved bits
  589. // if(pEnblMsgChRcvReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4))
  590. // {
  591. // pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
  592. // return sizeof(*pRes);
  593. // }
  594. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  595. // pChannelInfo = getChannelInfo (pEnblMsgChRcvReq->ChannelNum & 0x0F, BMCInst);
  596. // TDBG ("ENBL_MSG_CH_RCV: processing..\n");
  597. // if (NULL == pChannelInfo)
  598. // {
  599. // pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
  600. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  601. // return sizeof (*pRes);
  602. // }
  603. // switch (pEnblMsgChRcvReq->ChannelState)
  604. // {
  605. // case 0:
  606. // /* disable Receive Message Queue for this Channel */
  607. // pChannelInfo->ReceiveMsgQ = 0x0;
  608. // break;
  609. // case 1:
  610. // /*enable Recevive Message Queue for this Channel */
  611. // pChannelInfo->ReceiveMsgQ = 0x1;
  612. // break;
  613. // case 2:
  614. // /*get Channel State */
  615. // pEnblMsgChRcvRes->ChannelState = pChannelInfo->ReceiveMsgQ;
  616. // break;
  617. // default:
  618. // pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
  619. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  620. // return sizeof (*pRes);
  621. // }
  622. // pEnblMsgChRcvRes->CompletionCode = CC_NORMAL;
  623. // /*get Channel Number */
  624. // pEnblMsgChRcvRes->ChannelNum = pEnblMsgChRcvReq->ChannelNum & 0x0F;
  625. // pEnblMsgChRcvRes->ChannelState = pChannelInfo->ReceiveMsgQ;
  626. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  627. // return sizeof (EnblMsgChRcvRes_T);
  628. //}
  629. /*---------------------------------------
  630. * GetMessage
  631. *---------------------------------------*/
  632. int
  633. GetMessage ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  634. {
  635. GetMsgRes_T* pGetMsgRes = ( GetMsgRes_T*)pRes;
  636. uint8_t Index = 0,*kcsifcnum;
  637. #if GET_MSG_FLAGS != UNIMPLEMENTED
  638. GetMsgFlagsRes_T GetMsgFlagsRes;
  639. #endif
  640. printf("GetMessage!\n");
  641. // if (0 != GetMsg (&m_MsgPkt, &g_RcvMsgQ[*kcsifcnum][0], WAIT_NONE))
  642. // {
  643. // /* if Queue is Empty */
  644. // pGetMsgRes->CompletionCode = CC_GET_MSG_QUEUE_EMPTY;
  645. // return sizeof (*pRes);
  646. // }
  647. // #if GET_MSG_FLAGS != UNIMPLEMENTED
  648. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  649. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  650. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  651. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  652. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  653. // #else
  654. // if (0 == BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum])
  655. // #endif
  656. // {
  657. // /* Clear the SMS_ATN bit */
  658. // CLEAR_SMS_ATN (*kcsifcnum,BMCInst);
  659. // }
  660. // /* Completion Code */
  661. // pGetMsgRes->CompletionCode = CC_NORMAL;
  662. // /* Channel number and privilege level */
  663. // pGetMsgRes->ChannelNum = m_MsgPkt.Channel;
  664. // Index = sizeof (GetMsgRes_T);
  665. // /* First byte should be session handle */
  666. // if(pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)
  667. // {
  668. // if ((PRIMARY_IPMB_CHANNEL != m_MsgPkt.Channel) && (pBMCInfo->SecondaryIPMBCh != m_MsgPkt.Channel))
  669. // {
  670. // pGetMsgRes->ChannelNum |= m_MsgPkt.Privilege << 0x04;
  671. // pRes [Index++] = m_MsgPkt.Param;
  672. // }
  673. // }
  674. // else
  675. // {
  676. // if(PRIMARY_IPMB_CHANNEL != m_MsgPkt.Channel)
  677. // {
  678. // pGetMsgRes->ChannelNum |= m_MsgPkt.Privilege << 0x04;
  679. // pRes [Index++] = m_MsgPkt.Param;
  680. // }
  681. // }
  682. // /* copy the Message data */
  683. // _fmemcpy (( uint8_t*)&pRes[Index], &m_MsgPkt.Data[1], m_MsgPkt.Size-1);
  684. // IPMI_DBG_PRINT ("GetMsg: Sending the following data through requested channel\n");
  685. // IPMI_DBG_PRINT_BUF (pRes, m_MsgPkt.Size + Index);
  686. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  687. // return ((m_MsgPkt.Size-1)+ Index); /*+ 2 for completion code & channel No. */
  688. return 1;
  689. }
  690. /*---------------------------------------
  691. * SendMessage
  692. *---------------------------------------*/
  693. int
  694. SendMessage ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  695. {
  696. SendMsgReq_T* pSendMsgReq = ( SendMsgReq_T*)pReq;
  697. SendMsgRes_T* pSendMsgRes = ( SendMsgRes_T*)pRes;
  698. IPMIMsgHdr_T* pIPMIMsgHdr;
  699. int Queuefd = 0;
  700. uint8_t Tracking;
  701. uint8_t Channel=0,resaddr=0;
  702. uint8_t ResLen = 1;
  703. uint8_t RetVal = 0;
  704. uint8_t Offset = 1;
  705. uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
  706. uint8_t PBTbl = PRIMARY_PB_TBL;
  707. uint8_t SrcSessionHndl = 0;
  708. ChannelInfo_T* pChannelInfo;
  709. MsgPkt_T ResPkt;
  710. SessionInfo_T* pSessionInfo = NULL;
  711. uint32_t *CurSesID;
  712. uint8_t *curprivlevel,*curchannel,*kcsifcnum;
  713. *pRes = CC_NORMAL;
  714. if (ReqLen < 1)
  715. {
  716. *pRes = CC_REQ_INV_LEN;
  717. return sizeof (*pRes);
  718. }
  719. if(pSendMsgReq->ChNoTrackReq == 0xC0)
  720. {
  721. *pRes = CC_INV_DATA_FIELD;
  722. return sizeof (*pRes);
  723. }
  724. /* Get the channel number */
  725. Channel = pSendMsgReq->ChNoTrackReq & 0x0F;
  726. /* Get Tracking field */
  727. Tracking = pSendMsgReq->ChNoTrackReq >> 6;
  728. if (Tracking == RESERVED_BITS_SENDMS)
  729. {
  730. *pRes = CC_INV_DATA_FIELD;
  731. return sizeof (*pRes);
  732. }
  733. CurSesID = pthread_getspecific(g_tls.CurSessionID);
  734. curchannel = pthread_getspecific(g_tls.CurChannel);
  735. kcsifcnum = pthread_getspecific(g_tls.CurKCSIfcNum);
  736. m_MsgPkt.Param = BRIDGING_REQUEST;
  737. m_MsgPkt.Channel = Channel;
  738. m_MsgPkt.Size = ReqLen - 1; /* -1 to skip channel num */
  739. /* Copy the message data */
  740. memcpy (m_MsgPkt.Data, &pReq[1], m_MsgPkt.Size);
  741. /* Copy the IPMI Message header */
  742. pIPMIMsgHdr = ( IPMIMsgHdr_T*)&m_MsgPkt.Data[Offset - 1];
  743. if(ValidateIPMBChksum1(( uint8_t*)pIPMIMsgHdr) == FALSE)
  744. {
  745. *pRes = CC_INV_DATA_FIELD;
  746. printf("Invalid checksum1\n");
  747. return sizeof (*pRes);
  748. }
  749. if(m_MsgPkt.Data[ReqLen - 2] != CalculateCheckSum2 (( uint8_t*)pIPMIMsgHdr, ReqLen - Offset - 1))
  750. {
  751. *pRes = CC_INV_DATA_FIELD;
  752. return sizeof (*pRes);
  753. }
  754. #if 0
  755. int z;
  756. printf("m_MsgPkt: ");
  757. for(z = 0; z < m_MsgPkt.Size;z++)
  758. printf("%02x ", m_MsgPkt.Data[z]);
  759. printf("\n");
  760. #endif
  761. // printf("---> curchannel: %d, Channel: %d\n", *curchannel, Channel);
  762. if((Channel == PRIMARY_IPMB_CHANNEL) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1)
  763. {
  764. //printf ("SendMsg: To Primary IPMB Interface\n");
  765. m_MsgPkt.SrcQ = gFd_PrimaryIpmbIfcQ;
  766. }
  767. else if(( Channel == SECONDARY_IPMB_CHANNEL) && (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 1))
  768. {
  769. //printf ("SendMsg: To Secondary IPMB Interface\n");
  770. m_MsgPkt.SrcQ = gFd_SecondaryIpmbIfcQ;
  771. }
  772. else
  773. {
  774. printf ("SendMsg: Invalid Channel\n");
  775. *pRes = CC_DEST_UNAVAILABLE;
  776. return sizeof (*pRes);
  777. }
  778. if (1 == Tracking)
  779. {
  780. ResLen = 0;
  781. //printf("---> Tracking, curchannel %d, ", *curchannel);
  782. /* Tracking is not required if originator is System ifc */
  783. if (SYS_IFC_CHANNEL == (*curchannel & 0xF))
  784. {
  785. *pRes = CC_INV_DATA_FIELD;
  786. return sizeof (*pRes);
  787. }
  788. if(*curchannel == LAN_RMCP_CHANNEL)
  789. {
  790. pSessionInfo = getSessionInfo (SESSION_ID_INFO, CurSesID);
  791. //printf("SendMEssage/CurSesID %#x, SessionHandle %#x\n", *CurSesID, pSessionInfo->SessionHandle);
  792. if (NULL != pSessionInfo)
  793. {
  794. g_BMCInfo.SessionHandle = pSessionInfo->SessionHandle;
  795. }
  796. else
  797. {
  798. printf("Error: Not get valid session!\n");
  799. *pRes = CC_UNSPECIFIED_ERR;
  800. return sizeof(*pRes);
  801. }
  802. }
  803. PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
  804. //printf("PBTbl %d, g_BMCInfo.SendMsgSeqNum %d, ", PBTbl, g_BMCInfo.SendMsgSeqNum);
  805. /* Store in the table for response tracking */
  806. while(TRUE)
  807. {
  808. if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
  809. {
  810. m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = g_BMCInfo.IpmiConfig.SendMsgTimeout;
  811. m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = (*curchannel & 0xF);
  812. m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc = ORIGIN_SENDMSG;
  813. g_BMCInfo.SendMsgSeqNum = SeqNum;
  814. if (1 != Offset)
  815. {
  816. //TODO:这个貌似没用到?
  817. m_PendingBridgedResTbl[PBTbl][SeqNum].DstSessionHandle = pReq[Offset]; /* Session handle */
  818. }
  819. m_PendingBridgedResTbl[PBTbl][SeqNum].SrcSessionHandle = pSessionInfo->SessionHandle;// SrcSessionHndl;
  820. memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pIPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  821. /* Format the IPMI Msg Hdr */
  822. if(Channel == PRIMARY_IPMB_CHANNEL)
  823. {
  824. pIPMIMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr;
  825. }
  826. else if(Channel == SECONDARY_IPMB_CHANNEL)
  827. {
  828. pIPMIMsgHdr->ReqAddr = g_BMCInfo.SecondaryIPMBAddr;
  829. }
  830. else
  831. {
  832. printf("Invalid channel %d\n", Channel);//pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  833. }
  834. pIPMIMsgHdr->RqSeqLUN = (g_BMCInfo.SendMsgSeqNum << 2) & 0xFC; /* Seq Num and LUN =00 */
  835. /* Recalculate the checksum */
  836. m_MsgPkt.Data[ReqLen - 2] = CalculateCheckSum2 (( uint8_t*)pIPMIMsgHdr, ReqLen - Offset - 1);
  837. if((*curchannel & 0xF) == LAN_RMCP_CHANNEL)
  838. {
  839. m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFd_LanIfcQ;
  840. }
  841. else if((*curchannel & 0xF) == UDS_CHANNEL)
  842. {
  843. m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFdUdsIfc;
  844. }
  845. else
  846. {
  847. printf("Not support channel! %d\n", *curchannel);
  848. *pRes = CC_PARAM_OUT_OF_RANGE;
  849. return 1;
  850. }
  851. m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
  852. m_PendingBridgedResTbl[PBTbl][SeqNum].SeqNum = SeqNum;
  853. m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 0;
  854. //printf( "SendMessage SeqNum %d, ", SeqNum);
  855. //memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
  856. break;
  857. }
  858. else
  859. {
  860. SeqNum = (SeqNum + 1) & 0x3F;
  861. if (SeqNum == g_BMCInfo.SendMsgSeqNum) //转了一圈,没有空闲的SeqNum可用。
  862. {
  863. /* If not been added to the Pending Bridge table, an error should be reported back.
  864. If not, for internal channel, the thread calling it may end up waiting! */
  865. *pRes = CC_NODE_BUSY;
  866. return sizeof (*pRes);
  867. }
  868. }
  869. }
  870. }
  871. else
  872. {
  873. pSendMsgRes->CompletionCode = 0xff;
  874. return 1;
  875. }
  876. // printf ("SendMsgCmd:Posting to interface ");
  877. // int y;
  878. // for(y=0;y<m_MsgPkt.Size;y++)
  879. // printf("%#x ", m_MsgPkt.Data[y]);
  880. // printf("\n");
  881. m_MsgPkt.Cmd = PAYLOAD_IPMI_MSG;
  882. /* Post the message to interface */
  883. if (0 != PostMsg (m_MsgPkt.SrcQ, &m_MsgPkt))
  884. {
  885. printf ("Warning: SendMsg Failed to post message to interface queue\n");
  886. }
  887. pSendMsgRes->CompletionCode = CC_NORMAL;
  888. return ResLen;
  889. }
  890. ///*---------------------------------------
  891. //* ReadEvtMsgBuffer
  892. //*---------------------------------------*/
  893. //int
  894. //ReadEvtMsgBuffer ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  895. //{
  896. // ReadEvtMsgBufRes_T* pReadEvtMsgBufRes = ( ReadEvtMsgBufRes_T*)pRes;
  897. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  898. // GetMsgFlagsRes_T GetMsgFlagsRes;
  899. //#endif
  900. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  901. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  902. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
  903. // if (-2 == GetMsg(&m_MsgPkt, EVT_MSG_Q, WAIT_NONE, BMCInst))
  904. // {
  905. // /*If queue is empty */
  906. // pReadEvtMsgBufRes->CompletionCode = CC_EVT_MSG_QUEUE_EMPTY;/* Queue is empty */
  907. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  908. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  909. // return sizeof (*pRes);
  910. // }
  911. // if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg == 0)
  912. // {
  913. // pReadEvtMsgBufRes->CompletionCode = CC_EVT_MSG_QUEUE_EMPTY;
  914. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  915. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  916. // return sizeof (*pRes);
  917. // }
  918. // BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg--;
  919. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  920. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  921. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  922. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  923. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  924. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  925. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  926. //#else
  927. // if (0 == BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg)
  928. //#endif
  929. // {
  930. // /* if there is no messssage in buffer reset SMS/EVT ATN bit */
  931. // // CLEAR_SMS_ATN ();
  932. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  933. // {
  934. // CLEAR_SMS_ATN (0, BMCInst);
  935. // }
  936. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  937. // {
  938. // CLEAR_SMS_ATN (1, BMCInst);
  939. // }
  940. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  941. // {
  942. // CLEAR_SMS_ATN (2, BMCInst);
  943. // }
  944. // }
  945. // /* clear EventMessageBuffer full flag */
  946. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x02;
  947. // pReadEvtMsgBufRes->CompletionCode = CC_NORMAL; /* Completion Code */
  948. // /* copy the Message data */
  949. // _fmemcpy (pReadEvtMsgBufRes->ResData, m_MsgPkt.Data, m_MsgPkt.Size);
  950. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  951. // return sizeof (ReadEvtMsgBufRes_T);
  952. //}
  953. ///*---------------------------------------
  954. //* GetBTIfcCap
  955. //*---------------------------------------*/
  956. //int
  957. //GetBTIfcCap ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  958. //{
  959. // GetBTIfcCapRes_T* pGetBTIfcCapRes = ( GetBTIfcCapRes_T*)pRes;
  960. // pGetBTIfcCapRes->CompletionCode = CC_NORMAL;
  961. // pGetBTIfcCapRes->NumReqSupported = 2;
  962. // pGetBTIfcCapRes->InputBufSize = MAX_BT_PKT_LEN;
  963. // pGetBTIfcCapRes->OutputBufSize = MAX_BT_PKT_LEN;
  964. // pGetBTIfcCapRes->RespTime = 1;
  965. // pGetBTIfcCapRes->Retries = 0;
  966. // return sizeof (GetBTIfcCapRes_T);
  967. //}
  968. ///*---------------------------------------
  969. //* GetSystemGUID
  970. //*---------------------------------------*/
  971. //int
  972. //GetSystemGUID ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  973. //{
  974. // GetSysGUIDRes_T* pGetSysGUIDRes = ( GetSysGUIDRes_T*)pRes;
  975. // pGetSysGUIDRes->CompletionCode = CC_NORMAL;
  976. // LOCK_BMC_SHARED_MEM (BMCInst);
  977. // _fmemcpy (&pGetSysGUIDRes->Node, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
  978. // UNLOCK_BMC_SHARED_MEM (BMCInst);
  979. // return sizeof (GetSysGUIDRes_T);
  980. //}
  981. #define SUPPORT_IPMI20 0x02
  982. #define SUPPORT_IPMI15 0x01
  983. /*---------------------------------------
  984. * GetChAuthCap
  985. *---------------------------------------*/
  986. int
  987. GetChAuthCap ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  988. {
  989. //TODO: dummy data
  990. // GetChAuthCapReq_T* pGetChAuthCapReq = ( GetChAuthCapReq_T*)pReq;
  991. GetChAuthCapRes_T* pGetChAuthCapRes = ( GetChAuthCapRes_T*)pRes;
  992. pGetChAuthCapRes->CompletionCode = CC_NORMAL;
  993. pGetChAuthCapRes->ChannelNum = LAN_RMCP_CHANNEL;
  994. pGetChAuthCapRes->AuthType = 0x36;
  995. pGetChAuthCapRes->PerMsgUserAuthLoginStatus = 0x04;
  996. pGetChAuthCapRes->ExtCap = 0;
  997. pGetChAuthCapRes->OEMID[0] = 0;
  998. pGetChAuthCapRes->OEMID[1] = 0;
  999. pGetChAuthCapRes->OEMID[2] = 0;
  1000. pGetChAuthCapRes->OEMAuxData = 0;
  1001. return sizeof (GetChAuthCapRes_T);
  1002. }
  1003. /*---------------------------------------
  1004. * GetSessionChallenge
  1005. * Create session in this function
  1006. *---------------------------------------*/
  1007. int
  1008. GetSessionChallenge ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1009. {
  1010. GetSesChallengeReq_T* pGetSesChalReq = ( GetSesChallengeReq_T*)pReq;
  1011. GetSesChallengeRes_T* pGetSesChalRes = ( GetSesChallengeRes_T*)pRes;
  1012. uint8_t Index;
  1013. uint8_t ChallengeString[CHALLENGE_STR_LEN];
  1014. UserInfo_T *pUserInfo;
  1015. uint32_t TempSessId;
  1016. SessionInfo_T SessionInfo;
  1017. uint8_t *curchannel;
  1018. uint32_t TempRandom;
  1019. if(pGetSesChalReq->UserName[0] == 0)
  1020. {
  1021. pGetSesChalRes->CompletionCode = 0x82;
  1022. return sizeof (*pRes);
  1023. }
  1024. g_BMCInfo.pUserInfo = NULL;
  1025. pUserInfo = getUserNameInfo(pGetSesChalReq->UserName);
  1026. if((pUserInfo == NULL) || (TRUE != pUserInfo->UserStatus))
  1027. {
  1028. pGetSesChalRes->CompletionCode = 0x81;
  1029. return sizeof (*pRes);
  1030. }
  1031. curchannel = pthread_getspecific(g_tls.CurChannel);
  1032. do
  1033. {
  1034. /*generate 32 bit temp session Id*/
  1035. TempSessId = stm32_generate_random32bit();
  1036. } while ((NULL != getSessionInfo (SESSION_ID_INFO, &TempSessId)) || (0 == TempSessId));
  1037. SessionInfo.UserId = (uint8_t)pUserInfo->UserId;
  1038. /*Activated in ActivateSession Command*/
  1039. SessionInfo.Activated = FALSE;
  1040. SessionInfo.AuthType = pGetSesChalReq->AuthType;
  1041. SessionInfo.Channel = *curchannel & 0xF;
  1042. SessionInfo.SessionID = TempSessId;
  1043. SessionInfo.TimeOutValue = g_BMCInfo.IpmiConfig.SessionTimeOut;
  1044. if(GetNumOfUsedSessions() >= g_BMCInfo.IpmiConfig.MaxSession)
  1045. {
  1046. CleanSession();
  1047. }
  1048. /* Add Session information in Table */
  1049. AddSession (&SessionInfo);
  1050. g_BMCInfo.pUserInfo = pUserInfo;
  1051. pGetSesChalRes->CompletionCode = CC_NORMAL;
  1052. pGetSesChalRes->TempSessionID = TempSessId;
  1053. /* generate Randam Challenge String */
  1054. for(Index=0;Index < CHALLENGE_STR_LEN;Index+=4)
  1055. {
  1056. TempRandom = stm32_generate_random32bit();
  1057. // printf("TempRandom: %#lx\n", TempRandom);
  1058. ChallengeString[Index] = TempRandom&0xff;
  1059. ChallengeString[Index+1] = TempRandom>>8;
  1060. ChallengeString[Index+2] = TempRandom>>16;
  1061. ChallengeString[Index+3] = TempRandom>>24;
  1062. }
  1063. memcpy(pGetSesChalRes->ChallengeString, ChallengeString, CHALLENGE_STR_LEN);
  1064. return sizeof (GetSesChallengeRes_T);
  1065. }
  1066. /*---------------------------------------
  1067. * ActivateSession
  1068. *---------------------------------------*/
  1069. int
  1070. ActivateSession ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1071. {
  1072. //TODO: dummy data
  1073. ActivateSesReq_T* pAcvtSesReq = ( ActivateSesReq_T*)pReq;
  1074. ActivateSesRes_T* pAcvtSesRes = ( ActivateSesRes_T*)pRes;
  1075. uint32_t *CurSesID,*curchannel;
  1076. SessionInfo_T* pSessInfo;
  1077. /* Initial Outbound Sequence Number cannot be null */
  1078. if (pAcvtSesReq->OutboundSeq == 0)
  1079. {
  1080. pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_SEQ_OUT_OF_RANGE;
  1081. return sizeof(*pRes);
  1082. }
  1083. CurSesID = pthread_getspecific(g_tls.CurSessionID);
  1084. curchannel = pthread_getspecific(g_tls.CurChannel);
  1085. pSessInfo = getSessionInfo (SESSION_ID_INFO, CurSesID);
  1086. if(pSessInfo == NULL)
  1087. {
  1088. pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_INVALID_SESSION_ID;
  1089. return sizeof (*pRes);
  1090. }
  1091. pSessInfo->Activated = TRUE;
  1092. pSessInfo->Channel = (*curchannel & 0xF);
  1093. /* set the Max Privilege allowed for the Session*/
  1094. pSessInfo->MaxPrivilege = pAcvtSesReq->Privilege;
  1095. /* set the Out bound sequensce Number */
  1096. pSessInfo->OutboundSeq = (pAcvtSesReq->OutboundSeq);
  1097. g_BMCInfo.SessionHandle += 1;
  1098. pSessInfo->SessionHandle = g_BMCInfo.SessionHandle;
  1099. pAcvtSesRes->CompletionCode = CC_NORMAL;
  1100. pAcvtSesRes->AuthType = (pSessInfo->AuthType & 0x0F);
  1101. pAcvtSesRes->SessionID = pSessInfo->SessionID;
  1102. pAcvtSesRes->InboundSeq = stm32_generate_random32bit();
  1103. pAcvtSesRes->Privilege = 0x04;
  1104. pSessInfo->InboundRecv = 0xFF;
  1105. pSessInfo->InboundSeq = (pAcvtSesRes->InboundSeq -1);
  1106. return sizeof (ActivateSesRes_T);
  1107. }
  1108. /*---------------------------------------
  1109. * SetSessionPrivLevel
  1110. *---------------------------------------*/
  1111. int
  1112. SetSessionPrivLevel ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1113. {
  1114. SetSesPrivLevelReq_T* pSetSesPrivLevelReq = ( SetSesPrivLevelReq_T*)pReq;
  1115. SetSesPrivLevelRes_T* pSetSesPrivLevelRes = ( SetSesPrivLevelRes_T*)pRes;
  1116. //Check for Reserved bits
  1117. if((pSetSesPrivLevelReq->Privilege == PRIV_LEVEL_CALLBACK) || (pSetSesPrivLevelReq->Privilege > PRIV_LEVEL_PROPRIETARY))
  1118. {
  1119. pSetSesPrivLevelRes->CompletionCode = CC_INV_DATA_FIELD;
  1120. return sizeof(SetSesPrivLevelRes_T);
  1121. }
  1122. /* According to the IPMI 2.0 Priv Level =1 is reserved */
  1123. if((PRIV_USER != pSetSesPrivLevelReq->Privilege) &&
  1124. (PRIV_OPERATOR != pSetSesPrivLevelReq->Privilege) &&
  1125. (PRIV_ADMIN != pSetSesPrivLevelReq->Privilege) &&
  1126. (PRIV_OEM != pSetSesPrivLevelReq->Privilege))
  1127. {
  1128. /*Requested Privilege exceeds ChannelPrivilege Limit */
  1129. pSetSesPrivLevelRes->CompletionCode = CC_INV_DATA_FIELD;
  1130. return sizeof (*pRes);
  1131. }
  1132. pSetSesPrivLevelRes->CompletionCode = CC_NORMAL;
  1133. pSetSesPrivLevelRes->Privilege = pSetSesPrivLevelReq->Privilege;
  1134. return sizeof (SetSesPrivLevelRes_T);
  1135. }
  1136. /*---------------------------------------
  1137. * CloseSession
  1138. *---------------------------------------*/
  1139. int
  1140. CloseSession ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1141. {
  1142. CloseSesReq_T* pCloseSesReq = (CloseSesReq_T*)pReq;
  1143. SessionInfo_T* pSessInfo;
  1144. uint32_t SessionID;
  1145. *pRes = CC_REQ_INV_LEN;
  1146. if ((4 != ReqLen) && (5 != ReqLen))
  1147. {
  1148. return sizeof (*pRes);
  1149. }
  1150. if (0 == pCloseSesReq->SessionID)
  1151. {
  1152. if (5 != ReqLen)
  1153. {
  1154. return sizeof (*pRes);
  1155. }
  1156. SessionID = (uint32_t)pCloseSesReq->SessionHandle;
  1157. *pRes = CC_CLOSE_INVALID_SESSION_ID_HANDLE;
  1158. pSessInfo = getSessionInfo (SESSION_HANDLE_INFO, &SessionID);
  1159. }
  1160. else
  1161. {
  1162. if (4 != ReqLen)
  1163. {
  1164. return sizeof (*pRes);
  1165. }
  1166. SessionID = pCloseSesReq->SessionID;
  1167. *pRes = CC_CLOSE_INVALID_SESSION_ID;
  1168. pSessInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
  1169. }
  1170. if ((NULL == pSessInfo) || (0 == pSessInfo->Activated))
  1171. {
  1172. return sizeof (*pRes);
  1173. }
  1174. /* The SessionInfo is deleted form session table from interface */
  1175. DeleteSession(pSessInfo);
  1176. *pRes = CC_NORMAL;
  1177. return sizeof (*pRes);
  1178. }
  1179. //#if GET_SESSION_INFO != UNIMPLEMENTED
  1180. ///*---------------------------------------
  1181. //* GetSessionInfo
  1182. //*---------------------------------------*/
  1183. //int
  1184. //GetSessionInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  1185. //{
  1186. // GetSesInfoReq_T* pGetSesInfoReq = ( GetSesInfoReq_T*)pReq;
  1187. // GetSesInfoRes_T* pGetSesInfoRes = ( GetSesInfoRes_T*)pRes;
  1188. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1189. // LANSesInfoRes_T LANSesInfo;
  1190. // LANIPv6SesInfoRes_T LANIPv6SesInfo;
  1191. // SessionInfo_T* pSessInfo;
  1192. // ChannelInfo_T* pChannelInfo;
  1193. // void* SessionArg;
  1194. // uint8_t SessionArgAlign[4];
  1195. // uint8_t SessionArgType,EthIndex, netindex = 0xFF;
  1196. // char IfcName[IFNAMSIZ];
  1197. // uint32_t *CurSesID,*curchannel;
  1198. // int i;
  1199. // *pRes = CC_REQ_INV_LEN;
  1200. // switch (pGetSesInfoReq->SessionIndex)
  1201. // {
  1202. // case 0:
  1203. // /* Get session information for this session */
  1204. // if (1 != ReqLen)
  1205. // {
  1206. // return sizeof (*pRes);
  1207. // }
  1208. // SessionArgType = SESSION_ID_INFO;
  1209. // OS_THREAD_TLS_GET(g_tls.CurSessionID,CurSesID);
  1210. // SessionArg = CurSesID;
  1211. // break;
  1212. // case 0xFF:
  1213. // if (5 != ReqLen)
  1214. // {
  1215. // return sizeof (*pRes);
  1216. // }
  1217. // SessionArgType = SESSION_ID_INFO;
  1218. // SessionArgAlign[0] = pGetSesInfoReq->SessionHandleOrID[0];
  1219. // SessionArgAlign[1] = pGetSesInfoReq->SessionHandleOrID[1];
  1220. // SessionArgAlign[2] = pGetSesInfoReq->SessionHandleOrID[2];
  1221. // SessionArgAlign[3] = pGetSesInfoReq->SessionHandleOrID[3];
  1222. // SessionArg = SessionArgAlign;
  1223. // break;
  1224. // case 0xFE:
  1225. // if (2 != ReqLen)
  1226. // {
  1227. // return sizeof (*pRes);
  1228. // }
  1229. // if (pGetSesInfoReq->SessionHandleOrID[0] == 0)
  1230. // {
  1231. // *pRes=CC_INV_DATA_FIELD;
  1232. // return sizeof (*pRes);
  1233. // }
  1234. // SessionArgType = SESSION_HANDLE_INFO;
  1235. // SessionArgAlign[0] = pGetSesInfoReq->SessionHandleOrID[0];
  1236. // SessionArgAlign[1] = pGetSesInfoReq->SessionHandleOrID[1];
  1237. // SessionArgAlign[2] = pGetSesInfoReq->SessionHandleOrID[2];
  1238. // SessionArgAlign[3] = pGetSesInfoReq->SessionHandleOrID[3];
  1239. // SessionArg = SessionArgAlign;
  1240. // break;
  1241. // default:
  1242. // if (1 != ReqLen)
  1243. // {
  1244. // return sizeof (*pRes);
  1245. // }
  1246. // SessionArgType = SESSION_INDEX_INFO;
  1247. // SessionArg = &pGetSesInfoReq->SessionIndex;
  1248. // break;
  1249. // }
  1250. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  1251. // pSessInfo = getSessionInfo (SessionArgType, SessionArg, BMCInst);
  1252. // if (NULL == pSessInfo)
  1253. // {
  1254. // TDBG ("GetSessionInfo: pSessInfo is NULL\n");
  1255. // /* if there is no active channel for the current session Index
  1256. // * return the following bytes
  1257. // */
  1258. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1259. // pChannelInfo = getChannelInfo (*curchannel & 0xF, BMCInst);
  1260. // if(NULL == pChannelInfo)
  1261. // {
  1262. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1263. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1264. // return sizeof (*pRes);
  1265. // }
  1266. // pGetSesInfoRes->CompletionCode = CC_NORMAL;
  1267. // pGetSesInfoRes->SessionHandle = BMC_GET_SHARED_MEM (BMCInst)->SessionHandle;
  1268. // pGetSesInfoRes->NumPossibleActiveSession= pBMCInfo->IpmiConfig.MaxSession;
  1269. // pGetSesInfoRes->NumActiveSession = GetNumOfActiveSessions (BMCInst);
  1270. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1271. // return (sizeof (GetSesInfoRes_T) - sizeof (ActiveSesInfo_T) - sizeof (SessionInfoRes_T));
  1272. // }
  1273. // memset (pGetSesInfoRes,0,sizeof(GetSesInfoRes_T));
  1274. // pChannelInfo = getChannelInfo (pSessInfo->Channel, BMCInst);
  1275. // if(NULL == pChannelInfo)
  1276. // {
  1277. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1278. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1279. // return sizeof (*pRes);
  1280. // }
  1281. // pGetSesInfoRes->CompletionCode = CC_NORMAL;
  1282. // pGetSesInfoRes->SessionHandle = pSessInfo->SessionHandle;
  1283. // pGetSesInfoRes->NumPossibleActiveSession = pBMCInfo->IpmiConfig.MaxSession;
  1284. // pGetSesInfoRes->NumActiveSession = GetNumOfActiveSessions (BMCInst);
  1285. // pGetSesInfoRes->ActiveSesinfo.UserID = pSessInfo->UserId & 0x3F;
  1286. // pGetSesInfoRes->ActiveSesinfo.Privilege = pSessInfo->Privilege & 0x0F;
  1287. // /* Set protocol bit as per Auth Type, bit4 must be 1 for IPMIv2.0 RMCP, 0 for IPMIv1.5 */
  1288. // if( AUTHTYPE_RMCP_PLUS_FORMAT == pSessInfo->AuthType )
  1289. // {
  1290. // pGetSesInfoRes->ActiveSesinfo.ChannelNum = (pSessInfo->Channel & 0x0F) | 0x10;
  1291. // }else
  1292. // {
  1293. // pGetSesInfoRes->ActiveSesinfo.ChannelNum = pSessInfo->Channel & 0x0F;
  1294. // }
  1295. // EthIndex= GetEthIndex(pSessInfo->Channel & 0x0F, BMCInst);
  1296. // if(0xff == EthIndex)
  1297. // {
  1298. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1299. // *pRes = CC_INV_DATA_FIELD;
  1300. // DeleteSession (pSessInfo,BMCInst);
  1301. // return sizeof (uint8_t);
  1302. // }
  1303. // memset(IfcName,0,sizeof(IfcName));
  1304. // /*Get the EthIndex*/
  1305. // if(GetIfcName(EthIndex,IfcName, BMCInst) == -1)
  1306. // {
  1307. // TCRIT("Error in Getting Ifc name\n");
  1308. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1309. // *pRes = CC_INV_DATA_FIELD;
  1310. // return sizeof (uint8_t);
  1311. // }
  1312. // for(i=0;i<sizeof(Ifcnametable)/sizeof(IfcName_T);i++)
  1313. // {
  1314. // if(strcmp(Ifcnametable[i].Ifcname,IfcName) == 0)
  1315. // {
  1316. // netindex= Ifcnametable[i].Index;
  1317. // break;
  1318. // }
  1319. // }
  1320. // if(netindex == 0xFF)
  1321. // {
  1322. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1323. // *pRes = CC_INV_DATA_FIELD;
  1324. // return sizeof (uint8_t);
  1325. // }
  1326. // if (IsLANChannel( pSessInfo->Channel, BMCInst))
  1327. // {
  1328. // if(g_corefeatures.global_ipv6 == ENABLED)
  1329. // {
  1330. // if(GetIPAdrressType(&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[0])==4)
  1331. // {
  1332. // memset(&LANSesInfo,0,sizeof(LANSesInfo));
  1333. // /* IP Address */
  1334. // _fmemcpy (&(LANSesInfo.IPAddress),
  1335. // &pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[sizeof(struct in6_addr)-sizeof(struct in_addr)],
  1336. // sizeof(struct in_addr));
  1337. // /* MAC Address */
  1338. // if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
  1339. // nwGetSrcCacheMacAddr((uint8_t*)&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[12],
  1340. // netindex, pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
  1341. // _fmemcpy(LANSesInfo.MACAddress, pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
  1342. // /* Port number */
  1343. // LANSesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
  1344. // _fmemcpy ((pRes+sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)),&LANSesInfo, sizeof (LANSesInfoRes_T));
  1345. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1346. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)+sizeof (LANSesInfoRes_T));
  1347. // }
  1348. // else
  1349. // {
  1350. // /* IP Address */
  1351. // memset(&LANIPv6SesInfo,0,sizeof(LANIPv6SesInfo));
  1352. // _fmemcpy (&(LANIPv6SesInfo.IPv6Address),
  1353. // pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr,
  1354. // sizeof(struct in6_addr));
  1355. // /* MAC Address */
  1356. // if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
  1357. // nwGetSrcMacAddr_IPV6((uint8_t*)&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr,
  1358. // pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
  1359. // _fmemcpy(LANIPv6SesInfo.MACAddress, pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
  1360. // /* Port number */
  1361. // LANIPv6SesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
  1362. // _fmemcpy ((pRes+sizeof (GetSesInfoRes_T) - sizeof(SessionInfoRes_T)),&LANIPv6SesInfo, sizeof (LANIPv6SesInfoRes_T));
  1363. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1364. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)+sizeof (LANIPv6SesInfoRes_T));
  1365. // }
  1366. // }
  1367. // else
  1368. // {
  1369. // /* IP Address */
  1370. // _fmemcpy (pGetSesInfoRes->SesInfo.LANSesInfo.IPAddress,
  1371. // pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr,
  1372. // sizeof (pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr));
  1373. // /* MAC Address */
  1374. // if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
  1375. // nwGetSrcCacheMacAddr((uint8_t*)pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr, netindex,
  1376. // pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
  1377. // _fmemcpy(pGetSesInfoRes->SesInfo.LANSesInfo.MACAddress,
  1378. // pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
  1379. // /* Port number */
  1380. // pGetSesInfoRes->SesInfo.LANSesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
  1381. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1382. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T) + sizeof (LANSesInfoRes_T));
  1383. // }
  1384. // }
  1385. // else if (pBMCInfo->IpmiConfig.SerialIfcSupport == 1 && pBMCInfo->SERIALch== pSessInfo->Channel)
  1386. // {
  1387. // pChannelInfo = getChannelInfo (pBMCInfo->SERIALch, BMCInst);
  1388. // if(NULL == pChannelInfo)
  1389. // {
  1390. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1391. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1392. // return sizeof (*pRes);
  1393. // }
  1394. // pGetSesInfoRes->SesInfo.SerialSesInfo.SessionActivityType = 0;
  1395. // pGetSesInfoRes->SesInfo.SerialSesInfo.DestinationSelector = 0;
  1396. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1397. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T) + sizeof (SerialSesInfoRes_T));
  1398. // }
  1399. // else
  1400. // {
  1401. // pChannelInfo = getChannelInfo(pSessInfo->Channel, BMCInst);
  1402. // if(NULL == pChannelInfo)
  1403. // {
  1404. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1405. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1406. // return sizeof (*pRes);
  1407. // }
  1408. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1409. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T));
  1410. // }
  1411. //}
  1412. //#endif
  1413. ///**
  1414. // * @fn GetAuthCodeForTypeV15
  1415. // * @brief This function will use the encryption technique supported
  1416. // * in IPMI V1.5 in order to produce Auth Code.
  1417. // * @param[in] pUserInfo - Pointer to User info structure.
  1418. // * @param[in] pGetAuthCodeReq - Pointer to the structure of request data
  1419. // * @param[out] pGetAuthCodeRes - Pointer to the resultant data.
  1420. // * @retval size of the result data.
  1421. // */
  1422. //static int
  1423. //GetAuthCodeForTypeV15 (UserInfo_T* pUserInfo,
  1424. // GetAuthCodeReq_T* pGetAuthCodeReq,
  1425. // GetAuthCodeRes_T* pGetAuthCodeRes )
  1426. //{
  1427. // uint8_t AuthCode;
  1428. // uint8_t InBuffer[2*IPMI15_MAX_PASSWORD_LEN + HASH_DATA_LENGTH];
  1429. // char UserPswd[MAX_PASSWD_LEN];
  1430. // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  1431. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1432. // memset(&(pGetAuthCodeRes->AuthCode), 0, AUTH_CODE_HASH_LEN);
  1433. // AuthCode = pGetAuthCodeReq->AuthType & AUTH_CODE_V15_MASK;
  1434. // if((pGetAuthCodeReq->AuthType & (BIT5 | BIT4)) ||
  1435. // (AuthCode == AUTHTYPE_RESERVED) || (AuthCode == AUTHTYPE_NONE) ||
  1436. // (AuthCode == AUTHTYPE_STRAIGHT_PASSWORD) ||
  1437. // (AuthCode > AUTHTYPE_OEM_PROPRIETARY))
  1438. // {
  1439. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1440. // return (sizeof (GetAuthCodeRes_T) - 4);
  1441. // }
  1442. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1443. // {
  1444. // /* Get Encryption Key from the MBMCInfo_t structure */
  1445. // LOCK_BMC_SHARED_MEM(BMCInst);
  1446. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  1447. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1448. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  1449. // {
  1450. // TCRIT("Error in decrypting the IPMI User password for User ID:%d.\n", pUserInfo->UserId);
  1451. // pGetAuthCodeRes->CompletionCode = CC_UNSPECIFIED_ERR;
  1452. // return sizeof(*pGetAuthCodeRes);
  1453. // }
  1454. // memcpy(&InBuffer[0],UserPswd,IPMI15_MAX_PASSWORD_LEN);
  1455. // }
  1456. // else
  1457. // {
  1458. // memcpy(&InBuffer[0],pUserInfo->UserPassword,IPMI15_MAX_PASSWORD_LEN);
  1459. // }
  1460. // LOCK_BMC_SHARED_MEM(BMCInst);
  1461. // switch (AuthCode)
  1462. // {
  1463. // #if 0 // As per IPMIv2 Markup E4, Straight Password key is Reserved
  1464. // case AUTH_TYPE_PASSWORD: /* Straight password */
  1465. // if (0 == _fmemcmp (pUserInfo->UserPassword,pGetAuthCodeReq->HashData,IPMI15_MAX_PASSWORD_LEN))
  1466. // {
  1467. // _fmemcpy (pGetAuthCodeRes->AuthCode, "OK", 2);
  1468. // }
  1469. // else
  1470. // {
  1471. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1472. // }
  1473. // break;
  1474. // #endif
  1475. // case AUTH_TYPE_MD2: /* MD2 */
  1476. // _fmemcpy (&InBuffer[IPMI15_MAX_PASSWORD_LEN],
  1477. // pGetAuthCodeReq->HashData, HASH_DATA_LENGTH);
  1478. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1479. // {
  1480. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1481. // UserPswd, IPMI15_MAX_PASSWORD_LEN);
  1482. // }
  1483. // else
  1484. // {
  1485. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1486. // pUserInfo->UserPassword, IPMI15_MAX_PASSWORD_LEN);
  1487. // }
  1488. // AuthCodeCalMD2 (InBuffer, pGetAuthCodeRes->AuthCode, sizeof (InBuffer));
  1489. // break;
  1490. // case AUTH_TYPE_MD5: /* MD5 */
  1491. // _fmemcpy (&InBuffer[IPMI15_MAX_PASSWORD_LEN],
  1492. // pGetAuthCodeReq->HashData, HASH_DATA_LENGTH);
  1493. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1494. // {
  1495. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1496. // UserPswd,IPMI15_MAX_PASSWORD_LEN);
  1497. // }
  1498. // else
  1499. // {
  1500. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1501. // pUserInfo->UserPassword,IPMI15_MAX_PASSWORD_LEN);
  1502. // }
  1503. // AuthCodeCalMD5 (InBuffer, pGetAuthCodeRes->AuthCode, sizeof (InBuffer));
  1504. // break;
  1505. // default:
  1506. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1507. // }
  1508. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1509. // // IPMI V1.5 AuthCode is only 16 byte.
  1510. // return (sizeof (GetAuthCodeRes_T) - 4);
  1511. //}
  1512. ///**
  1513. // * @fn GetAuthCodeForTypeV20
  1514. // * @brief This function will use the encryption technique supported
  1515. // * in IPMI V2.0 in order to produce Auth Code.
  1516. // * @param[in] pUserInfo - Pointer to User info structure.
  1517. // * @param[in] pGetAuthCodeReq - Pointer to the structure of request data
  1518. // * @param[out] pGetAuthCodeRes - Pointer to the resultant data.
  1519. // * @retval size of the result data.
  1520. // */
  1521. //static int
  1522. //GetAuthCodeForTypeV20 (UserInfo_T* pUserInfo,
  1523. // GetAuthCodeReq_T* pGetAuthCodeReq,
  1524. // GetAuthCodeRes_T* pGetAuthCodeRes )
  1525. //{
  1526. // uint8_t AuthCode;
  1527. // uint8_t UserPasswdLen=0;
  1528. // uint8_t DecVal = 0;
  1529. // uint8_t m_SIK [SESSION_INTEGRITY_KEY_SIZE];
  1530. // char UserPswd[MAX_PASSWD_LEN];
  1531. // unsigned char PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  1532. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1533. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1534. // {
  1535. // /* Get Encryption Key from the MBMCInfo_t structure */
  1536. // LOCK_BMC_SHARED_MEM(BMCInst);
  1537. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  1538. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1539. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  1540. // {
  1541. // TCRIT("\nError in decrypting the IPMI User password for user with ID:%d.\n", pUserInfo->UserId);
  1542. // pGetAuthCodeRes->CompletionCode = CC_UNSPECIFIED_ERR;
  1543. // return sizeof (*pGetAuthCodeRes);
  1544. // }
  1545. // }
  1546. // else
  1547. // {
  1548. // memcpy(&UserPswd, pUserInfo->UserPassword, MAX_PASSWD_LEN);
  1549. // }
  1550. // /* Calculate password length */
  1551. // UserPasswdLen = _fstrlen (( char*)UserPswd);
  1552. // UserPasswdLen = (UserPasswdLen > MAX_PASSWORD_LEN) ?
  1553. // MAX_PASSWORD_LEN : UserPasswdLen;
  1554. // memset(&(pGetAuthCodeRes->AuthCode), 0, AUTH_CODE_HASH_LEN);
  1555. // AuthCode = pGetAuthCodeReq->AuthType & AUTH_CODE_V20_MASK;
  1556. // /* Validate the Auth Code */
  1557. // if ((AuthCode > MIN_AUTH_CODE_V20) && (AuthCode < MAX_AUTH_CODE_V20))
  1558. // {
  1559. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1560. // return sizeof(GetAuthCodeRes_T);
  1561. // }
  1562. // LOCK_BMC_SHARED_MEM(BMCInst);
  1563. // switch(AuthCode)
  1564. // {
  1565. // case AUTH_NONE: /* none */
  1566. // TDBG ("\nInside AUTH_NONE in GetAuthCode");
  1567. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1568. // break;
  1569. // case AUTH_HMAC_SHA1_96: /* HMAC-SHA1-96 */
  1570. // TDBG ("\nInside AUTH_HMAC_SHA1_96 in GetAuthCode");
  1571. // hmac_sha1 ((uint8_t *)UserPswd, UserPasswdLen,
  1572. // (uint8_t *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1573. // (uint8_t *)m_SIK, SESSION_INTEGRITY_KEY_SIZE);
  1574. // hmac_sha1 ((uint8_t *)m_SIK, SESSION_INTEGRITY_KEY_SIZE,
  1575. // (uint8_t *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1576. // (uint8_t *)&(pGetAuthCodeRes->AuthCode), HMAC_SHA1_96_LEN);
  1577. // DecVal = AUTH_CODE_HASH_LEN - HMAC_SHA1_96_LEN;
  1578. // break;
  1579. // case AUTH_HMAC_MD5_128: /* HMAC-MD5-128 */
  1580. // TDBG ("\nInside AUTH_HMAC_MD5_128 in GetAuthCode");
  1581. // hmac_md5 ((unsigned char*)UserPswd, UserPasswdLen,
  1582. // pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1583. // m_SIK, SESSION_HMAC_MD5_I_KEY_SIZE);
  1584. // hmac_md5 (m_SIK, SESSION_HMAC_MD5_I_KEY_SIZE,
  1585. // pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1586. // (unsigned char *)&(pGetAuthCodeRes->AuthCode),
  1587. // SESSION_HMAC_MD5_I_KEY_SIZE);
  1588. // DecVal = AUTH_CODE_HASH_LEN - SESSION_HMAC_MD5_I_KEY_SIZE;
  1589. // break;
  1590. // case AUTH_MD5_128: /* MD5-128 */
  1591. // TDBG ("\nInside AUTH_MD5_128 in GetAuthCode");
  1592. // MD5_128 ((char *)UserPswd, UserPasswdLen,
  1593. // (char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1594. // (char *)m_SIK, SESSION_MD5_KEY_SIZE);
  1595. // MD5_128 ((char *)m_SIK, SESSION_INTEGRITY_KEY_SIZE,
  1596. // (char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1597. // (char *)&(pGetAuthCodeRes->AuthCode), SESSION_MD5_KEY_SIZE);
  1598. // DecVal = AUTH_CODE_HASH_LEN - SESSION_MD5_KEY_SIZE;
  1599. // break;
  1600. // case AUTH_HMAC_SHA256_128: /* HMAC-SHA256-128 */
  1601. // TDBG ("\nInside AUTH_HMAC_SHA256_128 in GetAuthCode");
  1602. // hmac_sha256 ((unsigned char *)UserPswd, UserPasswdLen,
  1603. // (unsigned char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1604. // (unsigned char *)m_SIK, SHA2_HASH_KEY_SIZE);
  1605. // hmac_sha256 (m_SIK, SHA2_HASH_KEY_SIZE,
  1606. // (unsigned char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1607. // (unsigned char *)&(pGetAuthCodeRes->AuthCode), HMAC_SHA256_128_LEN);
  1608. // DecVal = AUTH_CODE_HASH_LEN - HMAC_SHA256_128_LEN;
  1609. // break;
  1610. // //! TODO: Need support in openssl.
  1611. // default: /* OEM or Reserved */
  1612. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1613. // }
  1614. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1615. // if (DecVal > sizeof(GetAuthCodeRes_T))
  1616. // return sizeof(GetAuthCodeRes_T);
  1617. // else
  1618. // return (sizeof(GetAuthCodeRes_T) - DecVal);
  1619. //}
  1620. ///**
  1621. // * @fn GetAuthCode
  1622. // * @brief This function will encrypt the given 16 byte data with
  1623. // * the algorithm given and return Auth Code.
  1624. // * @param[in] pReq - Request data.
  1625. // * @param[in] ReqLen - Length of the request data.
  1626. // * @param[out] pRes - Result data
  1627. // * @retval size of the result data.
  1628. // */
  1629. //int
  1630. //GetAuthCode ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes )
  1631. //{
  1632. // GetAuthCodeReq_T* pGetAuthCodeReq = ( GetAuthCodeReq_T*)pReq;
  1633. // GetAuthCodeRes_T* pGetAuthCodeRes = ( GetAuthCodeRes_T*)pRes;
  1634. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  1635. // UserInfo_T* pUserInfo;
  1636. // uint8_t AuthType,*curchannel;
  1637. // ChannelInfo_T* pChannelInfo;
  1638. // int nRetSize = 0;
  1639. // /* Check for Reserved Bits */
  1640. // if((pGetAuthCodeReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4)) ||
  1641. // (pGetAuthCodeReq->UserID & (BIT7 | BIT6)))
  1642. // {
  1643. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1644. // return sizeof(*pRes);
  1645. // }
  1646. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  1647. // /* Validate the channel number given */
  1648. // if (CURRENT_CHANNEL_NUM == pGetAuthCodeReq->ChannelNum)
  1649. // {
  1650. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1651. // pChannelInfo = getChannelInfo(*curchannel & 0xF,BMCInst);
  1652. // }
  1653. // else
  1654. // pChannelInfo = getChannelInfo(pGetAuthCodeReq->ChannelNum,BMCInst);
  1655. // if (NULL == pChannelInfo)
  1656. // {
  1657. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1658. // *pRes = CC_INV_DATA_FIELD;
  1659. // return sizeof(*pRes);
  1660. // }
  1661. // /* Get the user information for the given userID */
  1662. // pUserInfo = getUserIdInfo (pGetAuthCodeReq->UserID,BMCInst);
  1663. // if (NULL == pUserInfo)
  1664. // {
  1665. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1666. // TDBG ("AppDevice.c : GetAuthCode - Invalid user Id\n");
  1667. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1668. // return sizeof (*pRes);
  1669. // }
  1670. // AuthType = pGetAuthCodeReq->AuthType & GET_AUTH_TYPE_MASK;
  1671. // pGetAuthCodeRes->CompletionCode = CC_NORMAL;
  1672. // switch(AuthType)
  1673. // {
  1674. // case AUTH_TYPE_V15: /* IPMI v1.5 AuthCode Algorithms */
  1675. // nRetSize = GetAuthCodeForTypeV15(pUserInfo, pGetAuthCodeReq, pGetAuthCodeRes,BMCInst);
  1676. // break;
  1677. // case AUTH_TYPE_V20: /* IPMI v2.0/RMCP+ Algorithm Number */
  1678. // nRetSize = GetAuthCodeForTypeV20(pUserInfo, pGetAuthCodeReq, pGetAuthCodeRes,BMCInst);
  1679. // break;
  1680. // default:
  1681. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1682. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1683. // return sizeof(*pRes);
  1684. // }
  1685. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1686. // return nRetSize;
  1687. //}
  1688. ///*---------------------------------------
  1689. //* SetChAccess
  1690. //*---------------------------------------*/
  1691. //int
  1692. //SetChAccess ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  1693. //{
  1694. // SetChAccessReq_T* pSetChAccessReq = ( SetChAccessReq_T*)pReq;
  1695. // uint8_t ChannelNum, AccessMode;
  1696. // ChannelInfo_T* pNvrChInfo;
  1697. // ChannelInfo_T* pChannelInfo;
  1698. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1699. // uint8_t AccessFlags = 0,i=0,*curchannel;
  1700. //// char ChFilename[MAX_CHFILE_NAME];
  1701. // /* Reserve Bit Checking for Set Channel Acces */
  1702. // for(i=0;i<ReqLen;i++)
  1703. // {
  1704. // if( 0 != (pReq[i] & m_Set_ChReserveBit[i]))
  1705. // {
  1706. // *pRes = CC_INV_DATA_FIELD;
  1707. // return sizeof (*pRes);
  1708. // }
  1709. // }
  1710. // /* Reserve Value checking */
  1711. // if((pReq[1] & 0xC0)== 0xC0 || (pReq[2] & 0xC0) == 0xC0)
  1712. // {
  1713. // *pRes = CC_INV_DATA_FIELD;
  1714. // return sizeof (*pRes);
  1715. // }
  1716. // ChannelNum = pSetChAccessReq->ChannelNum & 0x0F;
  1717. // if (CURRENT_CHANNEL_NUM == ChannelNum)
  1718. // {
  1719. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1720. // ChannelNum = *curchannel & 0xF;
  1721. // }
  1722. // if (((GetBits (pSetChAccessReq->Privilege, 0x0F)) < PRIV_LEVEL_CALLBACK) ||
  1723. // ((GetBits (pSetChAccessReq->Privilege, 0x0F)) > PRIV_LEVEL_PROPRIETARY))
  1724. // {
  1725. // IPMI_DBG_PRINT_1 ("Invalid Channel Privilege = 0x%x\n", pSetChAccessReq->Privilege);
  1726. // *pRes = CC_INV_DATA_FIELD;
  1727. // return sizeof (*pRes);
  1728. // }
  1729. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  1730. // pChannelInfo = getChannelInfo(ChannelNum, BMCInst);
  1731. // if (NULL == pChannelInfo)
  1732. // {
  1733. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1734. // *pRes = CC_INV_DATA_FIELD;
  1735. // return sizeof (*pRes);
  1736. // }
  1737. // /*point to NVRAM ChannelInfo */
  1738. // pNvrChInfo = GetNVRChConfigs(pChannelInfo,BMCInst);
  1739. // if (SESSIONLESS_CHANNEL == pChannelInfo->SessionSupport)
  1740. // {
  1741. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1742. // /* Channel is sessionless channel this command is not supported */
  1743. // *pRes = CC_SET_CH_COMMAND_NOT_SUPPORTED;
  1744. // return sizeof (*pRes);
  1745. // }
  1746. // AccessMode = pSetChAccessReq->ChannelAccess & 0x07;
  1747. // if(ChannelNum == pBMCInfo->SERIALch)
  1748. // {
  1749. // if( NULL != g_PDKHandle[PDK_SWITCHMUX])
  1750. // {
  1751. // ((void(*)(uint8_t, int))(g_PDKHandle[PDK_SWITCHMUX]))(AccessMode ,BMCInst);
  1752. // }
  1753. // }
  1754. // /* if the requested access mode is supported for the given channel */
  1755. // if (0 == (pChannelInfo->AccessModeSupported & (1 << AccessMode)))
  1756. // {
  1757. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1758. // *pRes = CC_SET_CH_ACCES_MODE_NOT_SUPPORTED;
  1759. // return sizeof (*pRes);
  1760. // }
  1761. // AccessFlags = GetBits (pSetChAccessReq->ChannelAccess, 0xC0);
  1762. // switch (AccessFlags)
  1763. // {
  1764. // case 0:
  1765. // /* dont set channel access */
  1766. // break;
  1767. // case 1:
  1768. // /*set in Non volatile Memory and in voatile Memory */
  1769. // pNvrChInfo->Alerting = GetBits (pSetChAccessReq->ChannelAccess , 0x20);
  1770. // pNvrChInfo->PerMessageAuth = GetBits (pSetChAccessReq->ChannelAccess , 0x10);
  1771. // pNvrChInfo->UserLevelAuth = GetBits (pSetChAccessReq->ChannelAccess , 0x08);
  1772. // pNvrChInfo->AccessMode = AccessMode;
  1773. // /* write to NVRAM */
  1774. // FlushChConfigs((uint8_t*)pNvrChInfo,pNvrChInfo->ChannelNumber,BMCInst);
  1775. // pChannelInfo->Alerting = pNvrChInfo->Alerting;
  1776. // pChannelInfo->PerMessageAuth= pNvrChInfo->PerMessageAuth;
  1777. // pChannelInfo->UserLevelAuth = pNvrChInfo->UserLevelAuth;
  1778. // pChannelInfo->AccessMode = AccessMode;
  1779. // break;
  1780. // case 2:
  1781. // /*set in volatile Memmory only */
  1782. // pChannelInfo->Alerting = GetBits (pSetChAccessReq->ChannelAccess, 0x20);
  1783. // pChannelInfo->PerMessageAuth= GetBits (pSetChAccessReq->ChannelAccess, 0x10);
  1784. // pChannelInfo->UserLevelAuth = GetBits (pSetChAccessReq->ChannelAccess, 0x08);
  1785. // pChannelInfo->AccessMode = AccessMode;
  1786. // }
  1787. // switch (GetBits (pSetChAccessReq->Privilege, 0xC0))
  1788. // {
  1789. // case 0:
  1790. // /* dont set prilivege level */
  1791. // break;
  1792. // case 1:
  1793. // /* set in non volatile mem and volatile memeory*/ /*set privilege*/
  1794. // pNvrChInfo->MaxPrivilege = GetBits (pSetChAccessReq->Privilege, 0x0F);
  1795. // pChannelInfo->MaxPrivilege = pNvrChInfo->MaxPrivilege;
  1796. // break;
  1797. // case 2:
  1798. // /*set privilege*/
  1799. // /* set in volatile memeory only */
  1800. // pChannelInfo->MaxPrivilege = GetBits (pSetChAccessReq->Privilege, 0x0F);
  1801. // }
  1802. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1803. // *pRes = CC_NORMAL;
  1804. // return sizeof (*pRes);
  1805. //}
  1806. ///*---------------------------------------
  1807. //* GetChAccess
  1808. //*---------------------------------------*/
  1809. //int
  1810. //GetChAccess ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  1811. //{
  1812. // GetChAccessReq_T* pGetChAccessReq = ( GetChAccessReq_T*)pReq;
  1813. // GetChAccessRes_T* pGetChAccessRes = ( GetChAccessRes_T*)pRes;
  1814. // ChannelInfo_T* pChannelInfo;
  1815. // ChannelInfo_T* pNvrChInfo;
  1816. // uint8_t ChannelNum,AccessFlag,*curchannel;
  1817. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  1818. // /* Check for reserved bits */
  1819. // if((0 != (pGetChAccessReq->ChannelNum & 0xf0)) ||
  1820. // (0 != (pGetChAccessReq-> AccessFlag & 0x3f)))
  1821. // {
  1822. // pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  1823. // return sizeof (*pRes);
  1824. // }
  1825. // ChannelNum = pGetChAccessReq->ChannelNum & 0x0F;
  1826. // if (CURRENT_CHANNEL_NUM == ChannelNum)
  1827. // {
  1828. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1829. // ChannelNum = *curchannel & 0xF;
  1830. // }
  1831. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  1832. // pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
  1833. // if (NULL == pChannelInfo)
  1834. // {
  1835. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1836. // pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  1837. // return sizeof (*pRes);
  1838. // }
  1839. // if (SESSIONLESS_CHANNEL == pChannelInfo->SessionSupport)
  1840. // {
  1841. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1842. // /* Channel is sessionless channel this command is not supported */
  1843. // pGetChAccessRes->CompletionCode = CC_GET_CH_COMMAND_NOT_SUPPORTED;
  1844. // return sizeof (*pRes);
  1845. // }
  1846. // AccessFlag = GetBits (pGetChAccessReq->AccessFlag, 0xC0);
  1847. // pGetChAccessRes->CompletionCode = CC_NORMAL;
  1848. // switch (AccessFlag)
  1849. // {
  1850. // case 1:
  1851. // /* Get Channel Information from NVRAM */
  1852. // pNvrChInfo = GetNVRChConfigs(pChannelInfo,BMCInst);
  1853. // pGetChAccessRes->ChannelAccess = SetBits (0x20, pNvrChInfo->Alerting);
  1854. // pGetChAccessRes->ChannelAccess |= SetBits (0x10, pNvrChInfo->PerMessageAuth);
  1855. // pGetChAccessRes->ChannelAccess |= SetBits (0x08, pNvrChInfo->UserLevelAuth);
  1856. // pGetChAccessRes->ChannelAccess |= SetBits (0x07, pNvrChInfo->AccessMode);
  1857. // pGetChAccessRes->Privilege = SetBits (0x0F, pNvrChInfo->MaxPrivilege);
  1858. // break;
  1859. // case 2:
  1860. // /* Get Channel Information from Volatile RAM */
  1861. // pGetChAccessRes->ChannelAccess = SetBits (0x20, pChannelInfo->Alerting);
  1862. // pGetChAccessRes->ChannelAccess |= SetBits (0x10, pChannelInfo->PerMessageAuth);
  1863. // pGetChAccessRes->ChannelAccess |= SetBits (0x08, pChannelInfo->UserLevelAuth);
  1864. // pGetChAccessRes->ChannelAccess |= SetBits (0x07, pChannelInfo->AccessMode);
  1865. // pGetChAccessRes->Privilege = SetBits (0x0F, pChannelInfo->MaxPrivilege);
  1866. // break;
  1867. // default:
  1868. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1869. // pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  1870. // return sizeof (*pRes);
  1871. // }
  1872. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1873. // return sizeof (GetChAccessRes_T);
  1874. //}
  1875. /*---------------------------------------
  1876. * GetChInfo
  1877. *---------------------------------------*/
  1878. int
  1879. GetChInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1880. {
  1881. GetChInfoReq_T* pGetChInfoReq = ( GetChInfoReq_T*)pReq;
  1882. GetChInfoRes_T* pGetChInfoRes = ( GetChInfoRes_T*)pRes;
  1883. ChannelInfo_T* pChannelInfo;
  1884. uint8_t ChannelNum,*curchannel;
  1885. if(pGetChInfoReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4)) //Check for Reserved bits
  1886. {
  1887. pGetChInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1888. return sizeof(*pRes);
  1889. }
  1890. ChannelNum = pGetChInfoReq->ChannelNum;
  1891. if (CURRENT_CHANNEL_NUM == ChannelNum)
  1892. {
  1893. curchannel = pthread_getspecific(g_tls.CurChannel);
  1894. ChannelNum = *curchannel & 0xF;
  1895. /* UDS, not being a physical channel, will hold LAN properties */
  1896. if(UDS_CHANNEL == ChannelNum)
  1897. {
  1898. ChannelNum = LAN_RMCP_CHANNEL1_TYPE;
  1899. }
  1900. }
  1901. pChannelInfo = getChannelInfo(ChannelNum);
  1902. if (NULL == pChannelInfo)
  1903. {
  1904. pGetChInfoRes->CompletionCode = CC_INV_DATA_FIELD ;
  1905. return sizeof (*pRes);
  1906. }
  1907. pGetChInfoRes->CompletionCode = CC_NORMAL;
  1908. pGetChInfoRes->ChannelNum = ChannelNum;
  1909. pGetChInfoRes->ChannelMedium = pChannelInfo->ChannelMedium;
  1910. pGetChInfoRes->ChannelProtocol = pChannelInfo->ChannelProtocol;
  1911. pGetChInfoRes->SessionActiveSupport = pChannelInfo->SessionSupport << 6;
  1912. pGetChInfoRes->SessionActiveSupport |= pChannelInfo->ActiveSession;
  1913. memcpy (pGetChInfoRes->VendorID, pChannelInfo->ProtocolVendorId,
  1914. sizeof (pGetChInfoRes->VendorID));
  1915. memcpy (pGetChInfoRes->AuxiliaryInfo, pChannelInfo->AuxiliaryInfo,
  1916. sizeof (pGetChInfoRes->AuxiliaryInfo));
  1917. return sizeof (GetChInfoRes_T);
  1918. }
  1919. ///*---------------------------------------
  1920. //* IsChannelSuppGroups
  1921. //*---------------------------------------*/
  1922. //uint8_t IsChannelSuppGroups(uint8_t ChannelNum )
  1923. //{
  1924. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1925. // ChannelInfo_T* pChannelInfo;
  1926. // if(IsLANChannel(ChannelNum, BMCInst))
  1927. // {
  1928. //
  1929. // pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
  1930. // if(pChannelInfo==NULL)
  1931. // return 0;
  1932. // if(pChannelInfo->ChannelType==LAN_RMCP_CHANNEL1_TYPE)
  1933. // {
  1934. // return pChannelInfo->ChannelType;
  1935. // }
  1936. // else
  1937. // {
  1938. // if(pChannelInfo->ChannelType==LAN_RMCP_CHANNEL2_TYPE)
  1939. // {
  1940. // return pChannelInfo->ChannelType;
  1941. // }
  1942. // else
  1943. // {
  1944. // if(pChannelInfo->ChannelType==LAN_RMCP_CHANNEL3_TYPE)
  1945. // {
  1946. // return pChannelInfo->ChannelType;
  1947. // }
  1948. // else
  1949. // return 0;
  1950. // }
  1951. // }
  1952. // return 0;
  1953. // }
  1954. // else
  1955. // {
  1956. // if (pBMCInfo->IpmiConfig.SerialIfcSupport == 1 && (pBMCInfo->SERIALch != CH_NOT_USED && ChannelNum == pBMCInfo->SERIALch))
  1957. // {
  1958. // pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
  1959. // if(pChannelInfo==NULL)
  1960. // return 0;
  1961. // return pChannelInfo->ChannelType;
  1962. // }
  1963. // else
  1964. // return 0;
  1965. // }
  1966. //}
  1967. ///*---------------------------------------
  1968. //* ModifyUsrGRP
  1969. //*---------------------------------------*/
  1970. //int
  1971. //ModifyUsrGrp(char * UserName,uint8_t ChannelNum,uint8_t OldAccessLimit, uint8_t NewAccessLimit )
  1972. //{
  1973. // char oldgrp[20]="",newgrp[20]="";
  1974. // if(0 == NewAccessLimit)
  1975. // {
  1976. // DeleteUsrFromIPMIGrp(UserName);
  1977. // }
  1978. // if(PRIV_LEVEL_NO_ACCESS == OldAccessLimit)
  1979. // {
  1980. // strcpy(oldgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege].grpname);
  1981. // }
  1982. // else if(IGNORE_ADD_OR_REMOVE != OldAccessLimit)
  1983. // {
  1984. // strcpy(oldgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege+OldAccessLimit].grpname);
  1985. // }
  1986. // if(PRIV_LEVEL_NO_ACCESS == NewAccessLimit)
  1987. // {
  1988. // strcpy(newgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege].grpname);
  1989. // }
  1990. // else if(IGNORE_ADD_OR_REMOVE != NewAccessLimit)
  1991. // {
  1992. // strcpy(newgrp,g_GrpPriv[g_ChannelPrivtbl[ChannelNum].Privilege+NewAccessLimit].grpname);
  1993. // }
  1994. // AddIPMIUsrtoChGrp(UserName,(char *)oldgrp,(char *)newgrp);
  1995. // return 0;
  1996. //}
  1997. /*---------------------------------------
  1998. * SetUserAccess
  1999. *---------------------------------------*/
  2000. int
  2001. SetUserAccess ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  2002. {
  2003. SetUserAccessReq_T* pSetUserAccessReq = ( SetUserAccessReq_T*)pReq;
  2004. UserInfo_T* pUserInfo;
  2005. if (ReqLen == sizeof(SetUserAccessReq_T) - sizeof(pSetUserAccessReq->SessionLimit) )
  2006. {
  2007. pSetUserAccessReq->SessionLimit = 0;
  2008. }
  2009. else if(ReqLen == sizeof(SetUserAccessReq_T))
  2010. {
  2011. if(0 != pSetUserAccessReq->SessionLimit)
  2012. {
  2013. *pRes = CC_INV_DATA_FIELD;
  2014. return sizeof (*pRes);
  2015. }
  2016. }
  2017. else
  2018. {
  2019. *pRes = CC_REQ_INV_LEN;
  2020. return sizeof (*pRes);
  2021. }
  2022. pUserInfo = getUserIdInfo(pSetUserAccessReq->UserID);
  2023. if (NULL == pUserInfo)
  2024. {
  2025. printf ("AppDevice.c : SetUserAccess - Invalid user Id\n");
  2026. *pRes = CC_INV_DATA_FIELD;
  2027. return sizeof (*pRes);
  2028. }
  2029. // if (pUserInfo->ID != USER_ID)
  2030. // {
  2031. // printf("Invalid data field\n");
  2032. // *pRes = CC_INV_DATA_FIELD;
  2033. // return sizeof (*pRes);
  2034. // }
  2035. // pUserInfo->ChannelAccess = (pSetUserAccessReq->ChannelNoUserAccess&0x70) | (pSetUserAccessReq->AccessLimit&0x0f);
  2036. *pRes = CC_NORMAL;
  2037. return sizeof (*pRes);
  2038. }
  2039. /*---------------------------------------
  2040. * GetUserAccess
  2041. *---------------------------------------*/
  2042. int
  2043. GetUserAccess ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  2044. {
  2045. GetUserAccessReq_T* pGetUserAccessReq = ( GetUserAccessReq_T*)pReq;
  2046. GetUserAccessRes_T* pGetUserAccessRes = ( GetUserAccessRes_T*)pRes;
  2047. UserInfo_T* pUserInfo;
  2048. pUserInfo = getUserIdInfo (pGetUserAccessReq->UserID);
  2049. if (NULL == pUserInfo)
  2050. {
  2051. pGetUserAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  2052. return sizeof (*pRes);
  2053. }
  2054. if(FALSE == pUserInfo->UserStatus)
  2055. pGetUserAccessRes->ChannelAccess = 0x0F;
  2056. else
  2057. pGetUserAccessRes->ChannelAccess = 0x34;
  2058. pGetUserAccessRes->CompletionCode = CC_NORMAL;
  2059. pGetUserAccessRes->MaxNoUserID = MAX_USER_NUM;
  2060. pGetUserAccessRes->CurrentUserID = g_BMCInfo.CurrentNoUser;
  2061. pGetUserAccessRes->FixedUserID = 0;
  2062. return sizeof (GetUserAccessRes_T);
  2063. }
  2064. /*---------------------------------------
  2065. * SetUserName
  2066. *---------------------------------------*/
  2067. int
  2068. SetUserName ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes) //default password 123456
  2069. {
  2070. SetUserNameReq_T* pSetUserNameReq = ( SetUserNameReq_T*)pReq;
  2071. UserInfo_T* pUserInfo;
  2072. uint8_t i;
  2073. uint8_t UserName[MAX_USERNAME_LEN + 1]; //plus 1 for null terminator
  2074. uint8_t InvalidChar[]={ ' ' , ',' , '.' , '/' , ':' , ';' , '\\' , '(', ')' , 0x01 ,
  2075. 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09, 0x0A ,
  2076. 0x0B , 0x0C , 0x0D , 0x0E , 0x0F , 0x10 , 0x11 , 0x12, 0x13 ,
  2077. 0x14 , 0x15 , 0x16 , 0x17 , 0x18 , 0x19 , 0x1A , 0x1B, 0x1C ,
  2078. 0x1D , 0x1E , 0x1F , 0x7F} ;
  2079. // Check for Reserved bits
  2080. if(pSetUserNameReq->UserID & (BIT7 | BIT6) || (pSetUserNameReq->UserID == 0x00))
  2081. {
  2082. *pRes = CC_INV_DATA_FIELD;
  2083. return sizeof(*pRes);
  2084. }
  2085. /*User Id exceeded the limit or Cant set NULL User */
  2086. if (pSetUserNameReq->UserID > MAX_USER_NUM )
  2087. {
  2088. *pRes = CC_INV_DATA_FIELD ;
  2089. return sizeof (*pRes);
  2090. }
  2091. /* We should not set the NULL user */
  2092. if(0== pSetUserNameReq->UserName [0] )
  2093. {
  2094. printf("\n Setting the NULL user :%x",pSetUserNameReq->UserID);
  2095. *pRes = CC_INV_DATA_FIELD ;
  2096. return sizeof (*pRes);
  2097. }
  2098. if((strlen(pSetUserNameReq->UserName) > MAX_USERNAME_LEN) || (strlen(pSetUserNameReq->UserName) == 0))
  2099. {
  2100. printf("Invalid username length: %d\n", strlen(pSetUserNameReq->UserName));
  2101. *pRes = CC_INV_DATA_FIELD;
  2102. return 1;
  2103. }
  2104. pUserInfo = getUserIdInfo(pSetUserNameReq->UserID);
  2105. /* check for numeric first char and special chars */
  2106. if( (pSetUserNameReq->UserName[0] >= '0') && (pSetUserNameReq->UserName[0] <= '9') )
  2107. {
  2108. *pRes = CC_INV_DATA_FIELD;
  2109. return sizeof(*pRes);
  2110. }
  2111. else
  2112. {
  2113. strncpy((char *)UserName,(const char *) pSetUserNameReq->UserName, sizeof(pSetUserNameReq->UserName));
  2114. UserName[MAX_USERNAME_LEN] = '\0';
  2115. for(i=0;i<sizeof(InvalidChar);i++)
  2116. {
  2117. if( NULL != strchr((const char *)UserName, InvalidChar[i] ))
  2118. {
  2119. *pRes = CC_INV_DATA_FIELD;
  2120. return sizeof(*pRes);
  2121. }
  2122. }
  2123. }
  2124. //Don't check duplicated user names for 0xFF, this request is for deleting user
  2125. if(0xFF != pSetUserNameReq->UserName [0])
  2126. {
  2127. //checking for Duplicate user names
  2128. if(CheckForDuplicateUsers(pSetUserNameReq->UserName)==FALSE)
  2129. {
  2130. printf("Duplicate ipmi user!!\n");
  2131. *pRes = CC_INV_DATA_FIELD;
  2132. return sizeof (*pRes);
  2133. }
  2134. }
  2135. /* If User[0] is 0xFF means the user is requested to delete */
  2136. if (0xFF == pSetUserNameReq->UserName [0]) //delete user
  2137. {
  2138. if( (g_BMCInfo.CurrentNoUser > 1) && (0 != pUserInfo->UserId))
  2139. {
  2140. if(pUserInfo->UserStatus == TRUE)
  2141. {
  2142. g_BMCInfo.CurrentNoUser--;
  2143. }
  2144. /* Delete the user both in Volatile & Non Volatile memory*/
  2145. memset (pUserInfo, 0, sizeof (UserInfo_T));
  2146. }
  2147. else
  2148. {
  2149. *pRes = CC_INV_DATA_FIELD ;
  2150. return sizeof (*pRes);
  2151. }
  2152. }
  2153. else if(0 == pUserInfo->UserId) //add user
  2154. {
  2155. /* If First time-if user ID does not exist */
  2156. /* if the user name is set for the first time */
  2157. pUserInfo->UserId = pSetUserNameReq->UserID;
  2158. pUserInfo->UserStatus = TRUE;
  2159. memcpy(pUserInfo->UserName, pSetUserNameReq->UserName, MAX_USERNAME_LEN);
  2160. strcpy(pUserInfo->UserPassword, "123456");
  2161. g_BMCInfo.CurrentNoUser++;
  2162. }
  2163. else if (0 != pUserInfo->UserId)//modifying users
  2164. {
  2165. memcpy (pUserInfo->UserName, pSetUserNameReq->UserName, MAX_USERNAME_LEN);
  2166. }
  2167. FlushUserInfoTbl();
  2168. *pRes = CC_NORMAL;
  2169. return sizeof (*pRes);
  2170. }
  2171. /*---------------------------------------
  2172. * GetUserName
  2173. *---------------------------------------*/
  2174. int
  2175. GetUserName ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  2176. {
  2177. GetUserNameReq_T* pGetUserNameReq = ( GetUserNameReq_T*)pReq;
  2178. GetUserNameRes_T* pGetUserNameRes = ( GetUserNameRes_T*)pRes;
  2179. UserInfo_T* pUserInfo;
  2180. // Check for Reserved bits
  2181. if(pGetUserNameReq->UserID & (BIT7 | BIT6) || (pGetUserNameReq->UserID == 0x00))
  2182. {
  2183. pGetUserNameRes->CompletionCode = CC_INV_DATA_FIELD ;
  2184. return sizeof(*pRes);
  2185. }
  2186. if (pGetUserNameReq->UserID > MAX_USER_NUM)
  2187. {
  2188. /* if user ID exceeded the Max limit */
  2189. pGetUserNameRes->CompletionCode = CC_INV_DATA_FIELD ;
  2190. return sizeof (*pRes);/* Invalied user id */
  2191. }
  2192. pUserInfo = getUserIdInfo(pGetUserNameReq->UserID);
  2193. /* if User is disabled or if User is not created */
  2194. //if user is disabled we dont have to return invalid data field
  2195. //instead we return everything possible about the user
  2196. // if pUserInfo is NULL then nothing in the structure at all
  2197. // pUserInfo being NULL is probably not possible
  2198. // If the signature doesnt match then the useris not yet configured
  2199. // so reasonable to return an error
  2200. if ((NULL == pUserInfo)/* || (pUserInfo->ID != USER_ID)*/)
  2201. {
  2202. /* User with given ID is disabled */
  2203. *pRes = CC_INV_DATA_FIELD;
  2204. return sizeof (*pRes);
  2205. }
  2206. //if we are here then the user is just disabled
  2207. if(FALSE == pUserInfo->UserStatus)
  2208. {
  2209. *pRes = CC_INV_DATA_FIELD;
  2210. return sizeof (*pRes);
  2211. }
  2212. //Err = 0;
  2213. pGetUserNameRes->CompletionCode = CC_NORMAL;
  2214. memcpy (pGetUserNameRes->UserName, pUserInfo->UserName, MAX_USERNAME_LEN);
  2215. return sizeof (GetUserNameRes_T);
  2216. }
  2217. /*---------------------------------------
  2218. * SetUserPassword
  2219. *---------------------------------------*/
  2220. int
  2221. SetUserPassword ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  2222. {
  2223. SetUserPswdReq_T* pSetUserPswdReq = ( SetUserPswdReq_T*)pReq;
  2224. UserInfo_T* pUserInfo;
  2225. uint8_t UserId=0, Operation;
  2226. uint8_t i;
  2227. uint8_t UserPassword[ MAX_PASSWORD_LEN + 1 ] = {0};
  2228. uint8_t InvalidChar[] = { 0x01 , 0x02 , 0x03 , 0x04 ,0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A,
  2229. 0x0B , 0x0C , 0x0D , 0x0E , 0x0F , 0x10 , 0x11 , 0x12 , 0x13 , 0x14,
  2230. 0x15 , 0x16 , 0x17 , 0x18 , 0x19 , 0x1A , 0x1B , 0x1C , 0x1D , 0x1E ,
  2231. 0x1F , 0x7F };
  2232. Operation = pSetUserPswdReq->Operation & 0x03;
  2233. UserId = pSetUserPswdReq->UserID & 0x3F;
  2234. /* Reserved bits checking */
  2235. if((pSetUserPswdReq->UserID & BIT6) || (UserId == 0) || (pSetUserPswdReq->Operation & (BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)))
  2236. {
  2237. *pRes = CC_INV_DATA_FIELD;
  2238. return sizeof (*pRes);
  2239. }
  2240. if (ReqLen == IPMI_15_PASSWORD_LEN)
  2241. {
  2242. memset (pSetUserPswdReq->Password + 16, 0, 4);
  2243. }
  2244. ReqLen -=2;
  2245. if (UserId > MAX_USER_NUM)
  2246. {
  2247. *pRes = CC_INV_DATA_FIELD;
  2248. return sizeof (*pRes); /*User Id exceeded the limit*/
  2249. }
  2250. pUserInfo = getUserIdInfo (UserId);
  2251. if ( NULL == pUserInfo )
  2252. {
  2253. printf ("Invalid User Id \n");
  2254. *pRes = CC_INV_DATA_FIELD;
  2255. return sizeof (*pRes);
  2256. }
  2257. *pRes = CC_NORMAL;
  2258. switch (Operation)
  2259. {
  2260. case DISABLE_USER:
  2261. //here we can disable the user
  2262. if ((pUserInfo->UserStatus == TRUE) && (g_BMCInfo.CurrentNoUser > 1))
  2263. {
  2264. pUserInfo->UserStatus = FALSE;
  2265. g_BMCInfo.CurrentNoUser--;
  2266. FlushUserInfoTbl();
  2267. }
  2268. break;
  2269. case ENABLE_USER:
  2270. /*enable user */
  2271. if ((0 != pUserInfo->UserId) && (0 != pUserInfo->UserName[0]))
  2272. {
  2273. /* if for the first time then Increment the Current user No */
  2274. if ( pUserInfo->UserStatus == FALSE )
  2275. {
  2276. pUserInfo->UserStatus = TRUE;
  2277. g_BMCInfo.CurrentNoUser++;
  2278. FlushUserInfoTbl();
  2279. }
  2280. }
  2281. else
  2282. {
  2283. *pRes = CC_UNSPECIFIED_ERR;
  2284. return sizeof (*pRes);
  2285. }
  2286. break;
  2287. case SET_PASSWORD:
  2288. /*set password */
  2289. if ((0 != pUserInfo->UserId) && (0 != pUserInfo->UserName[0]))
  2290. {
  2291. /*check for special characters*/
  2292. strncpy((char *)UserPassword,(const char *) pSetUserPswdReq->Password, sizeof(pSetUserPswdReq->Password));
  2293. for( i = 0 ; i < sizeof(InvalidChar) ; i++ )
  2294. {
  2295. if( NULL != strchr((const char *)UserPassword, InvalidChar[i] ))
  2296. {
  2297. *pRes = CC_INV_DATA_FIELD;
  2298. return sizeof(*pRes);
  2299. }
  2300. }
  2301. strcpy(pUserInfo->UserPassword, pSetUserPswdReq->Password);
  2302. FlushUserInfoTbl();
  2303. }
  2304. else
  2305. {
  2306. *pRes = CC_INV_DATA_FIELD;
  2307. return sizeof (*pRes);
  2308. }
  2309. break;
  2310. case TEST_PASSWORD:
  2311. memcpy (UserPassword, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
  2312. /*Test Password */
  2313. if ((FALSE == pUserInfo->UserStatus) ||
  2314. (0 != memcmp (UserPassword, pSetUserPswdReq->Password, MAX_PASSWORD_LEN)))
  2315. {
  2316. *pRes = CC_PASSWORD_TEST_FAILED;
  2317. }
  2318. break;
  2319. }
  2320. return sizeof (*pRes);
  2321. }
  2322. ///*---------------------------------------
  2323. //* MasterWriteRead
  2324. //*---------------------------------------*/
  2325. //int
  2326. //MasterWriteRead ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  2327. //{
  2328. // MasterWriteReadReq_T* pMasterWriteReadReq = ( MasterWriteReadReq_T*)pReq;
  2329. // MasterWriteReadRes_T* pMasterWriteReadRes = ( MasterWriteReadRes_T*)pRes;
  2330. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  2331. // uint8_t* OutBuffer;
  2332. // uint8_t* InBuffer;
  2333. // uint8_t ChannelNum, BusID, BusType, SlaveAddr, ReadCount, WriteCount;
  2334. // INT8S BusName[64];
  2335. // int retval = 0;
  2336. // uint8_t OrgReadCount;
  2337. // uint8_t I2CBusId=0;
  2338. // uint8_t DevID = 0; // This will be '0' by Default... /dev/peci0
  2339. // uint8_t Target = 0x30; // This is the Client address. 30h = 48 is Default for CPU0
  2340. // uint8_t Domain = 0; // Multi-Domain support. Default is '0'
  2341. // uint8_t Xmit_Feedback = 0; // If full response is Desired, enable this. Default is '1'
  2342. // uint8_t AWFCS = 0; // Enable AWFCS in the Transmitted packet by Hw. Default is '0'
  2343. // uint8_t Read_Len = 0; // Number of bytes of read back Data from PECI Client
  2344. // uint8_t Write_Len = 0; // Number of bytes of data, host is sending to client
  2345. // uint8_t *Write_Data = NULL; // Pointer to the Data sent by User to the PECI Client
  2346. // uint8_t *Read_Data = NULL; // Pointer to the Data received from PECI Client to be sent to user
  2347. // int ret_val = 0;
  2348. // if(pMasterWriteReadReq->SlaveAddress & BIT0)
  2349. // {
  2350. // *pRes = CC_INV_DATA_FIELD;
  2351. // return sizeof (*pRes);
  2352. // }
  2353. // ReadCount = pMasterWriteReadReq->ReadCount;
  2354. // ChannelNum = GetBits (pMasterWriteReadReq->BusTypeChNo, 0xF0);
  2355. // BusID = GetBits (pMasterWriteReadReq->BusTypeChNo, 0x0E);
  2356. // BusType = GetBits (pMasterWriteReadReq->BusTypeChNo, 0x01);
  2357. // SlaveAddr = (pMasterWriteReadReq->SlaveAddress >> 1);
  2358. // if ((BusType == 0x00 && BusID != 0x00) || ((BusType == 0x01) && (BusID == 0x00)))
  2359. // {
  2360. // *pRes = CC_INV_DATA_FIELD;
  2361. // return sizeof (*pRes);
  2362. // }
  2363. // // Command order:
  2364. // // ipmitool -H <IP> -I lan -U <Username> -P <Password> bus=7 <Slave_Addr> <Read_Len> <Write_Len> <AWFCS> <Domain> <Data>
  2365. // // <bus=7> : Bus# must be 0x07 for comunicating with PECI over IPMI. Other buses are not for this feature
  2366. // // <Slave_Addr> : This is the PECI Client target address.
  2367. // // <Read_Len> : Number of bytes of data to read from the PECI Response
  2368. // // <Write_Len> : Number of bytes of data being written, as per the PECI Spec. Number of Bytes after Domain.
  2369. // // <AWFCS> : 0x01 or 0x00 indicates enabling or disabling of AWFCS feature respectively
  2370. // // <Domain> : 0x01 or 0x00 indicates domain=1 or domain=0 for multi-domain commands respectively
  2371. // // <Data> : Rest of data like Command, and other params as per the PECI Spec.
  2372. // // If BusType is External (0x01) and BusID is 7, then we consider to communicate with PECI
  2373. //
  2374. // if(g_corefeatures.peci_over_ipmi == ENABLED )
  2375. // {
  2376. // if ((BusType & 0x01) && (BusID == 0x07))
  2377. // {
  2378. // DevID = 0;
  2379. // Xmit_Feedback = 0;
  2380. // Target = pMasterWriteReadReq->SlaveAddress;
  2381. // Read_Len = ReadCount;
  2382. // Write_Len = pMasterWriteReadReq->Data[0];
  2383. // AWFCS = pMasterWriteReadReq->Data[1];
  2384. // Domain = pMasterWriteReadReq->Data[2];
  2385. // Write_Data = &pMasterWriteReadReq->Data[3];
  2386. // Read_Data = &pMasterWriteReadRes->Data[0];
  2387. // memset(&pMasterWriteReadRes->Data[0], 0, sizeof(pMasterWriteReadRes->Data));
  2388. //
  2389. // // Call the PECI Generic Handler for passing the command to the PECI Controller
  2390. // if(g_HALPECIHandle[HAL_PECI_COMMAND] != NULL)
  2391. // {
  2392. // ret_val = ((int(*)(char, char, char, char, char, char *, char, char *, char))g_HALPECIHandle[HAL_PECI_COMMAND]) (DevID, Target,
  2393. // Domain, Xmit_Feedback, AWFCS,
  2394. // (char *)Write_Data, Write_Len,
  2395. // (char *)Read_Data, Read_Len );
  2396. // }
  2397. // else
  2398. // {
  2399. // pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  2400. // return sizeof (*pRes);
  2401. // }
  2402. // /* Check if peci issue command operation is success or not */
  2403. // if (ret_val == -1)
  2404. // {
  2405. // pMasterWriteReadRes->CompletionCode = CC_INV_DATA_FIELD;
  2406. // return sizeof (*pRes);
  2407. // }
  2408. // pMasterWriteReadRes->CompletionCode = CC_NORMAL;
  2409. // return (sizeof (*pRes) + ReadCount);
  2410. // }
  2411. // }
  2412. // if(0 ==BusType){
  2413. // if(PRIMARY_IPMB_CHANNEL == ChannelNum)
  2414. // {
  2415. // I2CBusId=pBMCInfo->IpmiConfig.PrimaryIPMBBusNumber;
  2416. // }
  2417. // else if((pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)&&(pBMCInfo->SecondaryIPMBCh == ChannelNum))
  2418. // {
  2419. // I2CBusId=pBMCInfo->IpmiConfig.SecondaryIPMBBusNumber;
  2420. // }else{
  2421. // *pRes = CC_INV_DATA_FIELD;
  2422. // return sizeof (*pRes);
  2423. // }
  2424. // }
  2425. // else
  2426. // {
  2427. // if(BusID==pBMCInfo->IpmiConfig.PrimaryIPMBBusNumber)
  2428. // {
  2429. // *pRes = CC_INV_DATA_FIELD;
  2430. // return sizeof (*pRes);
  2431. // }else if((pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)&&(BusID==pBMCInfo->IpmiConfig.SecondaryIPMBBusNumber))
  2432. // {
  2433. // *pRes = CC_INV_DATA_FIELD;
  2434. // return sizeof (*pRes);
  2435. // }else{
  2436. // I2CBusId=BusID;
  2437. // }
  2438. // }
  2439. // if (ReqLen < 3)
  2440. // {
  2441. // *pRes = CC_REQ_INV_LEN;
  2442. // return sizeof (*pRes);
  2443. // }
  2444. // /* number of bytes to write
  2445. // * = pMasterWriteReadReq length - 3 for Request Data byte -
  2446. // * BusTypeChNo,SlaveAddr,Readcount + 1 byte for address
  2447. // */
  2448. // WriteCount = ReqLen - 3;
  2449. // OutBuffer = (pMasterWriteReadReq->Data);
  2450. // InBuffer = pMasterWriteReadRes->Data;
  2451. // sprintf(BusName,"/dev/i2c%d",I2CBusId);
  2452. // // Save original ReadCount in case we need to modify it
  2453. // OrgReadCount = ReadCount;
  2454. // // If both ReadCount and WriteCount are zero, then force a read of 1 byte.
  2455. // // If we do not do this, the write command will fail.
  2456. // // Having both counts 0 is a way of "pinging" the given device to see if it
  2457. // // is responding to its address.
  2458. //
  2459. // if (ReadCount == 0 && WriteCount == 0)
  2460. // {
  2461. // ReadCount = 1;
  2462. // }
  2463. // if (ReadCount > 0 && WriteCount == 0)
  2464. // {
  2465. // if(g_HALI2CHandle[HAL_I2C_MR] != NULL)
  2466. // {
  2467. // retval = ((int(*)(char *,u8,u8 *,size_t))g_HALI2CHandle[HAL_I2C_MR]) (BusName, SlaveAddr, InBuffer, ReadCount);
  2468. // if (retval < 0)
  2469. // {
  2470. // pMasterWriteReadRes->CompletionCode = (retval & MASTER_RW_ERRCODE);
  2471. // return sizeof (*pRes);
  2472. // }
  2473. // }
  2474. // else
  2475. // {
  2476. // pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  2477. // return sizeof(*pRes);
  2478. // }
  2479. // ReadCount = OrgReadCount;
  2480. // /* copy the bytes read to Response Data */
  2481. // _fmemcpy (pMasterWriteReadRes->Data, InBuffer, ReadCount);
  2482. // }
  2483. // else if(ReadCount > 0 && WriteCount > 0 )
  2484. // {
  2485. // if(g_HALI2CHandle[HAL_I2C_RW] != NULL)
  2486. // {
  2487. // retval = ((int(*)(char *,u8,u8 *,u8 *,size_t,size_t))g_HALI2CHandle[HAL_I2C_RW]) (BusName, SlaveAddr, OutBuffer, InBuffer, WriteCount, ReadCount);
  2488. // if (retval < 0)
  2489. // {
  2490. // pMasterWriteReadRes->CompletionCode = (retval & MASTER_RW_ERRCODE);
  2491. // return sizeof (*pRes);
  2492. // }
  2493. // }
  2494. // else
  2495. // {
  2496. // pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  2497. // return sizeof(*pRes);
  2498. // }
  2499. // ReadCount = OrgReadCount;
  2500. // /* copy the bytes read to Response Data */
  2501. // _fmemcpy (pMasterWriteReadRes->Data, InBuffer, ReadCount);
  2502. // }
  2503. // else
  2504. // {
  2505. // /* No data to read so use master write instead,
  2506. // * otherwise some devices (EEPROM) that have not finished writing
  2507. // * will fail on the read transaction and possibly corrupt data
  2508. // */
  2509. // if(g_HALI2CHandle[HAL_I2C_MW] != NULL)
  2510. // {
  2511. // retval= ((ssize_t(*)(char *,u8,u8 *,size_t))g_HALI2CHandle[HAL_I2C_MW]) (BusName, SlaveAddr, OutBuffer, WriteCount);
  2512. // if(retval < 0)
  2513. // {
  2514. // pMasterWriteReadRes->CompletionCode = (retval & MASTER_RW_ERRCODE);
  2515. // return sizeof (*pRes);
  2516. // }
  2517. // }
  2518. // else
  2519. // {
  2520. // pMasterWriteReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  2521. // return sizeof(*pRes);
  2522. // }
  2523. // }
  2524. // pMasterWriteReadRes->CompletionCode = CC_NORMAL;
  2525. // return (sizeof (*pRes) + ReadCount);
  2526. //}
  2527. //#if 0
  2528. ///*-------------------------------------------
  2529. //* ComputeAuthCode
  2530. //*-------------------------------------------*/
  2531. //void
  2532. //ComputeAuthCode ( uint8_t* pPassword, SessionHdr_T* pSessionHdr,
  2533. // IPMIMsgHdr_T* pIPMIMsg, uint8_t* pAuthCode,
  2534. // uint8_t ChannelType)
  2535. //{
  2536. // if (AUTH_TYPE_PASSWORD == pSessionHdr->AuthType)
  2537. // {
  2538. // _fmemcpy (pAuthCode, pPassword, MAX_PASSWORD_LEN);
  2539. // }
  2540. // else
  2541. // {
  2542. // uint8_t AuthBuf [MAX_AUTH_PARAM_SIZE];
  2543. // uint16_t AuthBufLen = 0;
  2544. // uint8_t IPMIMsgLen = *(( uint8_t*) pIPMIMsg - 1);
  2545. // /* Password */
  2546. // _fmemcpy (AuthBuf, pPassword, MAX_PASSWORD_LEN);
  2547. // AuthBufLen += MAX_PASSWORD_LEN;
  2548. // /* Session ID */
  2549. // _fmemcpy (AuthBuf + AuthBufLen, &pSessionHdr->SessionID, sizeof (uint32_t));
  2550. // AuthBufLen += sizeof (uint32_t);
  2551. // /* IPMI Response Message */
  2552. // _fmemcpy (AuthBuf + AuthBufLen, pIPMIMsg, IPMIMsgLen);
  2553. // AuthBufLen += IPMIMsgLen;
  2554. // if (ChannelType == MULTI_SESSION_CHANNEL)
  2555. // {
  2556. // /* Session Sequence Number */
  2557. // _fmemcpy (AuthBuf + AuthBufLen,
  2558. // &pSessionHdr->SessionSeqNum, sizeof (uint32_t));
  2559. // AuthBufLen += sizeof (uint32_t);
  2560. // }
  2561. // /* Password */
  2562. // _fmemcpy (AuthBuf + AuthBufLen, pPassword, MAX_PASSWORD_LEN);
  2563. // AuthBufLen += MAX_PASSWORD_LEN;
  2564. // switch (pSessionHdr->AuthType)
  2565. // {
  2566. // case AUTH_TYPE_MD2 :
  2567. // AuthCodeCalMD2 (AuthBuf, pAuthCode, AuthBufLen);
  2568. // break;
  2569. // case AUTH_TYPE_MD5 :
  2570. // AuthCodeCalMD5 (AuthBuf, pAuthCode, AuthBufLen);
  2571. // break;
  2572. // default :
  2573. // TDBG ("RMCP: Invalid Authentication Type \n");
  2574. // }
  2575. // }
  2576. //}
  2577. //#endif
  2578. ///*---------------------------------------
  2579. //* GetSystemInfoParam
  2580. //*---------------------------------------*/
  2581. //int
  2582. //GetSystemInfoParam ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  2583. //{
  2584. // GetSystemInfoParamReq_T* pGetSysInfoReq = ( GetSystemInfoParamReq_T*)pReq;
  2585. // GetSystemInfoParamRes_T* pGetSysInfoRes = ( GetSystemInfoParamRes_T* ) pRes ;
  2586. // GetSystemInfoParamOEMRes_T* pGetSysInfoOEMRes = ( GetSystemInfoParamOEMRes_T* ) pRes ;
  2587. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  2588. // SystemInfoConfig_T* pSysInfoCfg;
  2589. // uint8_t resSize = sizeof(pGetSysInfoRes->CompletionCode) + sizeof(pGetSysInfoRes->ParamRevision);
  2590. // uint8_t oem_len;
  2591. // unsigned long oem_addr;
  2592. // // Check for Reserved bits
  2593. // if(pGetSysInfoReq->ParamRev & (BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1 | BIT0))
  2594. // {
  2595. // pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2596. // return sizeof(pGetSysInfoRes->CompletionCode);
  2597. // }
  2598. // pGetSysInfoRes->CompletionCode = CC_NORMAL;
  2599. // /* Fill the param's older Version and the present version */
  2600. // pGetSysInfoRes->ParamRevision = ((PARAM_OLDER_REVISION << 4) & 0xF0 ) | PARAM_PRESENT_REVISION;
  2601. // /* Check for Revision only parameter */
  2602. // if (pGetSysInfoReq->ParamRev & GET_PARAM_REV_ONLY )
  2603. // {
  2604. // if((MAX_APP_CONF_PARAM >= pGetSysInfoReq->ParamSelector))
  2605. // {
  2606. // return resSize;
  2607. // }
  2608. // else if(( NULL != g_PDKHandle[PDK_GETSYSINFOPARAM]) &&
  2609. // ((MIN_SYSINFO_OEM_CONF_PARAM <= pGetSysInfoReq->ParamSelector) && (MAX_SYSINFO_OEM_CONF_PARAM >= pGetSysInfoReq->ParamSelector)))
  2610. // {
  2611. // oem_len = ((int(*)(uint8_t, unsigned long*,int))(g_PDKHandle[PDK_GETSYSINFOPARAM]))(pGetSysInfoReq->ParamSelector, &oem_addr ,BMCInst);
  2612. // if( oem_len == 0)
  2613. // {
  2614. // pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
  2615. // return sizeof(uint8_t);
  2616. // }
  2617. // else
  2618. // return resSize;
  2619. // }
  2620. // else
  2621. // {
  2622. // *pRes = CC_PARAM_NOT_SUPPORTED;
  2623. // return sizeof (*pRes);
  2624. // }
  2625. // }
  2626. // /* Get Systen Info parameters from NVRAM */
  2627. // pSysInfoCfg = &pBMCInfo->SystemInfoConfig;
  2628. // switch(pGetSysInfoReq->ParamSelector)
  2629. // {
  2630. // case SET_IN_PROGRESS_PARAM: /*Parameter 0 volatile*/
  2631. // if( (0x00 != pGetSysInfoReq->SetSelector) || (0x00 != pGetSysInfoReq->BlockSelector) )
  2632. // {
  2633. // pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2634. // return sizeof(pGetSysInfoRes->CompletionCode);
  2635. // }
  2636. // LOCK_BMC_SHARED_MEM(BMCInst);
  2637. // pGetSysInfoRes->SysInfo.SetInProgress = BMC_GET_SHARED_MEM(BMCInst)->m_Sys_SetInProgress;
  2638. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  2639. // resSize++;
  2640. // break;
  2641. // case SYS_FW_VERSION_PARAM:
  2642. // _fmemset(&pGetSysInfoRes->SysInfo.SysVerInfo,0,sizeof(SysVerInfo_T));
  2643. // if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)|| (0x00 != pGetSysInfoReq->BlockSelector))
  2644. // {
  2645. // pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2646. // return sizeof(pGetSysInfoRes->CompletionCode);
  2647. // }
  2648. // pGetSysInfoRes->SysInfo.SysVerInfo.SetSelector = pGetSysInfoReq->SetSelector;
  2649. // resSize++;
  2650. // if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
  2651. // {
  2652. // pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[0]=pSysInfoCfg->SysFWVersion.TypeOfEncoding;
  2653. // pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[1]=pSysInfoCfg->SysFWVersion.StringLength;
  2654. // _fmemcpy(&pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[2], pSysInfoCfg->SysFWVersion.SysFWVersionName,MAX_STRING_LENGTH_COPY);
  2655. // resSize += MAX_BLOCK_SIZE;
  2656. // }
  2657. // else
  2658. // {
  2659. // _fmemcpy(&pGetSysInfoRes->SysInfo.SysVerInfo.SysFWVersion[0],
  2660. // &pSysInfoCfg->SysFWVersion.SysFWVersionName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2],MAX_BLOCK_SIZE);
  2661. // resSize += MAX_BLOCK_SIZE;
  2662. // }
  2663. // break;
  2664. // case SYS_NAME_PARAM:
  2665. // if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)|| (0x00 != pGetSysInfoReq->BlockSelector))
  2666. // {
  2667. // pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2668. // return sizeof(pGetSysInfoRes->CompletionCode);
  2669. // }
  2670. // pGetSysInfoRes->SysInfo.SysNameInfo.SetSelector = pGetSysInfoReq->SetSelector;
  2671. // resSize++;
  2672. // if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
  2673. // {
  2674. // pGetSysInfoRes->SysInfo.SysNameInfo.SysName[0]=pSysInfoCfg->SysName.TypeOfEncoding_Sys_Name;
  2675. // pGetSysInfoRes->SysInfo.SysNameInfo.SysName[1]=pSysInfoCfg->SysName.StringLength_Sys_Name;
  2676. // _fmemcpy(&pGetSysInfoRes->SysInfo.SysNameInfo.SysName[2],&pSysInfoCfg->SysName.SystemName,MAX_STRING_LENGTH_COPY);
  2677. // resSize += MAX_BLOCK_SIZE;
  2678. // }
  2679. // else
  2680. // {
  2681. // _fmemcpy(&pGetSysInfoRes->SysInfo.SysNameInfo.SysName[0],
  2682. // &pSysInfoCfg->SysName.SystemName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2], MAX_BLOCK_SIZE);
  2683. // resSize += MAX_BLOCK_SIZE;
  2684. // }
  2685. // break;
  2686. // case PRIM_OS_NAME_PARAM:
  2687. // if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)|| (0x00 != pGetSysInfoReq->BlockSelector))
  2688. // {
  2689. // pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2690. // return sizeof(pGetSysInfoRes->CompletionCode);
  2691. // }
  2692. // pGetSysInfoRes->SysInfo.PrimOSInfo.SetSelector = pGetSysInfoReq->SetSelector;
  2693. // resSize++;
  2694. // if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
  2695. // {
  2696. // pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[0]=pSysInfoCfg->PrimaryOSName.TypeOfEncoding_PrimaryOSName;
  2697. // pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[1]=pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName;
  2698. // _fmemcpy(&pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[2], &pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName, MAX_STRING_LENGTH_COPY);
  2699. // resSize += MAX_BLOCK_SIZE;
  2700. // }
  2701. // else
  2702. // {
  2703. // _fmemcpy(&pGetSysInfoRes->SysInfo.PrimOSInfo.PrimaryOSName[0],
  2704. // &pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2],MAX_BLOCK_SIZE);
  2705. // resSize += MAX_BLOCK_SIZE;
  2706. // }
  2707. // break;
  2708. // case OS_NAME_PARAM:
  2709. // /*Parameter 4 volatile*/
  2710. // _fmemset(&pGetSysInfoRes->SysInfo.OSInfo,0,sizeof(OSInfo_T));
  2711. // if((pGetSysInfoReq->SetSelector >= MAX_BLOCK_SIZE)||(0x00 != pGetSysInfoReq->BlockSelector))
  2712. // {
  2713. // pGetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2714. // return sizeof(pGetSysInfoRes->CompletionCode);
  2715. // }
  2716. // pGetSysInfoRes->SysInfo.OSInfo.SetSelector = pGetSysInfoReq->SetSelector;
  2717. // resSize++;
  2718. // if(pGetSysInfoReq->SetSelector==ZERO_SETSELECTOR)
  2719. // {
  2720. // LOCK_BMC_SHARED_MEM(BMCInst);
  2721. // pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[0]=BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.TypeOfEncoding_OSName;
  2722. // pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[1]=BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName;
  2723. // _fmemcpy(&pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[2], BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName, MAX_STRING_LENGTH_COPY);
  2724. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  2725. // resSize += MAX_BLOCK_SIZE;
  2726. // }
  2727. // else
  2728. // {
  2729. // LOCK_BMC_SHARED_MEM(BMCInst);
  2730. // _fmemcpy(&pGetSysInfoRes->SysInfo.OSInfo.OperatingSystemName[0],
  2731. // &BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName[(pGetSysInfoReq->SetSelector * MAX_BLOCK_SIZE) - 2],MAX_BLOCK_SIZE);
  2732. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  2733. // resSize += MAX_BLOCK_SIZE;
  2734. // }
  2735. //
  2736. // break;
  2737. // default:
  2738. // if(g_PDKHandle[PDK_GETSYSINFOPARAM] != NULL &&
  2739. // (pGetSysInfoReq->ParamSelector >= 192 && pGetSysInfoReq->ParamSelector <= 255))
  2740. // {
  2741. // oem_len = ((int(*)(uint8_t, unsigned long*,int))(g_PDKHandle[PDK_GETSYSINFOPARAM]))(pGetSysInfoReq->ParamSelector, &oem_addr ,BMCInst);
  2742. // if( oem_len == 0)
  2743. // {
  2744. // pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
  2745. // return sizeof(uint8_t);
  2746. // }
  2747. // else
  2748. // {
  2749. // //Acquire the OEM parameters
  2750. // if( oem_len < MSG_PAYLOAD_SIZE - sizeof(GetLanCCRev_T))
  2751. // {
  2752. // memcpy((char*)pGetSysInfoOEMRes + sizeof(GetSystemInfoParamOEMRes_T) ,\
  2753. // (unsigned int*)oem_addr , oem_len);
  2754. // }
  2755. // else
  2756. // {
  2757. // pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
  2758. // return sizeof(uint8_t);
  2759. // }
  2760. // return sizeof(GetSystemInfoParamOEMRes_T) + oem_len;
  2761. // }
  2762. // }
  2763. // else
  2764. // {
  2765. // pGetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
  2766. // return sizeof(pGetSysInfoRes->CompletionCode);
  2767. // }
  2768. // }
  2769. // /* return the size of the response */
  2770. // return resSize;
  2771. //}
  2772. //int validatestring(uint8_t* String,int len,uint8_t TOE)
  2773. //{
  2774. // int i,delimit = 0,strlen = 0;
  2775. // for(i=0;i<len;i++)
  2776. // {
  2777. // if(String[i] == 0)
  2778. // {
  2779. // delimit++;
  2780. // }
  2781. // else
  2782. // {
  2783. // if(delimit != 0)
  2784. // {
  2785. // if(TOE == UNICODE)
  2786. // {
  2787. // if(delimit == 2)
  2788. // {
  2789. // strlen = strlen + 2;
  2790. // }
  2791. // else
  2792. // {
  2793. // return -1;
  2794. // }
  2795. // }
  2796. // else
  2797. // {
  2798. // if(delimit == 1)
  2799. // {
  2800. // strlen = strlen + 1;
  2801. // }
  2802. // else
  2803. // {
  2804. // return -1;
  2805. // }
  2806. // }
  2807. // delimit = 0;
  2808. // }
  2809. // strlen++;
  2810. // }
  2811. // }
  2812. // return strlen;
  2813. //}
  2814. ///*---------------------------------------
  2815. //* SetSystemInfoParam
  2816. //*---------------------------------------*/
  2817. //int
  2818. //SetSystemInfoParam ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  2819. //{
  2820. // SetSystemInfoParamReq_T* pSetSysInfoReq = ( SetSystemInfoParamReq_T*)pReq;
  2821. // SetSystemInfoParamOEMReq_T* pSetSysInfoOEMReq = ( SetSystemInfoParamOEMReq_T*)pReq;
  2822. // SetSystemInfoParamRes_T* pSetSysInfoRes = ( SetSystemInfoParamRes_T*)pRes;
  2823. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  2824. // SystemInfoConfig_T* pSysInfoCfg;
  2825. // uint8_t *pSetInProgress;
  2826. // unsigned long oem_addr[2]={0}; // use oem_addr[1] as read-only/write-only flag
  2827. // int size,strlen,len;
  2828. // uint8_t OSName[MAX_OS_NAME_LENGTH] = {0};
  2829. // //If the OEM parameter is existing, then skip the length check.
  2830. // if(g_PDKHandle[PDK_SETSYSINFOPARAM] == NULL && (pSetSysInfoReq->ParamSelector < 192 )){
  2831. // if( !( (SET_IN_PROGRESS_PARAM == pSetSysInfoReq->ParamSelector && ( ReqLen == ( sizeof(pSetSysInfoReq->ParamSelector) + sizeof(uint8_t) /* for Data */ ) )) ||
  2832. // ( pSetSysInfoReq->ParamSelector < MAX_PARAM_SELECTOR && ReqLen == ( sizeof(pSetSysInfoReq->ParamSelector) + sizeof(uint8_t) /* for set Selector */ + MAX_BLOCK_SIZE))) )
  2833. // {
  2834. // pSetSysInfoRes->CompletionCode = CC_REQ_INV_LEN;
  2835. // return sizeof(pSetSysInfoRes->CompletionCode);
  2836. // }
  2837. // }
  2838. // pSetInProgress = &BMC_GET_SHARED_MEM(BMCInst)->m_Sys_SetInProgress;
  2839. // pSetSysInfoRes->CompletionCode = CC_NORMAL;
  2840. // /*Get NVRAM System Info Configuration parameters */
  2841. // pSysInfoCfg = &pBMCInfo->SystemInfoConfig;
  2842. // switch (pSetSysInfoReq->ParamSelector)
  2843. // {
  2844. // /*Parameter 0 volatile */
  2845. // case SET_IN_PROGRESS_PARAM:
  2846. // LOCK_BMC_SHARED_MEM(BMCInst);
  2847. // /* If Request for Set In progress */
  2848. // if(( SYS_INFO_SET_IN_PROGRESS == *pSetInProgress ) &&
  2849. // ( SYS_INFO_SET_IN_PROGRESS == pSetSysInfoReq->SysInfo.SetInProgress ))
  2850. // {
  2851. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  2852. // /* Trying to SetinProgress when already in set*/
  2853. // pSetSysInfoRes->CompletionCode = CC_SYS_INFO_SET_IN_PROGRESS ;
  2854. // return sizeof(pSetSysInfoRes->CompletionCode);
  2855. // } else if( SYS_INFO_COMMIT_WRITE == pSetSysInfoReq->SysInfo.SetInProgress )
  2856. // {
  2857. // /* Write SysInfoConfig to NVR */
  2858. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig,
  2859. // pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SystemInfoConfig_T),BMCInst);
  2860. // /* Write volatile data to the BMC Shared memory */
  2861. //
  2862. // } else if ( SYS_INFO_SET_COMPLETE == pSetSysInfoReq->SysInfo.SetInProgress )
  2863. // {
  2864. // //PMCONFIG_FILE(BMCInst,PMConfigFile);
  2865. // /* Set it to set Complete */
  2866. // *pSetInProgress = pSetSysInfoReq->SysInfo.SetInProgress;
  2867. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig,
  2868. // pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SystemInfoConfig_T),BMCInst);
  2869. // } else if ( SYS_INFO_SET_IN_PROGRESS != pSetSysInfoReq->SysInfo.SetInProgress )
  2870. // {
  2871. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  2872. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2873. // return sizeof(pSetSysInfoRes->CompletionCode);
  2874. // }
  2875. // *pSetInProgress = pSetSysInfoReq->SysInfo.SetInProgress;
  2876. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  2877. // break;
  2878. // case SYS_FW_VERSION_PARAM:
  2879. //
  2880. // if(pSetSysInfoReq->SysInfo.SysVerInfo.SetSelector >= MAX_BLOCK_SIZE)
  2881. // {
  2882. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2883. // return sizeof(pSetSysInfoRes->CompletionCode);
  2884. // }
  2885. // if(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector==ZERO_SETSELECTOR)
  2886. // {
  2887. // if(pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]> MAX_FW_VER_LENGTH)
  2888. // {
  2889. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2890. // return sizeof(pSetSysInfoRes->CompletionCode);
  2891. // }
  2892. // if(pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0] > MAX_TYPE_OF_ENCODING)
  2893. // {
  2894. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2895. // return sizeof(pSetSysInfoRes->CompletionCode);
  2896. // }
  2897. // memset(&pSysInfoCfg->SysFWVersion,0,sizeof(pSysInfoCfg->SysFWVersion));
  2898. // pSysInfoCfg->SysFWVersion.TypeOfEncoding=pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0];
  2899. // pSysInfoCfg->SysFWVersion.StringLength=pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1];
  2900. // /*First character should not be a delimiter*/
  2901. // 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)))
  2902. // {
  2903. // *pRes = CC_INV_DATA_FIELD;
  2904. // return sizeof(uint8_t);
  2905. // }
  2906. // strlen = validatestring(&pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0]);
  2907. // if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]) || ((pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]))
  2908. // {
  2909. // *pRes = CC_INV_DATA_FIELD;
  2910. // return sizeof(uint8_t);
  2911. // }
  2912. // if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
  2913. // {
  2914. // *pRes = CC_INV_DATA_FIELD;
  2915. // return sizeof(uint8_t);
  2916. // }
  2917. // _fmemcpy(&pSysInfoCfg->SysFWVersion.SysFWVersionName[0],&pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[2], MAX_STRING_LENGTH_COPY);
  2918. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.SysFWVersion,
  2919. // pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysFWVersion_T),BMCInst);
  2920. // }
  2921. // else
  2922. // {
  2923. // _fmemcpy(&pSysInfoCfg->SysFWVersion.SysFWVersionName[(pSetSysInfoReq->SysInfo.SysVerInfo.SetSelector* MAX_BLOCK_SIZE) - 2],
  2924. // &pSetSysInfoReq->SysInfo.SysVerInfo.SysFWVersion[0],MAX_BLOCK_SIZE);
  2925. // len = ((pSetSysInfoReq->SysInfo.SysVerInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
  2926. // strlen = validatestring(&pSysInfoCfg->SysFWVersion.SysFWVersionName[0],len,pSysInfoCfg->SysFWVersion.TypeOfEncoding);
  2927. // if(strlen == -1 || (strlen > pSysInfoCfg->SysFWVersion.StringLength))
  2928. // {
  2929. // *pRes = CC_INV_DATA_FIELD;
  2930. // return sizeof(uint8_t);
  2931. // }
  2932. // /*Check the String length*/
  2933. // if(((len < pSysInfoCfg->SysFWVersion.StringLength) && (len != strlen)) || ((len > pSysInfoCfg->SysFWVersion.StringLength) && (pSysInfoCfg->SysFWVersion.StringLength != strlen)))
  2934. // {
  2935. // *pRes = CC_INV_DATA_FIELD;
  2936. // return sizeof(uint8_t);
  2937. // }
  2938. // if((len == pSysInfoCfg->SysFWVersion.StringLength) && (pSysInfoCfg->SysFWVersion.StringLength != strlen))
  2939. // {
  2940. // *pRes = CC_INV_DATA_FIELD;
  2941. // return sizeof(uint8_t);
  2942. // }
  2943. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,
  2944. // (uint8_t*)&pBMCInfo->SystemInfoConfig.SysFWVersion,pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysFWVersion_T),BMCInst);
  2945. // }
  2946. // break;
  2947. // case SYS_NAME_PARAM:
  2948. // if(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector >= MAX_BLOCK_SIZE )
  2949. // {
  2950. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2951. // return sizeof(pSetSysInfoRes->CompletionCode);
  2952. // }
  2953. // if(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector==ZERO_SETSELECTOR)
  2954. // {
  2955. // if((pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1] > MAX_SYS_NAME_LENGTH))
  2956. // {
  2957. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2958. // return sizeof(pSetSysInfoRes->CompletionCode);
  2959. // }
  2960. // if(pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0]>MAX_TYPE_OF_ENCODING)
  2961. // {
  2962. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  2963. // return sizeof(pSetSysInfoRes->CompletionCode);
  2964. // }
  2965. // memset(&pSysInfoCfg->SysName,0,sizeof(pSysInfoCfg->SysName));
  2966. // pSysInfoCfg->SysName.TypeOfEncoding_Sys_Name=pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0];
  2967. // pSysInfoCfg->SysName.StringLength_Sys_Name=pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1];
  2968. // /*First character should not be a delimiter*/
  2969. // 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)))
  2970. // {
  2971. // *pRes = CC_INV_DATA_FIELD;
  2972. // return sizeof(uint8_t);
  2973. // }
  2974. // strlen = validatestring(&pSetSysInfoReq->SysInfo.SysNameInfo.SysName[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.SysNameInfo.SysName[0]);
  2975. // if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1]) || ((pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1]))
  2976. // {
  2977. // *pRes = CC_INV_DATA_FIELD;
  2978. // return sizeof(uint8_t);
  2979. // }
  2980. // if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.SysNameInfo.SysName[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
  2981. // {
  2982. // *pRes = CC_INV_DATA_FIELD;
  2983. // return sizeof(uint8_t);
  2984. // }
  2985. // _fmemcpy(&pSysInfoCfg->SysName.SystemName[0], &pSetSysInfoReq->SysInfo.SysNameInfo.SysName[2],MAX_STRING_LENGTH_COPY);
  2986. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.SysName,
  2987. // pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysName_T),BMCInst);
  2988. // }
  2989. // else
  2990. // {
  2991. // _fmemcpy(&pSysInfoCfg->SysName.SystemName[(pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector* MAX_BLOCK_SIZE) - 2],
  2992. // &pSetSysInfoReq->SysInfo.SysNameInfo.SysName,MAX_BLOCK_SIZE);
  2993. // len = ((pSetSysInfoReq->SysInfo.SysNameInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
  2994. // strlen = validatestring(&pSysInfoCfg->SysName.SystemName[0],len,pSysInfoCfg->SysName.TypeOfEncoding_Sys_Name);
  2995. // if(strlen == -1 || (strlen > pSysInfoCfg->SysName.StringLength_Sys_Name))
  2996. // {
  2997. // *pRes = CC_INV_DATA_FIELD;
  2998. // return sizeof(uint8_t);
  2999. // }
  3000. // /*Check the String length*/
  3001. // if(((len < pSysInfoCfg->SysName.StringLength_Sys_Name) && (len != strlen)) || ((len > pSysInfoCfg->SysName.StringLength_Sys_Name) && (pSysInfoCfg->SysName.StringLength_Sys_Name != strlen)))
  3002. // {
  3003. // *pRes = CC_INV_DATA_FIELD;
  3004. // return sizeof(uint8_t);
  3005. // }
  3006. // if((len == pSysInfoCfg->SysName.StringLength_Sys_Name) && (pSysInfoCfg->SysName.StringLength_Sys_Name != strlen))
  3007. // {
  3008. // *pRes = CC_INV_DATA_FIELD;
  3009. // return sizeof(uint8_t);
  3010. // }
  3011. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.SysName,
  3012. // pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(SysName_T),BMCInst);
  3013. // }
  3014. // break;
  3015. // case PRIM_OS_NAME_PARAM:
  3016. // if(pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector >= MAX_BLOCK_SIZE )
  3017. // {
  3018. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  3019. // return sizeof(pSetSysInfoRes->CompletionCode);
  3020. // }
  3021. // if(pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector==ZERO_SETSELECTOR)
  3022. // {
  3023. // if((pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1] > MAX_PRIM_OS_NAME_LENGTH))
  3024. // {
  3025. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  3026. // return sizeof(pSetSysInfoRes->CompletionCode);
  3027. //
  3028. // }
  3029. // if(pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0]>MAX_TYPE_OF_ENCODING)
  3030. // {
  3031. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  3032. // return sizeof(pSetSysInfoRes->CompletionCode);
  3033. // }
  3034. // memset(&pSysInfoCfg->PrimaryOSName,0,sizeof(pSysInfoCfg->PrimaryOSName));
  3035. // pSysInfoCfg->PrimaryOSName.TypeOfEncoding_PrimaryOSName=pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0];
  3036. // pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName=pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1];
  3037. // /*First character should not be a delimiter*/
  3038. // 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)))
  3039. // {
  3040. // *pRes = CC_INV_DATA_FIELD;
  3041. // return sizeof(uint8_t);
  3042. // }
  3043. // strlen = validatestring(&pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[0]);
  3044. // if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1]) || ((pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1]))
  3045. // {
  3046. // *pRes = CC_INV_DATA_FIELD;
  3047. // return sizeof(uint8_t);
  3048. // }
  3049. // if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
  3050. // {
  3051. // *pRes = CC_INV_DATA_FIELD;
  3052. // return sizeof(uint8_t);
  3053. // }
  3054. // _fmemcpy(&pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[0], &pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName[2], MAX_STRING_LENGTH_COPY);
  3055. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,(uint8_t*)&pBMCInfo->SystemInfoConfig.PrimaryOSName,
  3056. // pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(PrimaryOSName_T),BMCInst);
  3057. // }
  3058. // else
  3059. // {
  3060. // _fmemcpy(&pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[(pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector * MAX_BLOCK_SIZE) - 2],
  3061. // &pSetSysInfoReq->SysInfo.PrimOSInfo.PrimaryOSName, MAX_BLOCK_SIZE);
  3062. // len = ((pSetSysInfoReq->SysInfo.PrimOSInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
  3063. // strlen = validatestring(&pSysInfoCfg->PrimaryOSName.PrimaryOperatingSystemName[0],len,pSysInfoCfg->PrimaryOSName.TypeOfEncoding_PrimaryOSName);
  3064. // if(strlen == -1 || (strlen > pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName))
  3065. // {
  3066. // *pRes = CC_INV_DATA_FIELD;
  3067. // return sizeof(uint8_t);
  3068. // }
  3069. // /*Check the String length*/
  3070. // if(((len < pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName) && (len != strlen)) || ((len > pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName) && (pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName != strlen)))
  3071. // {
  3072. // *pRes = CC_INV_DATA_FIELD;
  3073. // return sizeof(uint8_t);
  3074. // }
  3075. // if((len == pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName) && (pSysInfoCfg->PrimaryOSName.StringLength_PrimaryOSName != strlen))
  3076. // {
  3077. // *pRes = CC_INV_DATA_FIELD;
  3078. // return sizeof(uint8_t);
  3079. // }
  3080. // FlushIPMI((uint8_t*)&pBMCInfo->SystemInfoConfig,
  3081. // (uint8_t*)&pBMCInfo->SystemInfoConfig.PrimaryOSName,pBMCInfo->IPMIConfLoc.SystemInfoConfigAddr,sizeof(PrimaryOSName_T),BMCInst);
  3082. // }
  3083. // break;
  3084. // case OS_NAME_PARAM:
  3085. // /*Parameter 4 volatile*/
  3086. // if(pSetSysInfoReq->SysInfo.OSInfo.SetSelector >= MAX_BLOCK_SIZE )
  3087. // {
  3088. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  3089. // return sizeof(pSetSysInfoRes->CompletionCode);
  3090. // }
  3091. // if(pSetSysInfoReq->SysInfo.OSInfo.SetSelector==ZERO_SETSELECTOR)
  3092. // {
  3093. // if(pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1] > MAX_OS_NAME_LENGTH)
  3094. // {
  3095. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  3096. // return sizeof(pSetSysInfoRes->CompletionCode);
  3097. // }
  3098. // if(pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0] > MAX_TYPE_OF_ENCODING)
  3099. // {
  3100. // pSetSysInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  3101. // return sizeof(pSetSysInfoRes->CompletionCode);
  3102. // }
  3103. // /*First character should not be a delimiter*/
  3104. // 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)))
  3105. // {
  3106. // *pRes = CC_INV_DATA_FIELD;
  3107. // return sizeof(uint8_t);
  3108. // }
  3109. // strlen = validatestring(&pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[2],MAX_BLOCK_SIZE-2,pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0]);
  3110. // if(strlen == -1 || (strlen > pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1]) || ((pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1] <= (MAX_BLOCK_SIZE - 2)) && strlen != pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1]))
  3111. // {
  3112. // *pRes = CC_INV_DATA_FIELD;
  3113. // return sizeof(uint8_t);
  3114. // }
  3115. // if(((MAX_BLOCK_SIZE -2) < pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1]) && (strlen != (MAX_BLOCK_SIZE - 2)))
  3116. // {
  3117. // *pRes = CC_INV_DATA_FIELD;
  3118. // return sizeof(uint8_t);
  3119. // }
  3120. // memset(&BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName,0,sizeof(OSName_T));
  3121. // LOCK_BMC_SHARED_MEM(BMCInst);
  3122. // BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.TypeOfEncoding_OSName=pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[0];
  3123. // BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName=pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[1];
  3124. // _fmemcpy(&BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName, &pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName[2],
  3125. // MAX_STRING_LENGTH_COPY);
  3126. // UNLOCK_BMC_SHARED_MEM (BMCInst);
  3127. // }
  3128. // else
  3129. // {
  3130. // LOCK_BMC_SHARED_MEM(BMCInst);
  3131. // _fmemcpy(&OSName[0],&BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName[0],MAX_OS_NAME_LENGTH);
  3132. // _fmemcpy(&OSName[(pSetSysInfoReq->SysInfo.OSInfo.SetSelector * MAX_BLOCK_SIZE) - 2],&pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName,MAX_BLOCK_SIZE);
  3133. // len = ((pSetSysInfoReq->SysInfo.OSInfo.SetSelector* MAX_BLOCK_SIZE) + MAX_BLOCK_SIZE) - 2;
  3134. // strlen = validatestring(&OSName[0],len,BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.TypeOfEncoding_OSName);
  3135. // if(strlen == -1 || (strlen > BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName))
  3136. // {
  3137. // *pRes = CC_INV_DATA_FIELD;
  3138. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  3139. // return sizeof(uint8_t);
  3140. // }
  3141. // /*Check the String length*/
  3142. // 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)))
  3143. // {
  3144. // *pRes = CC_INV_DATA_FIELD;
  3145. // return sizeof(uint8_t);
  3146. // }
  3147. // if((len == BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName) && (BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.StringLength_OSName != strlen))
  3148. // {
  3149. // *pRes = CC_INV_DATA_FIELD;
  3150. // return sizeof(uint8_t);
  3151. // }
  3152. // _fmemcpy(&(BMC_GET_SHARED_MEM(BMCInst)->OperatingSystemName.OSName[(pSetSysInfoReq->SysInfo.OSInfo.SetSelector * MAX_BLOCK_SIZE) - 2]),
  3153. // &pSetSysInfoReq->SysInfo.OSInfo.OperatingSystemName,MAX_BLOCK_SIZE);
  3154. // UNLOCK_BMC_SHARED_MEM (BMCInst);
  3155. // }
  3156. // break;
  3157. // default:
  3158. // if(g_PDKHandle[PDK_SETSYSINFOPARAM] != NULL &&
  3159. // (pSetSysInfoReq->ParamSelector >= 192 && pSetSysInfoReq->ParamSelector <= 255))
  3160. // {
  3161. // oem_addr[0] = (unsigned long)((char*)pSetSysInfoOEMReq + sizeof(SetSystemInfoParamOEMReq_T));
  3162. // size = ((int(*)(uint8_t, unsigned long*,int))(g_PDKHandle[PDK_SETSYSINFOPARAM]))(pSetSysInfoReq->ParamSelector, oem_addr ,BMCInst);
  3163. // if(size <= 0)
  3164. // {
  3165. // switch (oem_addr[1]) {
  3166. // case CC_SYS_INFO_READ_ONLY_PARAM:
  3167. // pSetSysInfoRes->CompletionCode = CC_SYS_INFO_READ_ONLY_PARAM;
  3168. // break;
  3169. // default:
  3170. // pSetSysInfoRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
  3171. // }
  3172. // }
  3173. // else
  3174. // {
  3175. // pSetSysInfoRes->CompletionCode = CC_SYS_INFO_PARAM_NOT_SUPPORTED;
  3176. // return sizeof(pSetSysInfoRes->CompletionCode);
  3177. // }
  3178. // }
  3179. // }
  3180. // return sizeof(pSetSysInfoRes->CompletionCode);
  3181. //}
  3182. #endif /* APP_DEVICE */