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