AppDevice.c 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632
  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. #include "Api.h"
  37. #define USER_ID_ENABLED 0x01
  38. #define USER_ID_DISABLED 0x02
  39. #define OP_USERID_ONLY_LENGTH 2
  40. #define OP_ENABLE_USER_ID 1
  41. #define OP_DISABLE_USER_ID 0
  42. #define BIT3_BIT0_MASK 0xf
  43. #define GET_AUTH_TYPE_MASK 0xc0
  44. #define AUTH_TYPE_V15 0x0
  45. #define AUTH_TYPE_V20 0x40
  46. #define AUTH_CODE_V15_MASK 0x0f
  47. #define AUTH_CODE_V15_1 0x1
  48. #define AUTH_CODE_V15_2 0x2
  49. #define AUTH_CODE_V15_3 0x5
  50. #define AUTH_CODE_V20_MASK 0x3f
  51. #define MIN_AUTH_CODE_V20 0x04
  52. #define MAX_AUTH_CODE_V20 0xc0
  53. #define NULL_USER 1
  54. #define ZERO_SETSELECTOR 0x00
  55. #define MAX_TYPE_OF_ENCODING 0x02
  56. #define MAX_STRING_LENGTH_COPY 14
  57. #define ASCII_LATIN1 0x00
  58. #define UTF_8 0x01
  59. #define UNICODE 0x02
  60. /* Reserved bit macro definitions */
  61. #define RESERVED_BITS_SENDMS 0x03 //(BIT1 | BIT0)
  62. /* Auth code length */
  63. #define HMAC_SHA1_96_LEN 12
  64. #if APP_DEVICE == 1
  65. #define COUNT_INCREASE 1
  66. #define COUNT_DECREASE -1
  67. #define MAX_BT_PKT_LEN 255
  68. /*macro definitions for set user password options*/
  69. #define DISABLE_USER 0
  70. #define ENABLE_USER 1
  71. #define SET_PASSWORD 2
  72. #define TEST_PASSWORD 3
  73. #define MAX_LAN_CHANNELS 1
  74. #define LAN_RMCP_CHANNEL1_TYPE 0x01
  75. #define LAN_RMCP_CHANNEL2_TYPE 0x02
  76. #define LAN_RMCP_CHANNEL3_TYPE 0x03
  77. /*** Global variables ***/
  78. uint8_t g_TmrRunning;
  79. /*** Module variables ***/
  80. static MsgPkt_T m_MsgPkt; /**< Message Packet for posting and retrieving messaged to/from queue */
  81. static uint8_t m_Set_ChReserveBit[] ={0xF0,0x0,0x30};
  82. //extern IfcName_T Ifcnametable[MAX_LAN_CHANNELS];
  83. //static void UpdateCurrentEnabledUserCount(int value, int bmcInstId)
  84. //{
  85. // if (value == 0) return;
  86. // ChannelInfo_T* pChannelInfo = NULL;
  87. // ChannelInfo_T* pNvrChannelInfo = NULL;
  88. // BMCInfo_t* pBMCInfo = &g_BMCInfo[bmcInstId];
  89. // uint8_t maxUserCount = pBMCInfo->IpmiConfig.MaxChUsers;
  90. // uint8_t channelIndex = 0;
  91. // for (channelIndex = 0; channelIndex < MAX_NUM_CHANNELS; channelIndex++)
  92. // {
  93. // if (pBMCInfo->ChConfig[channelIndex].ChType == 0xff) continue;
  94. // pChannelInfo = (ChannelInfo_T*)&pBMCInfo->ChConfig[channelIndex].ChannelInfo;
  95. // if (((value > 0) && ((pChannelInfo->NoCurrentUser + value) > maxUserCount)) ||
  96. // ((value < 0) && ((pChannelInfo->NoCurrentUser + value) < 0)))
  97. // {
  98. // continue;
  99. // }
  100. // pNvrChannelInfo = GetNVRChConfigs(pChannelInfo, bmcInstId);
  101. // pChannelInfo->NoCurrentUser+=value;
  102. // pNvrChannelInfo->NoCurrentUser+=value;
  103. // FlushChConfigs((uint8_t*)pNvrChannelInfo,pNvrChannelInfo->ChannelNumber,bmcInstId);
  104. //}
  105. //}
  106. //static int IsPrivilegeAvailable(uint8_t requestedPrivilege, uint8_t channelNumber, int bmcInstId)
  107. //{
  108. // // PMConfig_T* pPMConfig = ( PMConfig_T*) GetNVRAddr(NVRH_PMCONFIG, bmcInstId);
  109. // BMCInfo_t *pBMCInfo = &g_BMCInfo[bmcInstId];
  110. // uint8_t EthIndex = GetEthIndex(channelNumber & 0x0F, bmcInstId);
  111. // uint8_t privilege = 0x00;
  112. //
  113. // if(0xff == EthIndex) return -1;
  114. //
  115. // //Get requested privilege status (enabled or disabled) from PMConfig by channel
  116. // switch (requestedPrivilege)
  117. // {
  118. // case PRIV_CALLBACK:
  119. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeCallBack;
  120. // break;
  121. //
  122. // case PRIV_USER:
  123. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeUser;
  124. // break;
  125. //
  126. // case PRIV_OPERATOR:
  127. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeOperator;
  128. // break;
  129. //
  130. // case PRIV_ADMIN:
  131. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeAdmin;
  132. // break;
  133. //
  134. // case PRIV_OEM:
  135. // privilege = pBMCInfo->LANCfs[EthIndex].AuthTypeEnables.AuthTypeOem;
  136. // break;
  137. //
  138. // default:
  139. // return -1;
  140. // }
  141. //
  142. // //All bits are 0 that means privilege level is disabled
  143. // return ((privilege != 0x00) ? 0 : -1);
  144. //}
  145. /*-------------------------------------
  146. * ValidateIPMBChksum1
  147. *-------------------------------------*/
  148. /* Function to validate IPMB Checksum1 for SendMessage Cmd */
  149. static int ValidateIPMBChksum1( uint8_t* Data)
  150. {
  151. int i=0;
  152. uint8_t chksum=0;
  153. for (i = 0; i < 3; i++)
  154. {
  155. chksum += *(Data + i);
  156. }
  157. if (chksum != 0)
  158. {
  159. return FALSE;
  160. }
  161. return TRUE;
  162. }
  163. ///*-------------------------------------
  164. //* ResetWDT
  165. //*-------------------------------------*/
  166. //int
  167. //ResetWDT ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  168. //{
  169. // uint8_t u8ExpirationFlag;
  170. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  171. // if (pBMCInfo->Msghndlr.TmrSet == FALSE)
  172. // {
  173. // *pRes = CC_ATTEMPT_TO_RESET_UNIN_WATCHDOG;
  174. // return sizeof (*pRes);
  175. // }
  176. // // save the WDT expiration flag for later use
  177. // u8ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
  178. // /* Reset of Watchdog should not happen once
  179. // once pretimeout interrupt interval is reached*/
  180. // if(pBMCInfo->WDTPreTmtStat == TRUE)
  181. // {
  182. // *pRes = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  183. // return sizeof (*pRes);
  184. // }
  185. // g_WDTTmrMgr.TmrPresent = TRUE;
  186. // g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown;
  187. // g_WDTTmrMgr.PreTimeOutInterval = SEC_TO_MS * pBMCInfo->WDTConfig.PreTimeOutInterval;
  188. // /* if the pre-timeout interrupt is not configured, adjust the pre-timeout interrupt
  189. // timeout value beyound the regular WDT timeout value so that it won't get triggered
  190. // before the WDT timeout. */
  191. // if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
  192. // {
  193. // g_WDTTmrMgr.PreTimeOutInterval = g_WDTTmrMgr.TmrInterval+ 1;
  194. // }
  195. // _fmemcpy (&g_WDTTmrMgr.WDTTmr, &pBMCInfo->WDTConfig, sizeof (WDTConfig_T));
  196. // // restore the WDT expiration flag, don't use the one from the flash
  197. // g_WDTTmrMgr.WDTTmr.ExpirationFlag = u8ExpirationFlag;
  198. // // clear WDT sensor event history
  199. // if( g_corefeatures.internal_sensor == ENABLED )
  200. // RestartWD2Sensor(BMCInst);
  201. // if(g_corefeatures.wdt_flush_support == ENABLED )
  202. // {
  203. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  204. // sizeof(WDTConfig_T),BMCInst);
  205. // }
  206. // if(BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent == FALSE)
  207. // {
  208. // LOCK_BMC_SHARED_MEM(BMCInst);
  209. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=TRUE;
  210. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent=TRUE;
  211. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  212. // sem_post(&g_BMCInfo[BMCInst].WDTSem);
  213. // }
  214. // else
  215. // {
  216. // LOCK_BMC_SHARED_MEM(BMCInst);
  217. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=TRUE;
  218. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent=TRUE;
  219. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  220. // //Set SetWDTUpdated flag to reload initial countdown value.
  221. // g_BMCInfo[BMCInst].SetWDTUpdated = TRUE;
  222. // }
  223. // *pRes = CC_NORMAL;
  224. // return sizeof (*pRes);
  225. //}
  226. ///*---------------------------------------
  227. //* SetWDT
  228. //*---------------------------------------*/
  229. //int
  230. //SetWDT ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  231. //{
  232. // SetWDTReq_T* pSetWDTReq = ( SetWDTReq_T*)pReq;
  233. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  234. // GetMsgFlagsRes_T GetMsgFlagsRes;
  235. //#endif
  236. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  237. // //Check for Reserved bits
  238. // if((pSetWDTReq->TmrUse & (BIT5 | BIT4 | BIT3)) || !(pSetWDTReq->TmrUse & (BIT2 | BIT1 | BIT0)) || ((pSetWDTReq->TmrUse & (BIT1 | BIT2)) == (BIT1 | BIT2)) ||
  239. // (pSetWDTReq->TmrActions & (BIT7 |BIT6 | BIT3 | BIT2)) || (pSetWDTReq->ExpirationFlag & (BIT7 | BIT6 | BIT0)))
  240. // {
  241. // *pRes = CC_INV_DATA_FIELD;
  242. // return sizeof(*pRes);
  243. // }
  244. //#if NO_WDT_PRETIMEOUT_INTERRUPT == 1
  245. // // do not support pre-timeout interrupt
  246. // if (pSetWDTReq->TmrActions & 0x70)
  247. // {
  248. // *pRes = CC_INV_DATA_FIELD;
  249. // return sizeof(*pRes);
  250. // }
  251. //#endif
  252. // pSetWDTReq->InitCountDown = htoipmi_u16(pSetWDTReq->InitCountDown);
  253. // // error out if the pre-timeout interrupt is greater than the initial countdown value
  254. // if (pSetWDTReq->InitCountDown < 10 * pSetWDTReq->PreTimeOutInterval)
  255. // {
  256. // *pRes = CC_INV_DATA_FIELD;
  257. // return sizeof(*pRes);
  258. // }
  259. // // only clear the memory version of the bit(s) when the input bit is set #31175
  260. // g_WDTTmrMgr.WDTTmr.ExpirationFlag &= ~pSetWDTReq->ExpirationFlag;
  261. // pSetWDTReq->ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
  262. // /* Copy the Timer configuration in NVRAM */
  263. // LOCK_BMC_SHARED_MEM(BMCInst);
  264. // _fmemset (( uint8_t*)&pBMCInfo->WDTConfig, 0, sizeof (WDTConfig_T));
  265. // _fmemcpy (( uint8_t*)&pBMCInfo->WDTConfig, ( uint8_t*)pSetWDTReq, sizeof (SetWDTReq_T));
  266. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  267. // if (TRUE ==BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning)
  268. // {
  269. // /* To check wheather Dont stop bit is set or not */
  270. // if (pSetWDTReq->TmrUse & 0x40)
  271. // {
  272. // /* Set the count down value to given value */
  273. // g_WDTTmrMgr.TmrPresent = TRUE;
  274. // LOCK_BMC_SHARED_MEM(BMCInst);
  275. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =TRUE;
  276. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  277. // g_WDTTmrMgr.TmrInterval= pSetWDTReq->InitCountDown;
  278. // g_WDTTmrMgr.PreTimeOutInterval = (SEC_TO_MS * pSetWDTReq->PreTimeOutInterval);
  279. // /* If PreTimeOutInt is set, clear it */
  280. // if (0 != (pSetWDTReq->TmrActions & 0x70))
  281. // {
  282. // pSetWDTReq->TmrActions &= ~0x70;
  283. // }
  284. // else
  285. // {
  286. // // if the pre-timeout interrupt is not configured, adjust the pre-timeout interrupt
  287. // // timeout value beyound the regular WDT timeout value so that it won't get triggered
  288. // // before the WDT timeout.
  289. // g_WDTTmrMgr.PreTimeOutInterval = pSetWDTReq->InitCountDown + 1;
  290. // }
  291. // _fmemcpy (&g_WDTTmrMgr.WDTTmr, pSetWDTReq, sizeof (WDTConfig_T ));
  292. // }
  293. // else
  294. // {
  295. // /* Stop the timer */
  296. // g_WDTTmrMgr.TmrPresent = FALSE;
  297. // LOCK_BMC_SHARED_MEM(BMCInst);
  298. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=FALSE;
  299. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
  300. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  301. // g_WDTTmrMgr.TmrInterval= pSetWDTReq->InitCountDown;
  302. // g_WDTTmrMgr.PreTimeOutInterval = SEC_TO_MS * pSetWDTReq->PreTimeOutInterval;
  303. // // clear WDT sensor event history
  304. // if( g_corefeatures.internal_sensor == ENABLED)
  305. // RestartWD2Sensor(BMCInst);
  306. // }
  307. // /* Clear the pre-timeout interupt flag */
  308. // LOCK_BMC_SHARED_MEM(BMCInst);
  309. // pBMCInfo->WDTConfig.PreTimeoutActionTaken = 0x00;
  310. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x08; /* Clear the flag */
  311. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  312. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  313. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  314. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  315. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  316. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  317. //#else
  318. // if((BMC_GET_SHARED_MEM(BMCInst)->MsgFlags & BIT3_BIT0_MASK) == 0)
  319. //#endif
  320. // {
  321. // /* Clear the SMS_ATN bit */
  322. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  323. // {
  324. // CLEAR_SMS_ATN (0, BMCInst);
  325. // }
  326. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  327. // {
  328. // CLEAR_SMS_ATN (1, BMCInst);
  329. // }
  330. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  331. // {
  332. // CLEAR_SMS_ATN (2, BMCInst);
  333. // }
  334. // }
  335. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  336. // }
  337. // else
  338. // {
  339. // g_WDTTmrMgr.TmrInterval = pSetWDTReq->InitCountDown;
  340. // g_WDTTmrMgr.TmrPresent = FALSE;
  341. // LOCK_BMC_SHARED_MEM(BMCInst);
  342. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
  343. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  344. // // clear WDT sensor event history
  345. // if( g_corefeatures.internal_sensor == ENABLED)
  346. // RestartWD2Sensor(BMCInst);
  347. // }
  348. // // Modify ARP status to resume the thread
  349. // // after receiving set Watchdog Timer command
  350. // //BMC_GET_SHARED_MEM(BMCInst)->GratArpStatus = RESUME_ARPS;
  351. //
  352. // int i = 0;
  353. // for (i = 0; i < MAX_LAN_CHANNELS; i++)
  354. // {
  355. // if((pBMCInfo->LanIfcConfig[i].Enabled == TRUE)
  356. // && (pBMCInfo->LanIfcConfig[i].Up_Status == LAN_IFC_UP))
  357. // {
  358. // BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[i] = RESUME_ARPS;
  359. // UpdateArpStatus(pBMCInfo->LanIfcConfig[i].Ethindex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);
  360. // }
  361. // }
  362. // if(g_corefeatures.wdt_flush_support == ENABLED )
  363. // {
  364. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  365. // sizeof(WDTConfig_T),BMCInst);
  366. // }
  367. // // set the "Don't Log" bit
  368. // g_WDTTmrMgr.WDTTmr.TmrUse &= 0x7F;
  369. // g_WDTTmrMgr.WDTTmr.TmrUse |= (pSetWDTReq->TmrUse & 0x80);
  370. // g_BMCInfo[BMCInst].SetWDTUpdated = TRUE;
  371. // g_BMCInfo[BMCInst].Msghndlr.TmrSet = TRUE;
  372. // pBMCInfo->WDTPreTmtStat = FALSE;
  373. // *pRes = CC_NORMAL;
  374. // return sizeof (*pRes);
  375. //}
  376. ///*---------------------------------------
  377. //* GetWDT
  378. //*---------------------------------------*/
  379. //int
  380. //GetWDT ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  381. //{
  382. // GetWDTRes_T* pGetWDTRes = ( GetWDTRes_T*)pRes;
  383. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  384. // /* Copy the current settings from the NVRAM */
  385. // LOCK_BMC_SHARED_MEM(BMCInst);
  386. // _fmemcpy (( uint8_t*)&pGetWDTRes->CurrentSettings,
  387. // ( uint8_t*)&pBMCInfo->WDTConfig, sizeof (WDTConfig_T));
  388. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  389. // // get the WDT expiration from the global veriable in memory, not from the flash
  390. // pGetWDTRes->CurrentSettings.ExpirationFlag = g_WDTTmrMgr.WDTTmr.ExpirationFlag;
  391. // // get the current "Don't Log" bit
  392. // pGetWDTRes->CurrentSettings.TmrUse &= 0x7F;
  393. // pGetWDTRes->CurrentSettings.TmrUse |= (g_WDTTmrMgr.WDTTmr.TmrUse & 0x80);
  394. // if (TRUE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent)
  395. // {
  396. // // set the WDT running bit #30235/30467
  397. // pGetWDTRes->CurrentSettings.TmrUse |= 0x40;
  398. // /* Present count down in 1/100 of second */
  399. // }
  400. // else
  401. // {
  402. // // clear the WDT running bit #30235/30467 for Timer Use (ie) WatchDog Timer status
  403. // pGetWDTRes->CurrentSettings.TmrUse &= ~0x40;
  404. // pGetWDTRes->CurrentSettings.ExpirationFlag = (pGetWDTRes->CurrentSettings.ExpirationFlag) & 0x3E;
  405. // }
  406. // pGetWDTRes->PresentCountDown = g_WDTTmrMgr.TmrInterval;
  407. // pGetWDTRes->CurrentSettings.InitCountDown = htoipmi_u16(pGetWDTRes->CurrentSettings.InitCountDown);
  408. // pGetWDTRes->CompletionCode = CC_NORMAL;
  409. // return sizeof (GetWDTRes_T);
  410. //}
  411. ///*---------------------------------------
  412. //* SetBMCGlobalEnables
  413. //*---------------------------------------*/
  414. //int
  415. //SetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  416. //{
  417. // uint8_t GblEnblByte = *pReq;
  418. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  419. // MsgPkt_T MsgPkt;
  420. // _fmemset (&MsgPkt, 0, sizeof (MsgPkt_T));
  421. // /* Check For the reserved bit 4 */
  422. // if ( GblEnblByte & BIT4)
  423. // {
  424. // *pRes = CC_INV_DATA_FIELD;
  425. // return sizeof (*pRes);
  426. // }
  427. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  428. // if (((BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables ^ GblEnblByte)) & 0x20)
  429. // {
  430. // /* OEM 0 puts us in ICTS compatibility mode for IPMIv2,
  431. // * Send a message to lan process so it can change behavior
  432. // */
  433. // MsgPkt.Channel = GetLANChannel(0, BMCInst);
  434. // MsgPkt.Param = LAN_ICTS_MODE;
  435. // MsgPkt.Privilege = PRIV_LOCAL;
  436. // if (GblEnblByte & 0x20)
  437. // MsgPkt.Cmd = 1;
  438. // else
  439. // MsgPkt.Cmd = 0;
  440. // PostMsg(&MsgPkt,LAN_IFC_Q,BMCInst);
  441. // }
  442. // BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables = GblEnblByte;
  443. // *pRes = CC_NORMAL;
  444. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  445. // return sizeof (*pRes);
  446. //}
  447. ///*---------------------------------------
  448. //* GetBMCGlobalEnables
  449. //*---------------------------------------*/
  450. //int
  451. //GetBMCGlobalEnables ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  452. //{
  453. // GetBMCGblEnblRes_T* pGetBMCGblEnblRes = ( GetBMCGblEnblRes_T*)pRes;
  454. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  455. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  456. // pGetBMCGblEnblRes->CompletionCode = CC_NORMAL;
  457. // pGetBMCGblEnblRes->BMCGblEnblByte = BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables;
  458. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  459. // return sizeof (GetBMCGblEnblRes_T);
  460. //}
  461. ///*---------------------------------------
  462. //* ClrMsgFlags
  463. //*---------------------------------------*/
  464. //int
  465. //ClrMsgFlags ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  466. //{
  467. // ClearMsgsFlagReq_T* pClearMsgsFlagReq = ( ClearMsgsFlagReq_T*)pReq;
  468. // uint8_t *kcsifcnum;
  469. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  470. // GetMsgFlagsRes_T GetMsgFlagsRes;
  471. //#endif
  472. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  473. // //Check for Reserved bits
  474. // if(pClearMsgsFlagReq->Flag & (BIT4 | BIT2))
  475. // {
  476. // *pRes = CC_INV_DATA_FIELD;
  477. // return sizeof(*pRes);
  478. // }
  479. // OS_THREAD_TLS_GET(g_tls.CurKCSIfcNum,kcsifcnum);
  480. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  481. // /* Flush Receive Message Queue */
  482. // if (0 != (pClearMsgsFlagReq->Flag & 0x01))
  483. // {
  484. // while (0 == GetMsg (&m_MsgPkt, &g_RcvMsgQ[*kcsifcnum][0], WAIT_NONE,BMCInst))
  485. // {
  486. // BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum]--;
  487. // }
  488. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x01; /* Clear the flag */
  489. // }
  490. // /* Flush Event Message Buffer */
  491. // if (0 != (pClearMsgsFlagReq->Flag & 0x02))
  492. // {
  493. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
  494. // while (0 == GetMsg (&m_MsgPkt, EVT_MSG_Q, WAIT_NONE,BMCInst))
  495. // {
  496. // BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg--;
  497. // }
  498. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  499. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x02; /* Clear the flag */
  500. // }
  501. // /* Clear WatchdogTimer Interrupt*/
  502. // if (0 != (pClearMsgsFlagReq->Flag & 0x08))
  503. // {
  504. // /* Clear the pre-timeout interupt flag */
  505. // pBMCInfo->WDTConfig.PreTimeoutActionTaken = 0x00;
  506. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x08; /* Clear the flag */
  507. // if(g_corefeatures.wdt_flush_support == ENABLED )
  508. // {
  509. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  510. // sizeof(WDTConfig_T),BMCInst);
  511. // }
  512. // }
  513. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  514. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  515. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  516. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  517. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  518. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  519. //#else
  520. // if((BMC_GET_SHARED_MEM(BMCInst)->MsgFlags & BIT3_BIT0_MASK) == 0)
  521. //#endif
  522. // {
  523. // /* Clear the SMS_ATN bit */
  524. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  525. // {
  526. // CLEAR_SMS_ATN (0, BMCInst);
  527. // }
  528. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  529. // {
  530. // CLEAR_SMS_ATN (1, BMCInst);
  531. // }
  532. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  533. // {
  534. // CLEAR_SMS_ATN (2, BMCInst);
  535. // }
  536. // }
  537. // *pRes = CC_NORMAL;
  538. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  539. // return sizeof (*pRes);
  540. //}
  541. // /*---------------------------------------
  542. // GetMsgFlags
  543. // ---------------------------------------*/
  544. // int
  545. // GetMsgFlags ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  546. // {
  547. // GetMsgFlagsRes_T* pGetMsgFlagsRes = ( GetMsgFlagsRes_T*)pRes;
  548. // uint8_t *kcsifcnum;
  549. // /* get the message flags */
  550. // pGetMsgFlagsRes->MsgFlags = BMC_GET_SHARED_MEM (BMCInst)->MsgFlags;
  551. // if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg >= EVT_MSG_BUF_SIZE)
  552. // {
  553. // /* If Event MessageBuffer is Full set the BIT */
  554. // pGetMsgFlagsRes->MsgFlags |= 0x02;
  555. // }
  556. // else
  557. // {
  558. // /* else reset the Flag */
  559. // pGetMsgFlagsRes->MsgFlags &= ~0x02;
  560. // }
  561. // if(kcsifcnum != NULL && 0 != BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum])
  562. // {
  563. // /* if any Message in ReceiveMsgQ set the Flag */
  564. // pGetMsgFlagsRes->MsgFlags |= 0x01;
  565. // }
  566. // else
  567. // {
  568. // /* else reset the Flag */
  569. // pGetMsgFlagsRes->MsgFlags &= ~0x01;
  570. // }
  571. // /* get the Pre-Timeout Bits Value & Set it to Response Data */
  572. // //PRETIMEOUT BIT is 3rd bit so changed accordingly
  573. // pGetMsgFlagsRes->MsgFlags |= (pBMCInfo->WDTConfig.PreTimeoutActionTaken & 0x08);
  574. // /* Update the Message flags in shared Mem */
  575. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags |= pGetMsgFlagsRes->MsgFlags;
  576. // pGetMsgFlagsRes->CompletionCode = CC_NORMAL;
  577. // return sizeof (GetMsgFlagsRes_T);
  578. // }
  579. ///*---------------------------------------
  580. //* EnblMsgChannelRcv
  581. //*---------------------------------------*/
  582. //int
  583. //EnblMsgChannelRcv ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  584. //{
  585. // EnblMsgChRcvReq_T* pEnblMsgChRcvReq = ( EnblMsgChRcvReq_T*)pReq;
  586. // EnblMsgChRcvRes_T* pEnblMsgChRcvRes = ( EnblMsgChRcvRes_T*)pRes;
  587. // ChannelInfo_T* pChannelInfo;
  588. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  589. // //Check for Reserved bits
  590. // if(pEnblMsgChRcvReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4))
  591. // {
  592. // pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
  593. // return sizeof(*pRes);
  594. // }
  595. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  596. // pChannelInfo = getChannelInfo (pEnblMsgChRcvReq->ChannelNum & 0x0F, BMCInst);
  597. // TDBG ("ENBL_MSG_CH_RCV: processing..\n");
  598. // if (NULL == pChannelInfo)
  599. // {
  600. // pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
  601. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  602. // return sizeof (*pRes);
  603. // }
  604. // switch (pEnblMsgChRcvReq->ChannelState)
  605. // {
  606. // case 0:
  607. // /* disable Receive Message Queue for this Channel */
  608. // pChannelInfo->ReceiveMsgQ = 0x0;
  609. // break;
  610. // case 1:
  611. // /*enable Recevive Message Queue for this Channel */
  612. // pChannelInfo->ReceiveMsgQ = 0x1;
  613. // break;
  614. // case 2:
  615. // /*get Channel State */
  616. // pEnblMsgChRcvRes->ChannelState = pChannelInfo->ReceiveMsgQ;
  617. // break;
  618. // default:
  619. // pEnblMsgChRcvRes->CompletionCode = CC_INV_DATA_FIELD;
  620. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  621. // return sizeof (*pRes);
  622. // }
  623. // pEnblMsgChRcvRes->CompletionCode = CC_NORMAL;
  624. // /*get Channel Number */
  625. // pEnblMsgChRcvRes->ChannelNum = pEnblMsgChRcvReq->ChannelNum & 0x0F;
  626. // pEnblMsgChRcvRes->ChannelState = pChannelInfo->ReceiveMsgQ;
  627. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  628. // return sizeof (EnblMsgChRcvRes_T);
  629. //}
  630. /*---------------------------------------
  631. * GetMessage
  632. *---------------------------------------*/
  633. int
  634. GetMessage ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  635. {
  636. GetMsgRes_T* pGetMsgRes = ( GetMsgRes_T*)pRes;
  637. uint8_t Index = 0,*kcsifcnum;
  638. #if GET_MSG_FLAGS != UNIMPLEMENTED
  639. GetMsgFlagsRes_T GetMsgFlagsRes;
  640. #endif
  641. printf("GetMessage!\n");
  642. // if (0 != GetMsg (&m_MsgPkt, &g_RcvMsgQ[*kcsifcnum][0], WAIT_NONE))
  643. // {
  644. // /* if Queue is Empty */
  645. // pGetMsgRes->CompletionCode = CC_GET_MSG_QUEUE_EMPTY;
  646. // return sizeof (*pRes);
  647. // }
  648. // #if GET_MSG_FLAGS != UNIMPLEMENTED
  649. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  650. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  651. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  652. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  653. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  654. // #else
  655. // if (0 == BMC_GET_SHARED_MEM (BMCInst)->NumRcvMsg[*kcsifcnum])
  656. // #endif
  657. // {
  658. // /* Clear the SMS_ATN bit */
  659. // CLEAR_SMS_ATN (*kcsifcnum,BMCInst);
  660. // }
  661. // /* Completion Code */
  662. // pGetMsgRes->CompletionCode = CC_NORMAL;
  663. // /* Channel number and privilege level */
  664. // pGetMsgRes->ChannelNum = m_MsgPkt.Channel;
  665. // Index = sizeof (GetMsgRes_T);
  666. // /* First byte should be session handle */
  667. // if(pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01)
  668. // {
  669. // if ((PRIMARY_IPMB_CHANNEL != m_MsgPkt.Channel) && (pBMCInfo->SecondaryIPMBCh != m_MsgPkt.Channel))
  670. // {
  671. // pGetMsgRes->ChannelNum |= m_MsgPkt.Privilege << 0x04;
  672. // pRes [Index++] = m_MsgPkt.Param;
  673. // }
  674. // }
  675. // else
  676. // {
  677. // if(PRIMARY_IPMB_CHANNEL != m_MsgPkt.Channel)
  678. // {
  679. // pGetMsgRes->ChannelNum |= m_MsgPkt.Privilege << 0x04;
  680. // pRes [Index++] = m_MsgPkt.Param;
  681. // }
  682. // }
  683. // /* copy the Message data */
  684. // _fmemcpy (( uint8_t*)&pRes[Index], &m_MsgPkt.Data[1], m_MsgPkt.Size-1);
  685. // IPMI_DBG_PRINT ("GetMsg: Sending the following data through requested channel\n");
  686. // IPMI_DBG_PRINT_BUF (pRes, m_MsgPkt.Size + Index);
  687. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  688. // return ((m_MsgPkt.Size-1)+ Index); /*+ 2 for completion code & channel No. */
  689. return 1;
  690. }
  691. /*---------------------------------------
  692. * SendMessage
  693. *---------------------------------------*/
  694. int
  695. SendMessage ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  696. {
  697. SendMsgReq_T* pSendMsgReq = ( SendMsgReq_T*)pReq;
  698. SendMsgRes_T* pSendMsgRes = ( SendMsgRes_T*)pRes;
  699. IPMIMsgHdr_T* pIPMIMsgHdr;
  700. int Queuefd = 0;
  701. uint8_t Tracking;
  702. uint8_t Channel=0,resaddr=0;
  703. uint8_t ResLen = 1;
  704. uint8_t RetVal = 0;
  705. uint8_t Offset = 1;
  706. uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
  707. uint8_t PBTbl = PRIMARY_PB_TBL;
  708. uint8_t SrcSessionHndl = 0;
  709. ChannelInfo_T* pChannelInfo;
  710. MsgPkt_T ResPkt;
  711. SessionInfo_T* pSessionInfo = NULL;
  712. uint32_t *CurSesID;
  713. uint8_t *curprivlevel,*curchannel,*kcsifcnum;
  714. *pRes = CC_NORMAL;
  715. if (ReqLen < 1)
  716. {
  717. *pRes = CC_REQ_INV_LEN;
  718. return sizeof (*pRes);
  719. }
  720. if(pSendMsgReq->ChNoTrackReq == 0xC0)
  721. {
  722. *pRes = CC_INV_DATA_FIELD;
  723. return sizeof (*pRes);
  724. }
  725. /* Get the channel number */
  726. Channel = pSendMsgReq->ChNoTrackReq & 0x0F;
  727. /* Get Tracking field */
  728. Tracking = pSendMsgReq->ChNoTrackReq >> 6;
  729. if (Tracking == RESERVED_BITS_SENDMS)
  730. {
  731. *pRes = CC_INV_DATA_FIELD;
  732. return sizeof (*pRes);
  733. }
  734. CurSesID = pthread_getspecific(g_tls.CurSessionID);
  735. curchannel = pthread_getspecific(g_tls.CurChannel);
  736. kcsifcnum = pthread_getspecific(g_tls.CurKCSIfcNum);
  737. m_MsgPkt.Param = BRIDGING_REQUEST;
  738. m_MsgPkt.Channel = Channel;
  739. m_MsgPkt.Size = ReqLen - 1; /* -1 to skip channel num */
  740. /* Copy the message data */
  741. memcpy (m_MsgPkt.Data, &pReq[1], m_MsgPkt.Size);
  742. /* Copy the IPMI Message header */
  743. pIPMIMsgHdr = ( IPMIMsgHdr_T*)&m_MsgPkt.Data[Offset - 1];
  744. if(ValidateIPMBChksum1(( uint8_t*)pIPMIMsgHdr) == FALSE)
  745. {
  746. *pRes = CC_INV_DATA_FIELD;
  747. printf("Invalid checksum1\n");
  748. return sizeof (*pRes);
  749. }
  750. if(m_MsgPkt.Data[ReqLen - 2] != CalculateCheckSum2 (( uint8_t*)pIPMIMsgHdr, ReqLen - Offset - 1))
  751. {
  752. *pRes = CC_INV_DATA_FIELD;
  753. return sizeof (*pRes);
  754. }
  755. #if 0
  756. int z;
  757. printf("m_MsgPkt: ");
  758. for(z = 0; z < m_MsgPkt.Size;z++)
  759. printf("%02x ", m_MsgPkt.Data[z]);
  760. printf("\n");
  761. #endif
  762. // printf("---> curchannel: %d, Channel: %d\n", *curchannel, Channel);
  763. if((Channel == PRIMARY_IPMB_CHANNEL) && g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1)
  764. {
  765. //printf ("SendMsg: To Primary IPMB Interface\n");
  766. m_MsgPkt.SrcQ = gFd_PrimaryIpmbIfcQ;
  767. }
  768. else if(( Channel == SECONDARY_IPMB_CHANNEL) && (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 1))
  769. {
  770. //printf ("SendMsg: To Secondary IPMB Interface\n");
  771. m_MsgPkt.SrcQ = gFd_SecondaryIpmbIfcQ;
  772. }
  773. else
  774. {
  775. printf ("SendMsg: Invalid Channel\n");
  776. *pRes = CC_DEST_UNAVAILABLE;
  777. return sizeof (*pRes);
  778. }
  779. if (1 == Tracking)
  780. {
  781. ResLen = 0;
  782. //printf("---> Tracking, curchannel %d, ", *curchannel);
  783. /* Tracking is not required if originator is System ifc */
  784. if (SYS_IFC_CHANNEL == (*curchannel & 0xF))
  785. {
  786. *pRes = CC_INV_DATA_FIELD;
  787. return sizeof (*pRes);
  788. }
  789. if(*curchannel == LAN_RMCP_CHANNEL)
  790. {
  791. pSessionInfo = getSessionInfo (SESSION_ID_INFO, CurSesID);
  792. //printf("SendMEssage/CurSesID %#x, SessionHandle %#x\n", *CurSesID, pSessionInfo->SessionHandle);
  793. if (NULL != pSessionInfo)
  794. {
  795. g_BMCInfo.SessionHandle = pSessionInfo->SessionHandle;
  796. }
  797. else
  798. {
  799. printf("Error: Not get valid session!\n");
  800. *pRes = CC_UNSPECIFIED_ERR;
  801. return sizeof(*pRes);
  802. }
  803. }
  804. PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
  805. //printf("PBTbl %d, g_BMCInfo.SendMsgSeqNum %d, ", PBTbl, g_BMCInfo.SendMsgSeqNum);
  806. /* Store in the table for response tracking */
  807. while(TRUE)
  808. {
  809. if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
  810. {
  811. m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = g_BMCInfo.IpmiConfig.SendMsgTimeout;
  812. m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = (*curchannel & 0xF);
  813. m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc = ORIGIN_SENDMSG;
  814. g_BMCInfo.SendMsgSeqNum = SeqNum;
  815. if (1 != Offset)
  816. {
  817. //TODO:这个貌似没用到?
  818. m_PendingBridgedResTbl[PBTbl][SeqNum].DstSessionHandle = pReq[Offset]; /* Session handle */
  819. }
  820. m_PendingBridgedResTbl[PBTbl][SeqNum].SrcSessionHandle = pSessionInfo->SessionHandle;// SrcSessionHndl;
  821. memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pIPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  822. /* Format the IPMI Msg Hdr */
  823. if(Channel == PRIMARY_IPMB_CHANNEL)
  824. {
  825. pIPMIMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr;
  826. }
  827. else if(Channel == SECONDARY_IPMB_CHANNEL)
  828. {
  829. pIPMIMsgHdr->ReqAddr = g_BMCInfo.SecondaryIPMBAddr;
  830. }
  831. else
  832. {
  833. printf("Invalid channel %d\n", Channel);//pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  834. }
  835. pIPMIMsgHdr->RqSeqLUN = (g_BMCInfo.SendMsgSeqNum << 2) & 0xFC; /* Seq Num and LUN =00 */
  836. /* Recalculate the checksum */
  837. m_MsgPkt.Data[ReqLen - 2] = CalculateCheckSum2 (( uint8_t*)pIPMIMsgHdr, ReqLen - Offset - 1);
  838. if((*curchannel & 0xF) == LAN_RMCP_CHANNEL)
  839. {
  840. m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFd_LanIfcQ;
  841. }
  842. else if((*curchannel & 0xF) == UDS_CHANNEL)
  843. {
  844. m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = gFdUdsIfc;
  845. }
  846. else
  847. {
  848. printf("Not support channel! %d\n", *curchannel);
  849. *pRes = CC_PARAM_OUT_OF_RANGE;
  850. return 1;
  851. }
  852. m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
  853. m_PendingBridgedResTbl[PBTbl][SeqNum].SeqNum = SeqNum;
  854. m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 0;
  855. //printf( "SendMessage SeqNum %d, ", SeqNum);
  856. //memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
  857. break;
  858. }
  859. else
  860. {
  861. SeqNum = (SeqNum + 1) & 0x3F;
  862. if (SeqNum == g_BMCInfo.SendMsgSeqNum) //转了一圈,没有空闲的SeqNum可用。
  863. {
  864. /* If not been added to the Pending Bridge table, an error should be reported back.
  865. If not, for internal channel, the thread calling it may end up waiting! */
  866. *pRes = CC_NODE_BUSY;
  867. return sizeof (*pRes);
  868. }
  869. }
  870. }
  871. }
  872. else
  873. {
  874. pSendMsgRes->CompletionCode = 0xff;
  875. return 1;
  876. }
  877. // printf ("SendMsgCmd:Posting to interface ");
  878. // int y;
  879. // for(y=0;y<m_MsgPkt.Size;y++)
  880. // printf("%#x ", m_MsgPkt.Data[y]);
  881. // printf("\n");
  882. m_MsgPkt.Cmd = PAYLOAD_IPMI_MSG;
  883. /* Post the message to interface */
  884. if (0 != PostMsg (m_MsgPkt.SrcQ, &m_MsgPkt))
  885. {
  886. printf ("Warning: SendMsg Failed to post message to interface queue\n");
  887. }
  888. pSendMsgRes->CompletionCode = CC_NORMAL;
  889. return ResLen;
  890. }
  891. ///*---------------------------------------
  892. //* ReadEvtMsgBuffer
  893. //*---------------------------------------*/
  894. //int
  895. //ReadEvtMsgBuffer ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  896. //{
  897. // ReadEvtMsgBufRes_T* pReadEvtMsgBufRes = ( ReadEvtMsgBufRes_T*)pRes;
  898. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  899. // GetMsgFlagsRes_T GetMsgFlagsRes;
  900. //#endif
  901. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  902. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->BMCMsgMutex,WAIT_INFINITE);
  903. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
  904. // if (-2 == GetMsg(&m_MsgPkt, EVT_MSG_Q, WAIT_NONE, BMCInst))
  905. // {
  906. // /*If queue is empty */
  907. // pReadEvtMsgBufRes->CompletionCode = CC_EVT_MSG_QUEUE_EMPTY;/* Queue is empty */
  908. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  909. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  910. // return sizeof (*pRes);
  911. // }
  912. // if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg == 0)
  913. // {
  914. // pReadEvtMsgBufRes->CompletionCode = CC_EVT_MSG_QUEUE_EMPTY;
  915. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  916. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  917. // return sizeof (*pRes);
  918. // }
  919. // BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg--;
  920. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  921. //#if GET_MSG_FLAGS != UNIMPLEMENTED
  922. // // Clear SMS_ATN bit if and only if the Get Message Flag return 0 in byte 2.
  923. // GetMsgFlags (NULL, 0, (uint8_t *)&GetMsgFlagsRes,BMCInst);
  924. // TDBG("GetMsgFlagsRes.CompletionCode : %X, GetMsgFlagsRes.MsgFlags : %X\n",
  925. // GetMsgFlagsRes.CompletionCode, GetMsgFlagsRes.MsgFlags);
  926. // if (GetMsgFlagsRes.CompletionCode == CC_NORMAL && GetMsgFlagsRes.MsgFlags == 0)
  927. //#else
  928. // if (0 == BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg)
  929. //#endif
  930. // {
  931. // /* if there is no messssage in buffer reset SMS/EVT ATN bit */
  932. // // CLEAR_SMS_ATN ();
  933. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  934. // {
  935. // CLEAR_SMS_ATN (0, BMCInst);
  936. // }
  937. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  938. // {
  939. // CLEAR_SMS_ATN (1, BMCInst);
  940. // }
  941. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  942. // {
  943. // CLEAR_SMS_ATN (2, BMCInst);
  944. // }
  945. // }
  946. // /* clear EventMessageBuffer full flag */
  947. // BMC_GET_SHARED_MEM (BMCInst)->MsgFlags &= ~0x02;
  948. // pReadEvtMsgBufRes->CompletionCode = CC_NORMAL; /* Completion Code */
  949. // /* copy the Message data */
  950. // _fmemcpy (pReadEvtMsgBufRes->ResData, m_MsgPkt.Data, m_MsgPkt.Size);
  951. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->BMCMsgMutex);
  952. // return sizeof (ReadEvtMsgBufRes_T);
  953. //}
  954. ///*---------------------------------------
  955. //* GetBTIfcCap
  956. //*---------------------------------------*/
  957. //int
  958. //GetBTIfcCap ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  959. //{
  960. // GetBTIfcCapRes_T* pGetBTIfcCapRes = ( GetBTIfcCapRes_T*)pRes;
  961. // pGetBTIfcCapRes->CompletionCode = CC_NORMAL;
  962. // pGetBTIfcCapRes->NumReqSupported = 2;
  963. // pGetBTIfcCapRes->InputBufSize = MAX_BT_PKT_LEN;
  964. // pGetBTIfcCapRes->OutputBufSize = MAX_BT_PKT_LEN;
  965. // pGetBTIfcCapRes->RespTime = 1;
  966. // pGetBTIfcCapRes->Retries = 0;
  967. // return sizeof (GetBTIfcCapRes_T);
  968. //}
  969. ///*---------------------------------------
  970. //* GetSystemGUID
  971. //*---------------------------------------*/
  972. //int
  973. //GetSystemGUID ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  974. //{
  975. // GetSysGUIDRes_T* pGetSysGUIDRes = ( GetSysGUIDRes_T*)pRes;
  976. // pGetSysGUIDRes->CompletionCode = CC_NORMAL;
  977. // LOCK_BMC_SHARED_MEM (BMCInst);
  978. // _fmemcpy (&pGetSysGUIDRes->Node, BMC_GET_SHARED_MEM (BMCInst)->SystemGUID, 16);
  979. // UNLOCK_BMC_SHARED_MEM (BMCInst);
  980. // return sizeof (GetSysGUIDRes_T);
  981. //}
  982. #define SUPPORT_IPMI20 0x02
  983. #define SUPPORT_IPMI15 0x01
  984. /*---------------------------------------
  985. * GetChAuthCap
  986. *---------------------------------------*/
  987. int
  988. GetChAuthCap ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  989. {
  990. //TODO: dummy data
  991. // GetChAuthCapReq_T* pGetChAuthCapReq = ( GetChAuthCapReq_T*)pReq;
  992. GetChAuthCapRes_T* pGetChAuthCapRes = ( GetChAuthCapRes_T*)pRes;
  993. pGetChAuthCapRes->CompletionCode = CC_NORMAL;
  994. pGetChAuthCapRes->ChannelNum = LAN_RMCP_CHANNEL;
  995. pGetChAuthCapRes->AuthType = 0x36;
  996. pGetChAuthCapRes->PerMsgUserAuthLoginStatus = 0x04;
  997. pGetChAuthCapRes->ExtCap = 0;
  998. pGetChAuthCapRes->OEMID[0] = 0;
  999. pGetChAuthCapRes->OEMID[1] = 0;
  1000. pGetChAuthCapRes->OEMID[2] = 0;
  1001. pGetChAuthCapRes->OEMAuxData = 0;
  1002. return sizeof (GetChAuthCapRes_T);
  1003. }
  1004. /*---------------------------------------
  1005. * GetSessionChallenge
  1006. * Create session in this function
  1007. *---------------------------------------*/
  1008. int
  1009. GetSessionChallenge ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1010. {
  1011. GetSesChallengeReq_T* pGetSesChalReq = ( GetSesChallengeReq_T*)pReq;
  1012. GetSesChallengeRes_T* pGetSesChalRes = ( GetSesChallengeRes_T*)pRes;
  1013. uint8_t Index;
  1014. uint8_t ChallengeString[CHALLENGE_STR_LEN];
  1015. UserInfo_T *pUserInfo;
  1016. uint32_t TempSessId;
  1017. SessionInfo_T SessionInfo;
  1018. uint8_t *curchannel;
  1019. uint32_t TempRandom;
  1020. if(pGetSesChalReq->UserName[0] == 0)
  1021. {
  1022. pGetSesChalRes->CompletionCode = 0x82;
  1023. return sizeof (*pRes);
  1024. }
  1025. g_BMCInfo.pUserInfo = NULL;
  1026. pUserInfo = getUserNameInfo(pGetSesChalReq->UserName);
  1027. if((pUserInfo == NULL) || (TRUE != pUserInfo->UserStatus))
  1028. {
  1029. pGetSesChalRes->CompletionCode = 0x81;
  1030. return sizeof (*pRes);
  1031. }
  1032. curchannel = pthread_getspecific(g_tls.CurChannel);
  1033. do
  1034. {
  1035. /*generate 32 bit temp session Id*/
  1036. TempSessId = stm32_generate_random32bit();
  1037. } while ((NULL != getSessionInfo (SESSION_ID_INFO, &TempSessId)) || (0 == TempSessId));
  1038. SessionInfo.UserId = (uint8_t)pUserInfo->UserId;
  1039. /*Activated in ActivateSession Command*/
  1040. SessionInfo.Activated = FALSE;
  1041. SessionInfo.AuthType = pGetSesChalReq->AuthType;
  1042. SessionInfo.Channel = *curchannel & 0xF;
  1043. SessionInfo.SessionID = TempSessId;
  1044. SessionInfo.TimeOutValue = g_BMCInfo.IpmiConfig.SessionTimeOut;
  1045. if(GetNumOfUsedSessions() >= g_BMCInfo.IpmiConfig.MaxSession)
  1046. {
  1047. CleanSession();
  1048. }
  1049. /* Add Session information in Table */
  1050. AddSession (&SessionInfo);
  1051. g_BMCInfo.pUserInfo = pUserInfo;
  1052. pGetSesChalRes->CompletionCode = CC_NORMAL;
  1053. pGetSesChalRes->TempSessionID = TempSessId;
  1054. /* generate Randam Challenge String */
  1055. for(Index=0;Index < CHALLENGE_STR_LEN;Index+=4)
  1056. {
  1057. TempRandom = stm32_generate_random32bit();
  1058. // printf("TempRandom: %#lx\n", TempRandom);
  1059. ChallengeString[Index] = TempRandom&0xff;
  1060. ChallengeString[Index+1] = TempRandom>>8;
  1061. ChallengeString[Index+2] = TempRandom>>16;
  1062. ChallengeString[Index+3] = TempRandom>>24;
  1063. }
  1064. memcpy(pGetSesChalRes->ChallengeString, ChallengeString, CHALLENGE_STR_LEN);
  1065. return sizeof (GetSesChallengeRes_T);
  1066. }
  1067. /*---------------------------------------
  1068. * ActivateSession
  1069. *---------------------------------------*/
  1070. int
  1071. ActivateSession ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1072. {
  1073. //TODO: dummy data
  1074. ActivateSesReq_T* pAcvtSesReq = ( ActivateSesReq_T*)pReq;
  1075. ActivateSesRes_T* pAcvtSesRes = ( ActivateSesRes_T*)pRes;
  1076. uint32_t *CurSesID,*curchannel;
  1077. SessionInfo_T* pSessInfo;
  1078. /* Initial Outbound Sequence Number cannot be null */
  1079. if (pAcvtSesReq->OutboundSeq == 0)
  1080. {
  1081. pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_SEQ_OUT_OF_RANGE;
  1082. return sizeof(*pRes);
  1083. }
  1084. CurSesID = pthread_getspecific(g_tls.CurSessionID);
  1085. curchannel = pthread_getspecific(g_tls.CurChannel);
  1086. pSessInfo = getSessionInfo (SESSION_ID_INFO, CurSesID);
  1087. if(pSessInfo == NULL)
  1088. {
  1089. pAcvtSesRes->CompletionCode = CC_ACTIVATE_SESS_INVALID_SESSION_ID;
  1090. return sizeof (*pRes);
  1091. }
  1092. pSessInfo->Activated = TRUE;
  1093. pSessInfo->Channel = (*curchannel & 0xF);
  1094. /* set the Max Privilege allowed for the Session*/
  1095. pSessInfo->MaxPrivilege = pAcvtSesReq->Privilege;
  1096. /* set the Out bound sequensce Number */
  1097. pSessInfo->OutboundSeq = (pAcvtSesReq->OutboundSeq);
  1098. g_BMCInfo.SessionHandle += 1;
  1099. pSessInfo->SessionHandle = g_BMCInfo.SessionHandle;
  1100. pAcvtSesRes->CompletionCode = CC_NORMAL;
  1101. pAcvtSesRes->AuthType = (pSessInfo->AuthType & 0x0F);
  1102. pAcvtSesRes->SessionID = pSessInfo->SessionID;
  1103. pAcvtSesRes->InboundSeq = stm32_generate_random32bit();
  1104. pAcvtSesRes->Privilege = 0x04;
  1105. pSessInfo->InboundRecv = 0xFF;
  1106. pSessInfo->InboundSeq = (pAcvtSesRes->InboundSeq -1);
  1107. return sizeof (ActivateSesRes_T);
  1108. }
  1109. /*---------------------------------------
  1110. * SetSessionPrivLevel
  1111. *---------------------------------------*/
  1112. int
  1113. SetSessionPrivLevel ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1114. {
  1115. SetSesPrivLevelReq_T* pSetSesPrivLevelReq = ( SetSesPrivLevelReq_T*)pReq;
  1116. SetSesPrivLevelRes_T* pSetSesPrivLevelRes = ( SetSesPrivLevelRes_T*)pRes;
  1117. //Check for Reserved bits
  1118. if((pSetSesPrivLevelReq->Privilege == PRIV_LEVEL_CALLBACK) || (pSetSesPrivLevelReq->Privilege > PRIV_LEVEL_PROPRIETARY))
  1119. {
  1120. pSetSesPrivLevelRes->CompletionCode = CC_INV_DATA_FIELD;
  1121. return sizeof(SetSesPrivLevelRes_T);
  1122. }
  1123. /* According to the IPMI 2.0 Priv Level =1 is reserved */
  1124. if((PRIV_USER != pSetSesPrivLevelReq->Privilege) &&
  1125. (PRIV_OPERATOR != pSetSesPrivLevelReq->Privilege) &&
  1126. (PRIV_ADMIN != pSetSesPrivLevelReq->Privilege) &&
  1127. (PRIV_OEM != pSetSesPrivLevelReq->Privilege))
  1128. {
  1129. /*Requested Privilege exceeds ChannelPrivilege Limit */
  1130. pSetSesPrivLevelRes->CompletionCode = CC_INV_DATA_FIELD;
  1131. return sizeof (*pRes);
  1132. }
  1133. pSetSesPrivLevelRes->CompletionCode = CC_NORMAL;
  1134. pSetSesPrivLevelRes->Privilege = pSetSesPrivLevelReq->Privilege;
  1135. return sizeof (SetSesPrivLevelRes_T);
  1136. }
  1137. /*---------------------------------------
  1138. * CloseSession
  1139. *---------------------------------------*/
  1140. int
  1141. CloseSession ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1142. {
  1143. CloseSesReq_T* pCloseSesReq = (CloseSesReq_T*)pReq;
  1144. SessionInfo_T* pSessInfo;
  1145. uint32_t SessionID;
  1146. *pRes = CC_REQ_INV_LEN;
  1147. if ((4 != ReqLen) && (5 != ReqLen))
  1148. {
  1149. return sizeof (*pRes);
  1150. }
  1151. if (0 == pCloseSesReq->SessionID)
  1152. {
  1153. if (5 != ReqLen)
  1154. {
  1155. return sizeof (*pRes);
  1156. }
  1157. SessionID = (uint32_t)pCloseSesReq->SessionHandle;
  1158. *pRes = CC_CLOSE_INVALID_SESSION_ID_HANDLE;
  1159. pSessInfo = getSessionInfo (SESSION_HANDLE_INFO, &SessionID);
  1160. }
  1161. else
  1162. {
  1163. if (4 != ReqLen)
  1164. {
  1165. return sizeof (*pRes);
  1166. }
  1167. SessionID = pCloseSesReq->SessionID;
  1168. *pRes = CC_CLOSE_INVALID_SESSION_ID;
  1169. pSessInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
  1170. }
  1171. if ((NULL == pSessInfo) || (0 == pSessInfo->Activated))
  1172. {
  1173. return sizeof (*pRes);
  1174. }
  1175. /* The SessionInfo is deleted form session table from interface */
  1176. DeleteSession(pSessInfo);
  1177. *pRes = CC_NORMAL;
  1178. return sizeof (*pRes);
  1179. }
  1180. //#if GET_SESSION_INFO != UNIMPLEMENTED
  1181. ///*---------------------------------------
  1182. //* GetSessionInfo
  1183. //*---------------------------------------*/
  1184. //int
  1185. //GetSessionInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  1186. //{
  1187. // GetSesInfoReq_T* pGetSesInfoReq = ( GetSesInfoReq_T*)pReq;
  1188. // GetSesInfoRes_T* pGetSesInfoRes = ( GetSesInfoRes_T*)pRes;
  1189. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1190. // LANSesInfoRes_T LANSesInfo;
  1191. // LANIPv6SesInfoRes_T LANIPv6SesInfo;
  1192. // SessionInfo_T* pSessInfo;
  1193. // ChannelInfo_T* pChannelInfo;
  1194. // void* SessionArg;
  1195. // uint8_t SessionArgAlign[4];
  1196. // uint8_t SessionArgType,EthIndex, netindex = 0xFF;
  1197. // char IfcName[IFNAMSIZ];
  1198. // uint32_t *CurSesID,*curchannel;
  1199. // int i;
  1200. // *pRes = CC_REQ_INV_LEN;
  1201. // switch (pGetSesInfoReq->SessionIndex)
  1202. // {
  1203. // case 0:
  1204. // /* Get session information for this session */
  1205. // if (1 != ReqLen)
  1206. // {
  1207. // return sizeof (*pRes);
  1208. // }
  1209. // SessionArgType = SESSION_ID_INFO;
  1210. // OS_THREAD_TLS_GET(g_tls.CurSessionID,CurSesID);
  1211. // SessionArg = CurSesID;
  1212. // break;
  1213. // case 0xFF:
  1214. // if (5 != ReqLen)
  1215. // {
  1216. // return sizeof (*pRes);
  1217. // }
  1218. // SessionArgType = SESSION_ID_INFO;
  1219. // SessionArgAlign[0] = pGetSesInfoReq->SessionHandleOrID[0];
  1220. // SessionArgAlign[1] = pGetSesInfoReq->SessionHandleOrID[1];
  1221. // SessionArgAlign[2] = pGetSesInfoReq->SessionHandleOrID[2];
  1222. // SessionArgAlign[3] = pGetSesInfoReq->SessionHandleOrID[3];
  1223. // SessionArg = SessionArgAlign;
  1224. // break;
  1225. // case 0xFE:
  1226. // if (2 != ReqLen)
  1227. // {
  1228. // return sizeof (*pRes);
  1229. // }
  1230. // if (pGetSesInfoReq->SessionHandleOrID[0] == 0)
  1231. // {
  1232. // *pRes=CC_INV_DATA_FIELD;
  1233. // return sizeof (*pRes);
  1234. // }
  1235. // SessionArgType = SESSION_HANDLE_INFO;
  1236. // SessionArgAlign[0] = pGetSesInfoReq->SessionHandleOrID[0];
  1237. // SessionArgAlign[1] = pGetSesInfoReq->SessionHandleOrID[1];
  1238. // SessionArgAlign[2] = pGetSesInfoReq->SessionHandleOrID[2];
  1239. // SessionArgAlign[3] = pGetSesInfoReq->SessionHandleOrID[3];
  1240. // SessionArg = SessionArgAlign;
  1241. // break;
  1242. // default:
  1243. // if (1 != ReqLen)
  1244. // {
  1245. // return sizeof (*pRes);
  1246. // }
  1247. // SessionArgType = SESSION_INDEX_INFO;
  1248. // SessionArg = &pGetSesInfoReq->SessionIndex;
  1249. // break;
  1250. // }
  1251. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  1252. // pSessInfo = getSessionInfo (SessionArgType, SessionArg, BMCInst);
  1253. // if (NULL == pSessInfo)
  1254. // {
  1255. // TDBG ("GetSessionInfo: pSessInfo is NULL\n");
  1256. // /* if there is no active channel for the current session Index
  1257. // * return the following bytes
  1258. // */
  1259. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1260. // pChannelInfo = getChannelInfo (*curchannel & 0xF, BMCInst);
  1261. // if(NULL == pChannelInfo)
  1262. // {
  1263. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1264. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1265. // return sizeof (*pRes);
  1266. // }
  1267. // pGetSesInfoRes->CompletionCode = CC_NORMAL;
  1268. // pGetSesInfoRes->SessionHandle = BMC_GET_SHARED_MEM (BMCInst)->SessionHandle;
  1269. // pGetSesInfoRes->NumPossibleActiveSession= pBMCInfo->IpmiConfig.MaxSession;
  1270. // pGetSesInfoRes->NumActiveSession = GetNumOfActiveSessions (BMCInst);
  1271. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1272. // return (sizeof (GetSesInfoRes_T) - sizeof (ActiveSesInfo_T) - sizeof (SessionInfoRes_T));
  1273. // }
  1274. // memset (pGetSesInfoRes,0,sizeof(GetSesInfoRes_T));
  1275. // pChannelInfo = getChannelInfo (pSessInfo->Channel, BMCInst);
  1276. // if(NULL == pChannelInfo)
  1277. // {
  1278. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1279. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1280. // return sizeof (*pRes);
  1281. // }
  1282. // pGetSesInfoRes->CompletionCode = CC_NORMAL;
  1283. // pGetSesInfoRes->SessionHandle = pSessInfo->SessionHandle;
  1284. // pGetSesInfoRes->NumPossibleActiveSession = pBMCInfo->IpmiConfig.MaxSession;
  1285. // pGetSesInfoRes->NumActiveSession = GetNumOfActiveSessions (BMCInst);
  1286. // pGetSesInfoRes->ActiveSesinfo.UserID = pSessInfo->UserId & 0x3F;
  1287. // pGetSesInfoRes->ActiveSesinfo.Privilege = pSessInfo->Privilege & 0x0F;
  1288. // /* Set protocol bit as per Auth Type, bit4 must be 1 for IPMIv2.0 RMCP, 0 for IPMIv1.5 */
  1289. // if( AUTHTYPE_RMCP_PLUS_FORMAT == pSessInfo->AuthType )
  1290. // {
  1291. // pGetSesInfoRes->ActiveSesinfo.ChannelNum = (pSessInfo->Channel & 0x0F) | 0x10;
  1292. // }else
  1293. // {
  1294. // pGetSesInfoRes->ActiveSesinfo.ChannelNum = pSessInfo->Channel & 0x0F;
  1295. // }
  1296. // EthIndex= GetEthIndex(pSessInfo->Channel & 0x0F, BMCInst);
  1297. // if(0xff == EthIndex)
  1298. // {
  1299. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1300. // *pRes = CC_INV_DATA_FIELD;
  1301. // DeleteSession (pSessInfo,BMCInst);
  1302. // return sizeof (uint8_t);
  1303. // }
  1304. // memset(IfcName,0,sizeof(IfcName));
  1305. // /*Get the EthIndex*/
  1306. // if(GetIfcName(EthIndex,IfcName, BMCInst) == -1)
  1307. // {
  1308. // TCRIT("Error in Getting Ifc name\n");
  1309. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1310. // *pRes = CC_INV_DATA_FIELD;
  1311. // return sizeof (uint8_t);
  1312. // }
  1313. // for(i=0;i<sizeof(Ifcnametable)/sizeof(IfcName_T);i++)
  1314. // {
  1315. // if(strcmp(Ifcnametable[i].Ifcname,IfcName) == 0)
  1316. // {
  1317. // netindex= Ifcnametable[i].Index;
  1318. // break;
  1319. // }
  1320. // }
  1321. // if(netindex == 0xFF)
  1322. // {
  1323. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1324. // *pRes = CC_INV_DATA_FIELD;
  1325. // return sizeof (uint8_t);
  1326. // }
  1327. // if (IsLANChannel( pSessInfo->Channel, BMCInst))
  1328. // {
  1329. // if(g_corefeatures.global_ipv6 == ENABLED)
  1330. // {
  1331. // if(GetIPAdrressType(&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[0])==4)
  1332. // {
  1333. // memset(&LANSesInfo,0,sizeof(LANSesInfo));
  1334. // /* IP Address */
  1335. // _fmemcpy (&(LANSesInfo.IPAddress),
  1336. // &pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[sizeof(struct in6_addr)-sizeof(struct in_addr)],
  1337. // sizeof(struct in_addr));
  1338. // /* MAC Address */
  1339. // if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
  1340. // nwGetSrcCacheMacAddr((uint8_t*)&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr[12],
  1341. // netindex, pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
  1342. // _fmemcpy(LANSesInfo.MACAddress, pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
  1343. // /* Port number */
  1344. // LANSesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
  1345. // _fmemcpy ((pRes+sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)),&LANSesInfo, sizeof (LANSesInfoRes_T));
  1346. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1347. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)+sizeof (LANSesInfoRes_T));
  1348. // }
  1349. // else
  1350. // {
  1351. // /* IP Address */
  1352. // memset(&LANIPv6SesInfo,0,sizeof(LANIPv6SesInfo));
  1353. // _fmemcpy (&(LANIPv6SesInfo.IPv6Address),
  1354. // pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr,
  1355. // sizeof(struct in6_addr));
  1356. // /* MAC Address */
  1357. // if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
  1358. // nwGetSrcMacAddr_IPV6((uint8_t*)&pSessInfo->LANRMCPPkt.IPHdr.Srcv6Addr,
  1359. // pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
  1360. // _fmemcpy(LANIPv6SesInfo.MACAddress, pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
  1361. // /* Port number */
  1362. // LANIPv6SesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
  1363. // _fmemcpy ((pRes+sizeof (GetSesInfoRes_T) - sizeof(SessionInfoRes_T)),&LANIPv6SesInfo, sizeof (LANIPv6SesInfoRes_T));
  1364. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1365. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T)+sizeof (LANIPv6SesInfoRes_T));
  1366. // }
  1367. // }
  1368. // else
  1369. // {
  1370. // /* IP Address */
  1371. // _fmemcpy (pGetSesInfoRes->SesInfo.LANSesInfo.IPAddress,
  1372. // pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr,
  1373. // sizeof (pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr));
  1374. // /* MAC Address */
  1375. // if(pSessInfo->LANRMCPPkt.MACHdr.DestAddr[0] == 0)
  1376. // nwGetSrcCacheMacAddr((uint8_t*)pSessInfo->LANRMCPPkt.IPHdr.Srcv4Addr, netindex,
  1377. // pSessInfo->LANRMCPPkt.MACHdr.DestAddr);
  1378. // _fmemcpy(pGetSesInfoRes->SesInfo.LANSesInfo.MACAddress,
  1379. // pSessInfo->LANRMCPPkt.MACHdr.DestAddr, MAC_ADDR_LEN);
  1380. // /* Port number */
  1381. // pGetSesInfoRes->SesInfo.LANSesInfo.PortNumber = pSessInfo->LANRMCPPkt.UDPHdr.SrcPort;
  1382. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1383. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T) + sizeof (LANSesInfoRes_T));
  1384. // }
  1385. // }
  1386. // else if (pBMCInfo->IpmiConfig.SerialIfcSupport == 1 && pBMCInfo->SERIALch== pSessInfo->Channel)
  1387. // {
  1388. // pChannelInfo = getChannelInfo (pBMCInfo->SERIALch, BMCInst);
  1389. // if(NULL == pChannelInfo)
  1390. // {
  1391. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1392. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1393. // return sizeof (*pRes);
  1394. // }
  1395. // pGetSesInfoRes->SesInfo.SerialSesInfo.SessionActivityType = 0;
  1396. // pGetSesInfoRes->SesInfo.SerialSesInfo.DestinationSelector = 0;
  1397. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1398. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T) + sizeof (SerialSesInfoRes_T));
  1399. // }
  1400. // else
  1401. // {
  1402. // pChannelInfo = getChannelInfo(pSessInfo->Channel, BMCInst);
  1403. // if(NULL == pChannelInfo)
  1404. // {
  1405. // pGetSesInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1406. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1407. // return sizeof (*pRes);
  1408. // }
  1409. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1410. // return (sizeof (GetSesInfoRes_T) - sizeof (SessionInfoRes_T));
  1411. // }
  1412. //}
  1413. //#endif
  1414. ///**
  1415. // * @fn GetAuthCodeForTypeV15
  1416. // * @brief This function will use the encryption technique supported
  1417. // * in IPMI V1.5 in order to produce Auth Code.
  1418. // * @param[in] pUserInfo - Pointer to User info structure.
  1419. // * @param[in] pGetAuthCodeReq - Pointer to the structure of request data
  1420. // * @param[out] pGetAuthCodeRes - Pointer to the resultant data.
  1421. // * @retval size of the result data.
  1422. // */
  1423. //static int
  1424. //GetAuthCodeForTypeV15 (UserInfo_T* pUserInfo,
  1425. // GetAuthCodeReq_T* pGetAuthCodeReq,
  1426. // GetAuthCodeRes_T* pGetAuthCodeRes )
  1427. //{
  1428. // uint8_t AuthCode;
  1429. // uint8_t InBuffer[2*IPMI15_MAX_PASSWORD_LEN + HASH_DATA_LENGTH];
  1430. // char UserPswd[MAX_PASSWD_LEN];
  1431. // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  1432. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1433. // memset(&(pGetAuthCodeRes->AuthCode), 0, AUTH_CODE_HASH_LEN);
  1434. // AuthCode = pGetAuthCodeReq->AuthType & AUTH_CODE_V15_MASK;
  1435. // if((pGetAuthCodeReq->AuthType & (BIT5 | BIT4)) ||
  1436. // (AuthCode == AUTHTYPE_RESERVED) || (AuthCode == AUTHTYPE_NONE) ||
  1437. // (AuthCode == AUTHTYPE_STRAIGHT_PASSWORD) ||
  1438. // (AuthCode > AUTHTYPE_OEM_PROPRIETARY))
  1439. // {
  1440. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1441. // return (sizeof (GetAuthCodeRes_T) - 4);
  1442. // }
  1443. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1444. // {
  1445. // /* Get Encryption Key from the MBMCInfo_t structure */
  1446. // LOCK_BMC_SHARED_MEM(BMCInst);
  1447. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  1448. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1449. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  1450. // {
  1451. // TCRIT("Error in decrypting the IPMI User password for User ID:%d.\n", pUserInfo->UserId);
  1452. // pGetAuthCodeRes->CompletionCode = CC_UNSPECIFIED_ERR;
  1453. // return sizeof(*pGetAuthCodeRes);
  1454. // }
  1455. // memcpy(&InBuffer[0],UserPswd,IPMI15_MAX_PASSWORD_LEN);
  1456. // }
  1457. // else
  1458. // {
  1459. // memcpy(&InBuffer[0],pUserInfo->UserPassword,IPMI15_MAX_PASSWORD_LEN);
  1460. // }
  1461. // LOCK_BMC_SHARED_MEM(BMCInst);
  1462. // switch (AuthCode)
  1463. // {
  1464. // #if 0 // As per IPMIv2 Markup E4, Straight Password key is Reserved
  1465. // case AUTH_TYPE_PASSWORD: /* Straight password */
  1466. // if (0 == _fmemcmp (pUserInfo->UserPassword,pGetAuthCodeReq->HashData,IPMI15_MAX_PASSWORD_LEN))
  1467. // {
  1468. // _fmemcpy (pGetAuthCodeRes->AuthCode, "OK", 2);
  1469. // }
  1470. // else
  1471. // {
  1472. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1473. // }
  1474. // break;
  1475. // #endif
  1476. // case AUTH_TYPE_MD2: /* MD2 */
  1477. // _fmemcpy (&InBuffer[IPMI15_MAX_PASSWORD_LEN],
  1478. // pGetAuthCodeReq->HashData, HASH_DATA_LENGTH);
  1479. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1480. // {
  1481. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1482. // UserPswd, IPMI15_MAX_PASSWORD_LEN);
  1483. // }
  1484. // else
  1485. // {
  1486. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1487. // pUserInfo->UserPassword, IPMI15_MAX_PASSWORD_LEN);
  1488. // }
  1489. // AuthCodeCalMD2 (InBuffer, pGetAuthCodeRes->AuthCode, sizeof (InBuffer));
  1490. // break;
  1491. // case AUTH_TYPE_MD5: /* MD5 */
  1492. // _fmemcpy (&InBuffer[IPMI15_MAX_PASSWORD_LEN],
  1493. // pGetAuthCodeReq->HashData, HASH_DATA_LENGTH);
  1494. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1495. // {
  1496. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1497. // UserPswd,IPMI15_MAX_PASSWORD_LEN);
  1498. // }
  1499. // else
  1500. // {
  1501. // _fmemcpy(&InBuffer[IPMI15_MAX_PASSWORD_LEN+HASH_DATA_LENGTH],
  1502. // pUserInfo->UserPassword,IPMI15_MAX_PASSWORD_LEN);
  1503. // }
  1504. // AuthCodeCalMD5 (InBuffer, pGetAuthCodeRes->AuthCode, sizeof (InBuffer));
  1505. // break;
  1506. // default:
  1507. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1508. // }
  1509. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1510. // // IPMI V1.5 AuthCode is only 16 byte.
  1511. // return (sizeof (GetAuthCodeRes_T) - 4);
  1512. //}
  1513. ///**
  1514. // * @fn GetAuthCodeForTypeV20
  1515. // * @brief This function will use the encryption technique supported
  1516. // * in IPMI V2.0 in order to produce Auth Code.
  1517. // * @param[in] pUserInfo - Pointer to User info structure.
  1518. // * @param[in] pGetAuthCodeReq - Pointer to the structure of request data
  1519. // * @param[out] pGetAuthCodeRes - Pointer to the resultant data.
  1520. // * @retval size of the result data.
  1521. // */
  1522. //static int
  1523. //GetAuthCodeForTypeV20 (UserInfo_T* pUserInfo,
  1524. // GetAuthCodeReq_T* pGetAuthCodeReq,
  1525. // GetAuthCodeRes_T* pGetAuthCodeRes )
  1526. //{
  1527. // uint8_t AuthCode;
  1528. // uint8_t UserPasswdLen=0;
  1529. // uint8_t DecVal = 0;
  1530. // uint8_t m_SIK [SESSION_INTEGRITY_KEY_SIZE];
  1531. // char UserPswd[MAX_PASSWD_LEN];
  1532. // unsigned char PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  1533. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1534. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1535. // {
  1536. // /* Get Encryption Key from the MBMCInfo_t structure */
  1537. // LOCK_BMC_SHARED_MEM(BMCInst);
  1538. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  1539. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1540. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pUserInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  1541. // {
  1542. // TCRIT("\nError in decrypting the IPMI User password for user with ID:%d.\n", pUserInfo->UserId);
  1543. // pGetAuthCodeRes->CompletionCode = CC_UNSPECIFIED_ERR;
  1544. // return sizeof (*pGetAuthCodeRes);
  1545. // }
  1546. // }
  1547. // else
  1548. // {
  1549. // memcpy(&UserPswd, pUserInfo->UserPassword, MAX_PASSWD_LEN);
  1550. // }
  1551. // /* Calculate password length */
  1552. // UserPasswdLen = _fstrlen (( char*)UserPswd);
  1553. // UserPasswdLen = (UserPasswdLen > MAX_PASSWORD_LEN) ?
  1554. // MAX_PASSWORD_LEN : UserPasswdLen;
  1555. // memset(&(pGetAuthCodeRes->AuthCode), 0, AUTH_CODE_HASH_LEN);
  1556. // AuthCode = pGetAuthCodeReq->AuthType & AUTH_CODE_V20_MASK;
  1557. // /* Validate the Auth Code */
  1558. // if ((AuthCode > MIN_AUTH_CODE_V20) && (AuthCode < MAX_AUTH_CODE_V20))
  1559. // {
  1560. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1561. // return sizeof(GetAuthCodeRes_T);
  1562. // }
  1563. // LOCK_BMC_SHARED_MEM(BMCInst);
  1564. // switch(AuthCode)
  1565. // {
  1566. // case AUTH_NONE: /* none */
  1567. // TDBG ("\nInside AUTH_NONE in GetAuthCode");
  1568. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1569. // break;
  1570. // case AUTH_HMAC_SHA1_96: /* HMAC-SHA1-96 */
  1571. // TDBG ("\nInside AUTH_HMAC_SHA1_96 in GetAuthCode");
  1572. // hmac_sha1 ((uint8_t *)UserPswd, UserPasswdLen,
  1573. // (uint8_t *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1574. // (uint8_t *)m_SIK, SESSION_INTEGRITY_KEY_SIZE);
  1575. // hmac_sha1 ((uint8_t *)m_SIK, SESSION_INTEGRITY_KEY_SIZE,
  1576. // (uint8_t *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1577. // (uint8_t *)&(pGetAuthCodeRes->AuthCode), HMAC_SHA1_96_LEN);
  1578. // DecVal = AUTH_CODE_HASH_LEN - HMAC_SHA1_96_LEN;
  1579. // break;
  1580. // case AUTH_HMAC_MD5_128: /* HMAC-MD5-128 */
  1581. // TDBG ("\nInside AUTH_HMAC_MD5_128 in GetAuthCode");
  1582. // hmac_md5 ((unsigned char*)UserPswd, UserPasswdLen,
  1583. // pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1584. // m_SIK, SESSION_HMAC_MD5_I_KEY_SIZE);
  1585. // hmac_md5 (m_SIK, SESSION_HMAC_MD5_I_KEY_SIZE,
  1586. // pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1587. // (unsigned char *)&(pGetAuthCodeRes->AuthCode),
  1588. // SESSION_HMAC_MD5_I_KEY_SIZE);
  1589. // DecVal = AUTH_CODE_HASH_LEN - SESSION_HMAC_MD5_I_KEY_SIZE;
  1590. // break;
  1591. // case AUTH_MD5_128: /* MD5-128 */
  1592. // TDBG ("\nInside AUTH_MD5_128 in GetAuthCode");
  1593. // MD5_128 ((char *)UserPswd, UserPasswdLen,
  1594. // (char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1595. // (char *)m_SIK, SESSION_MD5_KEY_SIZE);
  1596. // MD5_128 ((char *)m_SIK, SESSION_INTEGRITY_KEY_SIZE,
  1597. // (char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1598. // (char *)&(pGetAuthCodeRes->AuthCode), SESSION_MD5_KEY_SIZE);
  1599. // DecVal = AUTH_CODE_HASH_LEN - SESSION_MD5_KEY_SIZE;
  1600. // break;
  1601. // case AUTH_HMAC_SHA256_128: /* HMAC-SHA256-128 */
  1602. // TDBG ("\nInside AUTH_HMAC_SHA256_128 in GetAuthCode");
  1603. // hmac_sha256 ((unsigned char *)UserPswd, UserPasswdLen,
  1604. // (unsigned char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1605. // (unsigned char *)m_SIK, SHA2_HASH_KEY_SIZE);
  1606. // hmac_sha256 (m_SIK, SHA2_HASH_KEY_SIZE,
  1607. // (unsigned char *)pGetAuthCodeReq->HashData, HASH_DATA_LEN,
  1608. // (unsigned char *)&(pGetAuthCodeRes->AuthCode), HMAC_SHA256_128_LEN);
  1609. // DecVal = AUTH_CODE_HASH_LEN - HMAC_SHA256_128_LEN;
  1610. // break;
  1611. // //! TODO: Need support in openssl.
  1612. // default: /* OEM or Reserved */
  1613. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1614. // }
  1615. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  1616. // if (DecVal > sizeof(GetAuthCodeRes_T))
  1617. // return sizeof(GetAuthCodeRes_T);
  1618. // else
  1619. // return (sizeof(GetAuthCodeRes_T) - DecVal);
  1620. //}
  1621. ///**
  1622. // * @fn GetAuthCode
  1623. // * @brief This function will encrypt the given 16 byte data with
  1624. // * the algorithm given and return Auth Code.
  1625. // * @param[in] pReq - Request data.
  1626. // * @param[in] ReqLen - Length of the request data.
  1627. // * @param[out] pRes - Result data
  1628. // * @retval size of the result data.
  1629. // */
  1630. //int
  1631. //GetAuthCode ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes )
  1632. //{
  1633. // GetAuthCodeReq_T* pGetAuthCodeReq = ( GetAuthCodeReq_T*)pReq;
  1634. // GetAuthCodeRes_T* pGetAuthCodeRes = ( GetAuthCodeRes_T*)pRes;
  1635. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  1636. // UserInfo_T* pUserInfo;
  1637. // uint8_t AuthType,*curchannel;
  1638. // ChannelInfo_T* pChannelInfo;
  1639. // int nRetSize = 0;
  1640. // /* Check for Reserved Bits */
  1641. // if((pGetAuthCodeReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4)) ||
  1642. // (pGetAuthCodeReq->UserID & (BIT7 | BIT6)))
  1643. // {
  1644. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1645. // return sizeof(*pRes);
  1646. // }
  1647. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  1648. // /* Validate the channel number given */
  1649. // if (CURRENT_CHANNEL_NUM == pGetAuthCodeReq->ChannelNum)
  1650. // {
  1651. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1652. // pChannelInfo = getChannelInfo(*curchannel & 0xF,BMCInst);
  1653. // }
  1654. // else
  1655. // pChannelInfo = getChannelInfo(pGetAuthCodeReq->ChannelNum,BMCInst);
  1656. // if (NULL == pChannelInfo)
  1657. // {
  1658. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1659. // *pRes = CC_INV_DATA_FIELD;
  1660. // return sizeof(*pRes);
  1661. // }
  1662. // /* Get the user information for the given userID */
  1663. // pUserInfo = getUserIdInfo (pGetAuthCodeReq->UserID,BMCInst);
  1664. // if (NULL == pUserInfo)
  1665. // {
  1666. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1667. // TDBG ("AppDevice.c : GetAuthCode - Invalid user Id\n");
  1668. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1669. // return sizeof (*pRes);
  1670. // }
  1671. // AuthType = pGetAuthCodeReq->AuthType & GET_AUTH_TYPE_MASK;
  1672. // pGetAuthCodeRes->CompletionCode = CC_NORMAL;
  1673. // switch(AuthType)
  1674. // {
  1675. // case AUTH_TYPE_V15: /* IPMI v1.5 AuthCode Algorithms */
  1676. // nRetSize = GetAuthCodeForTypeV15(pUserInfo, pGetAuthCodeReq, pGetAuthCodeRes,BMCInst);
  1677. // break;
  1678. // case AUTH_TYPE_V20: /* IPMI v2.0/RMCP+ Algorithm Number */
  1679. // nRetSize = GetAuthCodeForTypeV20(pUserInfo, pGetAuthCodeReq, pGetAuthCodeRes,BMCInst);
  1680. // break;
  1681. // default:
  1682. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1683. // pGetAuthCodeRes->CompletionCode = CC_INV_DATA_FIELD;
  1684. // return sizeof(*pRes);
  1685. // }
  1686. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1687. // return nRetSize;
  1688. //}
  1689. ///*---------------------------------------
  1690. //* SetChAccess
  1691. //*---------------------------------------*/
  1692. //int
  1693. //SetChAccess ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  1694. //{
  1695. // SetChAccessReq_T* pSetChAccessReq = ( SetChAccessReq_T*)pReq;
  1696. // uint8_t ChannelNum, AccessMode;
  1697. // ChannelInfo_T* pNvrChInfo;
  1698. // ChannelInfo_T* pChannelInfo;
  1699. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1700. // uint8_t AccessFlags = 0,i=0,*curchannel;
  1701. //// char ChFilename[MAX_CHFILE_NAME];
  1702. // /* Reserve Bit Checking for Set Channel Acces */
  1703. // for(i=0;i<ReqLen;i++)
  1704. // {
  1705. // if( 0 != (pReq[i] & m_Set_ChReserveBit[i]))
  1706. // {
  1707. // *pRes = CC_INV_DATA_FIELD;
  1708. // return sizeof (*pRes);
  1709. // }
  1710. // }
  1711. // /* Reserve Value checking */
  1712. // if((pReq[1] & 0xC0)== 0xC0 || (pReq[2] & 0xC0) == 0xC0)
  1713. // {
  1714. // *pRes = CC_INV_DATA_FIELD;
  1715. // return sizeof (*pRes);
  1716. // }
  1717. // ChannelNum = pSetChAccessReq->ChannelNum & 0x0F;
  1718. // if (CURRENT_CHANNEL_NUM == ChannelNum)
  1719. // {
  1720. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1721. // ChannelNum = *curchannel & 0xF;
  1722. // }
  1723. // if (((GetBits (pSetChAccessReq->Privilege, 0x0F)) < PRIV_LEVEL_CALLBACK) ||
  1724. // ((GetBits (pSetChAccessReq->Privilege, 0x0F)) > PRIV_LEVEL_PROPRIETARY))
  1725. // {
  1726. // IPMI_DBG_PRINT_1 ("Invalid Channel Privilege = 0x%x\n", pSetChAccessReq->Privilege);
  1727. // *pRes = CC_INV_DATA_FIELD;
  1728. // return sizeof (*pRes);
  1729. // }
  1730. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  1731. // pChannelInfo = getChannelInfo(ChannelNum, BMCInst);
  1732. // if (NULL == pChannelInfo)
  1733. // {
  1734. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1735. // *pRes = CC_INV_DATA_FIELD;
  1736. // return sizeof (*pRes);
  1737. // }
  1738. // /*point to NVRAM ChannelInfo */
  1739. // pNvrChInfo = GetNVRChConfigs(pChannelInfo,BMCInst);
  1740. // if (SESSIONLESS_CHANNEL == pChannelInfo->SessionSupport)
  1741. // {
  1742. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1743. // /* Channel is sessionless channel this command is not supported */
  1744. // *pRes = CC_SET_CH_COMMAND_NOT_SUPPORTED;
  1745. // return sizeof (*pRes);
  1746. // }
  1747. // AccessMode = pSetChAccessReq->ChannelAccess & 0x07;
  1748. // if(ChannelNum == pBMCInfo->SERIALch)
  1749. // {
  1750. // if( NULL != g_PDKHandle[PDK_SWITCHMUX])
  1751. // {
  1752. // ((void(*)(uint8_t, int))(g_PDKHandle[PDK_SWITCHMUX]))(AccessMode ,BMCInst);
  1753. // }
  1754. // }
  1755. // /* if the requested access mode is supported for the given channel */
  1756. // if (0 == (pChannelInfo->AccessModeSupported & (1 << AccessMode)))
  1757. // {
  1758. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1759. // *pRes = CC_SET_CH_ACCES_MODE_NOT_SUPPORTED;
  1760. // return sizeof (*pRes);
  1761. // }
  1762. // AccessFlags = GetBits (pSetChAccessReq->ChannelAccess, 0xC0);
  1763. // switch (AccessFlags)
  1764. // {
  1765. // case 0:
  1766. // /* dont set channel access */
  1767. // break;
  1768. // case 1:
  1769. // /*set in Non volatile Memory and in voatile Memory */
  1770. // pNvrChInfo->Alerting = GetBits (pSetChAccessReq->ChannelAccess , 0x20);
  1771. // pNvrChInfo->PerMessageAuth = GetBits (pSetChAccessReq->ChannelAccess , 0x10);
  1772. // pNvrChInfo->UserLevelAuth = GetBits (pSetChAccessReq->ChannelAccess , 0x08);
  1773. // pNvrChInfo->AccessMode = AccessMode;
  1774. // /* write to NVRAM */
  1775. // FlushChConfigs((uint8_t*)pNvrChInfo,pNvrChInfo->ChannelNumber,BMCInst);
  1776. // pChannelInfo->Alerting = pNvrChInfo->Alerting;
  1777. // pChannelInfo->PerMessageAuth= pNvrChInfo->PerMessageAuth;
  1778. // pChannelInfo->UserLevelAuth = pNvrChInfo->UserLevelAuth;
  1779. // pChannelInfo->AccessMode = AccessMode;
  1780. // break;
  1781. // case 2:
  1782. // /*set in volatile Memmory only */
  1783. // pChannelInfo->Alerting = GetBits (pSetChAccessReq->ChannelAccess, 0x20);
  1784. // pChannelInfo->PerMessageAuth= GetBits (pSetChAccessReq->ChannelAccess, 0x10);
  1785. // pChannelInfo->UserLevelAuth = GetBits (pSetChAccessReq->ChannelAccess, 0x08);
  1786. // pChannelInfo->AccessMode = AccessMode;
  1787. // }
  1788. // switch (GetBits (pSetChAccessReq->Privilege, 0xC0))
  1789. // {
  1790. // case 0:
  1791. // /* dont set prilivege level */
  1792. // break;
  1793. // case 1:
  1794. // /* set in non volatile mem and volatile memeory*/ /*set privilege*/
  1795. // pNvrChInfo->MaxPrivilege = GetBits (pSetChAccessReq->Privilege, 0x0F);
  1796. // pChannelInfo->MaxPrivilege = pNvrChInfo->MaxPrivilege;
  1797. // break;
  1798. // case 2:
  1799. // /*set privilege*/
  1800. // /* set in volatile memeory only */
  1801. // pChannelInfo->MaxPrivilege = GetBits (pSetChAccessReq->Privilege, 0x0F);
  1802. // }
  1803. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1804. // *pRes = CC_NORMAL;
  1805. // return sizeof (*pRes);
  1806. //}
  1807. ///*---------------------------------------
  1808. //* GetChAccess
  1809. //*---------------------------------------*/
  1810. //int
  1811. //GetChAccess ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  1812. //{
  1813. // GetChAccessReq_T* pGetChAccessReq = ( GetChAccessReq_T*)pReq;
  1814. // GetChAccessRes_T* pGetChAccessRes = ( GetChAccessRes_T*)pRes;
  1815. // ChannelInfo_T* pChannelInfo;
  1816. // ChannelInfo_T* pNvrChInfo;
  1817. // uint8_t ChannelNum,AccessFlag,*curchannel;
  1818. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  1819. // /* Check for reserved bits */
  1820. // if((0 != (pGetChAccessReq->ChannelNum & 0xf0)) ||
  1821. // (0 != (pGetChAccessReq-> AccessFlag & 0x3f)))
  1822. // {
  1823. // pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  1824. // return sizeof (*pRes);
  1825. // }
  1826. // ChannelNum = pGetChAccessReq->ChannelNum & 0x0F;
  1827. // if (CURRENT_CHANNEL_NUM == ChannelNum)
  1828. // {
  1829. // OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1830. // ChannelNum = *curchannel & 0xF;
  1831. // }
  1832. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  1833. // pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
  1834. // if (NULL == pChannelInfo)
  1835. // {
  1836. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1837. // pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  1838. // return sizeof (*pRes);
  1839. // }
  1840. // if (SESSIONLESS_CHANNEL == pChannelInfo->SessionSupport)
  1841. // {
  1842. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1843. // /* Channel is sessionless channel this command is not supported */
  1844. // pGetChAccessRes->CompletionCode = CC_GET_CH_COMMAND_NOT_SUPPORTED;
  1845. // return sizeof (*pRes);
  1846. // }
  1847. // AccessFlag = GetBits (pGetChAccessReq->AccessFlag, 0xC0);
  1848. // pGetChAccessRes->CompletionCode = CC_NORMAL;
  1849. // switch (AccessFlag)
  1850. // {
  1851. // case 1:
  1852. // /* Get Channel Information from NVRAM */
  1853. // pNvrChInfo = GetNVRChConfigs(pChannelInfo,BMCInst);
  1854. // pGetChAccessRes->ChannelAccess = SetBits (0x20, pNvrChInfo->Alerting);
  1855. // pGetChAccessRes->ChannelAccess |= SetBits (0x10, pNvrChInfo->PerMessageAuth);
  1856. // pGetChAccessRes->ChannelAccess |= SetBits (0x08, pNvrChInfo->UserLevelAuth);
  1857. // pGetChAccessRes->ChannelAccess |= SetBits (0x07, pNvrChInfo->AccessMode);
  1858. // pGetChAccessRes->Privilege = SetBits (0x0F, pNvrChInfo->MaxPrivilege);
  1859. // break;
  1860. // case 2:
  1861. // /* Get Channel Information from Volatile RAM */
  1862. // pGetChAccessRes->ChannelAccess = SetBits (0x20, pChannelInfo->Alerting);
  1863. // pGetChAccessRes->ChannelAccess |= SetBits (0x10, pChannelInfo->PerMessageAuth);
  1864. // pGetChAccessRes->ChannelAccess |= SetBits (0x08, pChannelInfo->UserLevelAuth);
  1865. // pGetChAccessRes->ChannelAccess |= SetBits (0x07, pChannelInfo->AccessMode);
  1866. // pGetChAccessRes->Privilege = SetBits (0x0F, pChannelInfo->MaxPrivilege);
  1867. // break;
  1868. // default:
  1869. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1870. // pGetChAccessRes->CompletionCode = CC_INV_DATA_FIELD;
  1871. // return sizeof (*pRes);
  1872. // }
  1873. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  1874. // return sizeof (GetChAccessRes_T);
  1875. //}
  1876. /*---------------------------------------
  1877. * GetChInfo
  1878. *---------------------------------------*/
  1879. int
  1880. GetChInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1881. {
  1882. GetChInfoReq_T* pGetChInfoReq = ( GetChInfoReq_T*)pReq;
  1883. GetChInfoRes_T* pGetChInfoRes = ( GetChInfoRes_T*)pRes;
  1884. ChannelInfo_T* pChannelInfo;
  1885. uint8_t ChannelNum,*curchannel;
  1886. if(pGetChInfoReq->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4)) //Check for Reserved bits
  1887. {
  1888. pGetChInfoRes->CompletionCode = CC_INV_DATA_FIELD;
  1889. return sizeof(*pRes);
  1890. }
  1891. ChannelNum = pGetChInfoReq->ChannelNum;
  1892. if (CURRENT_CHANNEL_NUM == ChannelNum)
  1893. {
  1894. curchannel = pthread_getspecific(g_tls.CurChannel);
  1895. ChannelNum = *curchannel & 0xF;
  1896. /* UDS, not being a physical channel, will hold LAN properties */
  1897. if(UDS_CHANNEL == ChannelNum)
  1898. {
  1899. ChannelNum = LAN_RMCP_CHANNEL1_TYPE;
  1900. }
  1901. }
  1902. pChannelInfo = getChannelInfo(ChannelNum);
  1903. if (NULL == pChannelInfo)
  1904. {
  1905. pGetChInfoRes->CompletionCode = CC_INV_DATA_FIELD ;
  1906. return sizeof (*pRes);
  1907. }
  1908. pGetChInfoRes->CompletionCode = CC_NORMAL;
  1909. pGetChInfoRes->ChannelNum = ChannelNum;
  1910. pGetChInfoRes->ChannelMedium = pChannelInfo->ChannelMedium;
  1911. pGetChInfoRes->ChannelProtocol = pChannelInfo->ChannelProtocol;
  1912. pGetChInfoRes->SessionActiveSupport = pChannelInfo->SessionSupport << 6;
  1913. pGetChInfoRes->SessionActiveSupport |= pChannelInfo->ActiveSession;
  1914. memcpy (pGetChInfoRes->VendorID, pChannelInfo->ProtocolVendorId,
  1915. sizeof (pGetChInfoRes->VendorID));
  1916. memcpy (pGetChInfoRes->AuxiliaryInfo, pChannelInfo->AuxiliaryInfo,
  1917. sizeof (pGetChInfoRes->AuxiliaryInfo));
  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 */