ipmi_lanp.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483
  1. /*
  2. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * Neither the name of Sun Microsystems, Inc. or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * This software is provided "AS IS," without a warranty of any kind.
  20. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  21. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  22. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  23. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  25. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  26. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  27. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  28. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  29. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  30. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <strings.h>
  36. #include <sys/types.h>
  37. #include <sys/socket.h>
  38. #include <netinet/in.h>
  39. #include <arpa/inet.h>
  40. #include <errno.h>
  41. #include <unistd.h>
  42. #include <signal.h>
  43. #include <setjmp.h>
  44. #include <netdb.h>
  45. #include <limits.h>
  46. #include <ipmitool/ipmi.h>
  47. #include <ipmitool/log.h>
  48. #include <ipmitool/ipmi_intf.h>
  49. #include <ipmitool/helper.h>
  50. #include <ipmitool/ipmi_constants.h>
  51. #include <ipmitool/ipmi_strings.h>
  52. #include <ipmitool/ipmi_lanp.h>
  53. #include <ipmitool/ipmi_channel.h>
  54. #include <ipmitool/ipmi_user.h>
  55. extern int verbose;
  56. static void print_lan_alert_print_usage(void);
  57. static void print_lan_alert_set_usage(void);
  58. static void print_lan_set_usage(void);
  59. static void print_lan_set_access_usage(void);
  60. static void print_lan_set_arp_usage(void);
  61. static void print_lan_set_auth_usage(void);
  62. static void print_lan_set_bakgw_usage(void);
  63. static void print_lan_set_cipher_privs_usage(void);
  64. static void print_lan_set_defgw_usage(void);
  65. static void print_lan_set_ipsrc_usage(void);
  66. static void print_lan_set_snmp_usage(void);
  67. static void print_lan_set_vlan_usage(void);
  68. static void print_lan_usage(void);
  69. /* is_lan_channel - Check if channel is LAN medium
  70. *
  71. * return 1 if channel is LAN
  72. * return 0 if channel is not LAN
  73. *
  74. * @intf: ipmi interface handle
  75. * @chan: channel number to check
  76. */
  77. static int
  78. is_lan_channel(struct ipmi_intf * intf, uint8_t chan)
  79. {
  80. uint8_t medium;
  81. //jimbo modify, 固定死网络的通道号是1
  82. if(chan == 1)
  83. return 1;
  84. // if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX)
  85. // return 0;
  86. // medium = ipmi_get_channel_medium(intf, chan);
  87. // if (medium == IPMI_CHANNEL_MEDIUM_LAN ||
  88. // medium == IPMI_CHANNEL_MEDIUM_LAN_OTHER)
  89. // return 1;
  90. return 0;
  91. }
  92. /* find_lan_channel - Find first channel that is LAN
  93. *
  94. * return channel number if successful
  95. * return 0 if no lan channel found, which is not a valid LAN channel
  96. *
  97. * @intf: ipmi interface handle
  98. * @start: channel number to start searching from
  99. */
  100. uint8_t
  101. find_lan_channel(struct ipmi_intf * intf, uint8_t start)
  102. {
  103. uint8_t chan = 0;
  104. for (chan = start; chan < IPMI_CHANNEL_NUMBER_MAX; chan++) {
  105. if (is_lan_channel(intf, chan)) {
  106. return chan;
  107. }
  108. }
  109. return 0;
  110. }
  111. /* get_lan_param_select - Query BMC for LAN parameter data
  112. *
  113. * return pointer to lan_param if successful
  114. * if parameter not supported then
  115. * return pointer to lan_param with
  116. * lan_param->data == NULL and lan_param->data_len == 0
  117. * return NULL on error
  118. *
  119. * @intf: ipmi interface handle
  120. * @chan: ipmi channel
  121. * @param: lan parameter id
  122. * @select: lan parameter set selector
  123. */
  124. static struct lan_param *
  125. get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int select)
  126. {
  127. struct lan_param * p = NULL;
  128. struct ipmi_rs * rsp;
  129. struct ipmi_rq req;
  130. int i = 0;
  131. uint8_t msg_data[4];
  132. for (i = 0; ipmi_lan_params[i].cmd != (-1); i++) {
  133. if (ipmi_lan_params[i].cmd == param) {
  134. p = &ipmi_lan_params[i];
  135. break;
  136. }
  137. }
  138. if (p == NULL) {
  139. lprintf(LOG_INFO, "Get LAN Parameter failed: Unknown parameter.");
  140. return NULL;
  141. }
  142. msg_data[0] = chan;
  143. msg_data[1] = p->cmd;
  144. msg_data[2] = select;
  145. msg_data[3] = 0;
  146. memset(&req, 0, sizeof(req));
  147. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  148. req.msg.cmd = IPMI_LAN_GET_CONFIG;
  149. req.msg.data = msg_data;
  150. req.msg.data_len = 4;
  151. rsp = intf->sendrecv(intf, &req);
  152. if (rsp == NULL) {
  153. lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed", p->desc);
  154. return NULL;
  155. }
  156. switch (rsp->ccode)
  157. {
  158. case 0x00: /* successful */
  159. break;
  160. case 0x80: /* parameter not supported */
  161. case 0xc9: /* parameter out of range */
  162. case 0xcc: /* invalid data field in request */
  163. /* these completion codes usually mean parameter not supported */
  164. lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
  165. p->desc, val2str(rsp->ccode, completion_code_vals));
  166. p->data = NULL;
  167. p->data_len = 0;
  168. return p;
  169. default:
  170. /* other completion codes are treated as error */
  171. lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
  172. p->desc, val2str(rsp->ccode, completion_code_vals));
  173. return NULL;
  174. }
  175. p->data = rsp->data + 1;
  176. p->data_len = rsp->data_len - 1;
  177. return p;
  178. }
  179. /* get_lan_param - Query BMC for LAN parameter data
  180. *
  181. * return pointer to lan_param if successful
  182. * if parameter not supported then
  183. * return pointer to lan_param with
  184. * lan_param->data == NULL and lan_param->data_len == 0
  185. * return NULL on error
  186. *
  187. * @intf: ipmi interface handle
  188. * @chan: ipmi channel
  189. * @param: lan parameter id
  190. */
  191. static struct lan_param *
  192. get_lan_param(struct ipmi_intf * intf, uint8_t chan, int param)
  193. {
  194. return get_lan_param_select(intf, chan, param, 0);
  195. }
  196. /* set_lan_param_wait - Wait for Set LAN Parameter command to complete
  197. *
  198. * On some systems this can take unusually long so we wait for the write
  199. * to take effect and verify that the data was written successfully
  200. * before continuing or retrying.
  201. *
  202. * returns 0 on success
  203. * returns -1 on error
  204. *
  205. * @intf: ipmi interface handle
  206. * @chan: ipmi channel
  207. * @param: lan parameter id
  208. * @data: lan parameter data
  209. * @len: length of lan parameter data
  210. */
  211. static int
  212. set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
  213. int param, uint8_t * data, int len)
  214. {
  215. struct lan_param * p;
  216. int retry = 10; /* 10 retries */
  217. lprintf(LOG_DEBUG, "Waiting for Set LAN Parameter to complete...");
  218. if (verbose > 1)
  219. printbuf(data, len, "SET DATA");
  220. for (;;) {
  221. p = get_lan_param(intf, chan, param);
  222. if (p == NULL) {
  223. sleep(IPMI_LANP_TIMEOUT);
  224. if (retry-- == 0)
  225. return -1;
  226. continue;
  227. }
  228. if (verbose > 1)
  229. printbuf(p->data, p->data_len, "READ DATA");
  230. if (p->data_len != len) {
  231. sleep(IPMI_LANP_TIMEOUT);
  232. if (retry-- == 0) {
  233. lprintf(LOG_WARNING, "Mismatched data lengths: %d != %d",
  234. p->data_len, len);
  235. return -1;
  236. }
  237. continue;
  238. }
  239. if (memcmp(data, p->data, len) != 0) {
  240. sleep(IPMI_LANP_TIMEOUT);
  241. if (retry-- == 0) {
  242. lprintf(LOG_WARNING, "LAN Parameter Data does not match! "
  243. "Write may have failed.");
  244. return -1;
  245. }
  246. continue;
  247. }
  248. break;
  249. }
  250. return 0;
  251. }
  252. /* __set_lan_param - Write LAN Parameter data to BMC
  253. *
  254. * This function does the actual work of writing the LAN parameter
  255. * to the BMC and calls set_lan_param_wait() if requested.
  256. *
  257. * returns 0 on success
  258. * returns -1 on error
  259. *
  260. * @intf: ipmi interface handle
  261. * @chan: ipmi channel
  262. * @param: lan parameter id
  263. * @data: lan parameter data
  264. * @len: length of lan parameter data
  265. * @wait: whether to wait for write completion
  266. */
  267. static int
  268. __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
  269. int param, uint8_t * data, int len, int wait)
  270. {
  271. struct ipmi_rs * rsp;
  272. struct ipmi_rq req;
  273. uint8_t msg_data[32];
  274. if (param < 0)
  275. return -1;
  276. msg_data[0] = chan;
  277. msg_data[1] = param;
  278. memcpy(&msg_data[2], data, len);
  279. memset(&req, 0, sizeof(req));
  280. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  281. req.msg.cmd = IPMI_LAN_SET_CONFIG;
  282. req.msg.data = msg_data;
  283. req.msg.data_len = len+2;
  284. rsp = intf->sendrecv(intf, &req);
  285. if (rsp == NULL) {
  286. lprintf(LOG_ERR, "Set LAN Parameter failed");
  287. return -1;
  288. }
  289. if ((rsp->ccode > 0) && (wait != 0)) {
  290. lprintf(LOG_DEBUG, "Warning: Set LAN Parameter failed: %s",
  291. val2str(rsp->ccode, completion_code_vals));
  292. if (rsp->ccode == 0xcc) {
  293. /* retry hack for invalid data field ccode */
  294. int retry = 10; /* 10 retries */
  295. lprintf(LOG_DEBUG, "Retrying...");
  296. for (;;) {
  297. if (retry-- == 0)
  298. break;
  299. sleep(IPMI_LANP_TIMEOUT);
  300. rsp = intf->sendrecv(intf, &req);
  301. if (rsp == NULL)
  302. continue;
  303. if (rsp->ccode > 0)
  304. continue;
  305. return set_lan_param_wait(intf, chan, param, data, len);
  306. }
  307. }
  308. else if (rsp->ccode != 0xff) {
  309. /* let 0xff ccode continue */
  310. return -1;
  311. }
  312. }
  313. if (wait == 0)
  314. return 0;
  315. return set_lan_param_wait(intf, chan, param, data, len);
  316. }
  317. /* ipmi_lanp_lock_state - Retrieve set-in-progress status
  318. *
  319. * returns one of:
  320. * IPMI_LANP_WRITE_UNLOCK
  321. * IPMI_LANP_WRITE_LOCK
  322. * IPMI_LANP_WRITE_COMMIT
  323. * -1 on error/if not supported
  324. *
  325. * @intf: ipmi interface handle
  326. * @chan: ipmi channel
  327. */
  328. static int
  329. ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan)
  330. {
  331. struct lan_param * p;
  332. p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
  333. if (p == NULL)
  334. return -1;
  335. if (p->data == NULL)
  336. return -1;
  337. return (p->data[0] & 3);
  338. }
  339. /* ipmi_lanp_lock - Lock set-in-progress bits for our use
  340. *
  341. * Write to the Set-In-Progress LAN parameter to indicate
  342. * to other management software that we are modifying parameters.
  343. *
  344. * No meaningful return value because this is an optional
  345. * requirement in IPMI spec and not found on many BMCs.
  346. *
  347. * @intf: ipmi interface handle
  348. * @chan: ipmi channel
  349. */
  350. static void
  351. ipmi_lanp_lock(struct ipmi_intf * intf, uint8_t chan)
  352. {
  353. uint8_t val = IPMI_LANP_WRITE_LOCK;
  354. int retry = 3;
  355. for (;;) {
  356. int state = ipmi_lanp_lock_state(intf, chan);
  357. if (state == -1)
  358. break;
  359. if (state == val)
  360. break;
  361. if (retry-- == 0)
  362. break;
  363. __set_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS,
  364. &val, 1, 0);
  365. }
  366. }
  367. /* ipmi_lanp_unlock - Unlock set-in-progress bits
  368. *
  369. * Write to the Set-In-Progress LAN parameter, first with
  370. * a "commit" instruction and then unlocking it.
  371. *
  372. * No meaningful return value because this is an optional
  373. * requirement in IPMI spec and not found on many BMCs.
  374. *
  375. * @intf: ipmi interface handle
  376. * @chan: ipmi channel
  377. */
  378. static void
  379. ipmi_lanp_unlock(struct ipmi_intf * intf, uint8_t chan)
  380. {
  381. uint8_t val = IPMI_LANP_WRITE_COMMIT;
  382. int rc;
  383. rc = __set_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS, &val, 1, 0);
  384. if (rc < 0) {
  385. lprintf(LOG_DEBUG, "LAN Parameter Commit not supported");
  386. }
  387. val = IPMI_LANP_WRITE_UNLOCK;
  388. __set_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS, &val, 1, 0);
  389. }
  390. /* set_lan_param - Wrap LAN parameter write with set-in-progress lock
  391. *
  392. * Returns value from __set_lan_param()
  393. *
  394. * @intf: ipmi interface handle
  395. * @chan: ipmi channel
  396. * @param: lan parameter id
  397. * @data: lan parameter data
  398. * @len: length of lan parameter data
  399. */
  400. static int
  401. set_lan_param(struct ipmi_intf * intf, uint8_t chan,
  402. int param, uint8_t * data, int len)
  403. {
  404. int rc;
  405. ipmi_lanp_lock(intf, chan);
  406. rc = __set_lan_param(intf, chan, param, data, len, 1);
  407. ipmi_lanp_unlock(intf, chan);
  408. return rc;
  409. }
  410. /* set_lan_param_nowait - Wrap LAN parameter write without set-in-progress lock
  411. *
  412. * Returns value from __set_lan_param()
  413. *
  414. * @intf: ipmi interface handle
  415. * @chan: ipmi channel
  416. * @param: lan parameter id
  417. * @data: lan parameter data
  418. * @len: length of lan parameter data
  419. */
  420. static int
  421. set_lan_param_nowait(struct ipmi_intf * intf, uint8_t chan,
  422. int param, uint8_t * data, int len)
  423. {
  424. int rc;
  425. ipmi_lanp_lock(intf, chan);
  426. rc = __set_lan_param(intf, chan, param, data, len, 0);
  427. ipmi_lanp_unlock(intf, chan);
  428. return rc;
  429. }
  430. static int
  431. lan_set_arp_interval(struct ipmi_intf * intf, uint8_t chan, uint8_t ival)
  432. {
  433. struct lan_param *lp;
  434. uint8_t interval = 0;
  435. int rc = 0;
  436. lp = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
  437. if (lp == NULL)
  438. return -1;
  439. if (lp->data == NULL)
  440. return -1;
  441. if (ival != 0) {
  442. if (((UINT8_MAX - 1) / 2) < ival) {
  443. lprintf(LOG_ERR, "Given ARP interval '%u' is too big.", ival);
  444. return (-1);
  445. }
  446. interval = (ival * 2) - 1;
  447. rc = set_lan_param(intf, chan, IPMI_LANP_GRAT_ARP, &interval, 1);
  448. } else {
  449. interval = lp->data[0];
  450. }
  451. printf("BMC-generated Gratuitous ARP interval: %.1f seconds\n",
  452. (float)((interval + 1) / 2));
  453. return rc;
  454. }
  455. static int
  456. lan_set_arp_generate(struct ipmi_intf * intf,
  457. uint8_t chan, uint8_t ctl)
  458. {
  459. struct lan_param *lp;
  460. uint8_t data;
  461. lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
  462. if (lp == NULL)
  463. return -1;
  464. if (lp->data == NULL)
  465. return -1;
  466. data = lp->data[0];
  467. /* set arp generate bitflag */
  468. if (ctl == 0)
  469. data &= ~0x1;
  470. else
  471. data |= 0x1;
  472. printf("%sabling BMC-generated Gratuitous ARPs\n", ctl ? "En" : "Dis");
  473. return set_lan_param(intf, chan, IPMI_LANP_BMC_ARP, &data, 1);
  474. }
  475. static int
  476. lan_set_arp_respond(struct ipmi_intf * intf,
  477. uint8_t chan, uint8_t ctl)
  478. {
  479. struct lan_param *lp;
  480. uint8_t data;
  481. lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
  482. if (lp == NULL)
  483. return -1;
  484. if (lp->data == NULL)
  485. return -1;
  486. data = lp->data[0];
  487. /* set arp response bitflag */
  488. if (ctl == 0)
  489. data &= ~0x2;
  490. else
  491. data |= 0x2;
  492. printf("%sabling BMC-generated ARP responses\n", ctl ? "En" : "Dis");
  493. return set_lan_param(intf, chan, IPMI_LANP_BMC_ARP, &data, 1);
  494. }
  495. /* TODO - probably move elsewhere */
  496. static char priv_level_to_char(unsigned char priv_level)
  497. {
  498. char ret = 'X';
  499. switch (priv_level)
  500. {
  501. case IPMI_SESSION_PRIV_CALLBACK:
  502. ret = 'c';
  503. break;
  504. case IPMI_SESSION_PRIV_USER:
  505. ret = 'u';
  506. break;
  507. case IPMI_SESSION_PRIV_OPERATOR:
  508. ret = 'o';
  509. break;
  510. case IPMI_SESSION_PRIV_ADMIN:
  511. ret = 'a';
  512. break;
  513. case IPMI_SESSION_PRIV_OEM:
  514. ret = 'O';
  515. break;
  516. }
  517. return ret;
  518. }
  519. static int
  520. ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
  521. {
  522. struct lan_param * p;
  523. if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX) {
  524. lprintf(LOG_ERR, "Invalid Channel %d", chan);
  525. return -1;
  526. }
  527. /* find type of channel and only accept 802.3 LAN */
  528. if (!is_lan_channel(intf, chan)) {
  529. lprintf(LOG_ERR, "Channel %d is not a LAN channel", chan);
  530. return -1;
  531. }
  532. p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
  533. if (p == NULL)
  534. return -1;
  535. if (p->data != NULL) {
  536. printf("%-24s: ", p->desc);
  537. p->data[0] &= 3;
  538. switch (p->data[0]) {
  539. case 0:
  540. printf("Set Complete\n");
  541. break;
  542. case 1:
  543. printf("Set In Progress\n");
  544. break;
  545. case 2:
  546. printf("Commit Write\n");
  547. break;
  548. case 3:
  549. printf("Reserved\n");
  550. break;
  551. default:
  552. printf("Unknown\n");
  553. }
  554. }
  555. p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE);
  556. if (p == NULL)
  557. return -1;
  558. if (p->data != NULL) {
  559. printf("%-24s: %s%s%s%s%s\n", p->desc,
  560. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
  561. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
  562. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
  563. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
  564. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
  565. }
  566. p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
  567. if (p == NULL)
  568. return -1;
  569. if (p->data != NULL) {
  570. printf("%-24s: Callback : %s%s%s%s%s\n", p->desc,
  571. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
  572. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
  573. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
  574. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
  575. (p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
  576. printf("%-24s: User : %s%s%s%s%s\n", "",
  577. (p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
  578. (p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
  579. (p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
  580. (p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
  581. (p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
  582. printf("%-24s: Operator : %s%s%s%s%s\n", "",
  583. (p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
  584. (p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
  585. (p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
  586. (p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
  587. (p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
  588. printf("%-24s: Admin : %s%s%s%s%s\n", "",
  589. (p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
  590. (p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
  591. (p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
  592. (p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
  593. (p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
  594. printf("%-24s: OEM : %s%s%s%s%s\n", "",
  595. (p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
  596. (p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
  597. (p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
  598. (p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
  599. (p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
  600. }
  601. p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR_SRC);
  602. if (p == NULL)
  603. return -1;
  604. if (p->data != NULL) {
  605. printf("%-24s: ", p->desc);
  606. p->data[0] &= 0xf;
  607. switch (p->data[0]) {
  608. case 0:
  609. printf("Unspecified\n");
  610. break;
  611. case 1:
  612. printf("Static Address\n");
  613. break;
  614. case 2:
  615. printf("DHCP Address\n");
  616. break;
  617. case 3:
  618. printf("BIOS Assigned Address\n");
  619. break;
  620. default:
  621. printf("Other\n");
  622. break;
  623. }
  624. }
  625. p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR);
  626. if (p == NULL)
  627. return -1;
  628. if (p->data != NULL)
  629. printf("%-24s: %d.%d.%d.%d\n", p->desc,
  630. p->data[0], p->data[1], p->data[2], p->data[3]);
  631. p = get_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK);
  632. if (p == NULL)
  633. return -1;
  634. if (p->data != NULL)
  635. printf("%-24s: %d.%d.%d.%d\n", p->desc,
  636. p->data[0], p->data[1], p->data[2], p->data[3]);
  637. p = get_lan_param(intf, chan, IPMI_LANP_MAC_ADDR);
  638. if (p == NULL)
  639. return -1;
  640. if (p->data != NULL)
  641. printf("%-24s: %s\n", p->desc, mac2str(p->data));
  642. p = get_lan_param(intf, chan, IPMI_LANP_SNMP_STRING);
  643. if (p == NULL)
  644. return -1;
  645. if (p->data != NULL)
  646. printf("%-24s: %s\n", p->desc, p->data);
  647. p = get_lan_param(intf, chan, IPMI_LANP_IP_HEADER);
  648. if (p == NULL)
  649. return -1;
  650. if (p->data != NULL)
  651. printf("%-24s: TTL=0x%02x Flags=0x%02x Precedence=0x%02x TOS=0x%02x\n",
  652. p->desc, p->data[0], p->data[1] & 0xe0, p->data[2] & 0xe0, p->data[2] & 0x1e);
  653. p = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
  654. if (p == NULL)
  655. return -1;
  656. if (p->data != NULL)
  657. printf("%-24s: ARP Responses %sabled, Gratuitous ARP %sabled\n", p->desc,
  658. (p->data[0] & 2) ? "En" : "Dis", (p->data[0] & 1) ? "En" : "Dis");
  659. p = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
  660. if (p == NULL)
  661. return -1;
  662. if (p->data != NULL)
  663. printf("%-24s: %.1f seconds\n", p->desc, (float)((p->data[0] + 1) / 2));
  664. p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP);
  665. if (p == NULL)
  666. return -1;
  667. if (p->data != NULL)
  668. printf("%-24s: %d.%d.%d.%d\n", p->desc,
  669. p->data[0], p->data[1], p->data[2], p->data[3]);
  670. p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC);
  671. if (p == NULL)
  672. return -1;
  673. if (p->data != NULL)
  674. printf("%-24s: %s\n", p->desc, mac2str(p->data));
  675. p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP);
  676. if (p == NULL)
  677. return -1;
  678. if (p->data != NULL)
  679. printf("%-24s: %d.%d.%d.%d\n", p->desc,
  680. p->data[0], p->data[1], p->data[2], p->data[3]);
  681. p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC);
  682. if (p == NULL)
  683. return -1;
  684. if (p->data != NULL)
  685. printf("%-24s: %s\n", p->desc, mac2str(p->data));
  686. p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
  687. if (p != NULL && p->data != NULL) {
  688. int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
  689. if (p->data[1] & 0x80)
  690. printf("%-24s: %d\n", p->desc, id);
  691. else
  692. printf("%-24s: Disabled\n", p->desc);
  693. }
  694. p = get_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY);
  695. if (p != NULL && p->data != NULL)
  696. printf("%-24s: %d\n", p->desc, p->data[0] & 0x07);
  697. /* Determine supported Cipher Suites -- Requires two calls */
  698. p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHER_SUPPORT);
  699. if (p == NULL)
  700. return -1;
  701. else if (p->data != NULL)
  702. {
  703. unsigned char cipher_suite_count = p->data[0];
  704. p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHERS);
  705. if (p == NULL)
  706. return -1;
  707. printf("%-24s: ", p->desc);
  708. /* Now we're dangerous. There are only 15 fixed cipher
  709. suite IDs, but the spec allows for 16 in the return data.*/
  710. if ((p->data != NULL) && (p->data_len <= 17))
  711. {
  712. unsigned int i;
  713. for (i = 0; (i < 16) && (i < cipher_suite_count); ++i)
  714. {
  715. printf("%s%d",
  716. (i > 0? ",": ""),
  717. p->data[i + 1]);
  718. }
  719. printf("\n");
  720. }
  721. else
  722. {
  723. printf("None\n");
  724. }
  725. }
  726. /* RMCP+ Messaging Cipher Suite Privilege Levels */
  727. /* These are the privilege levels for the 15 fixed cipher suites */
  728. p = get_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS);
  729. if (p == NULL)
  730. return -1;
  731. if ((p->data != NULL) && (p->data_len == 9))
  732. {
  733. printf("%-24s: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", p->desc,
  734. priv_level_to_char(p->data[1] & 0x0F),
  735. priv_level_to_char(p->data[1] >> 4),
  736. priv_level_to_char(p->data[2] & 0x0F),
  737. priv_level_to_char(p->data[2] >> 4),
  738. priv_level_to_char(p->data[3] & 0x0F),
  739. priv_level_to_char(p->data[3] >> 4),
  740. priv_level_to_char(p->data[4] & 0x0F),
  741. priv_level_to_char(p->data[4] >> 4),
  742. priv_level_to_char(p->data[5] & 0x0F),
  743. priv_level_to_char(p->data[5] >> 4),
  744. priv_level_to_char(p->data[6] & 0x0F),
  745. priv_level_to_char(p->data[6] >> 4),
  746. priv_level_to_char(p->data[7] & 0x0F),
  747. priv_level_to_char(p->data[7] >> 4),
  748. priv_level_to_char(p->data[8] & 0x0F));
  749. /* Now print a legend */
  750. printf("%-24s: %s\n", "", " X=Cipher Suite Unused");
  751. printf("%-24s: %s\n", "", " c=CALLBACK");
  752. printf("%-24s: %s\n", "", " u=USER");
  753. printf("%-24s: %s\n", "", " o=OPERATOR");
  754. printf("%-24s: %s\n", "", " a=ADMIN");
  755. printf("%-24s: %s\n", "", " O=OEM");
  756. }
  757. else
  758. printf("%-24s: Not Available\n", p->desc);
  759. /* Bad Password Threshold */
  760. p = get_lan_param(intf, chan, IPMI_LANP_BAD_PASS_THRESH);
  761. if (p == NULL)
  762. return -1;
  763. if ((p->data != NULL) && (p->data_len == 6)) {
  764. int tmp;
  765. printf("%-24s: %d\n", p->desc, p->data[1]);
  766. printf("%-24s: %s\n", "Invalid password disable",
  767. p->data[0] & 1 ? "yes" : "no" );
  768. tmp = p->data[2] + (p->data[3] << 8);
  769. printf("%-24s: %d\n", "Attempt Count Reset Int.", tmp * 10);
  770. tmp = p->data[4] + (p->data[5] << 8);
  771. printf("%-24s: %d\n", "User Lockout Interval", tmp * 10);
  772. } else {
  773. printf("%-24s: Not Available\n", p->desc);
  774. }
  775. return 0;
  776. }
  777. /* Configure Authentication Types */
  778. /* TODO - probably some code duplication going on ??? */
  779. static int
  780. ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * types)
  781. {
  782. uint8_t data[5];
  783. uint8_t authtype = 0;
  784. char * p;
  785. struct lan_param * lp;
  786. if (level == NULL || types == NULL)
  787. return -1;
  788. lp = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
  789. if (lp == NULL)
  790. return -1;
  791. if (lp->data == NULL)
  792. return -1;
  793. lprintf(LOG_DEBUG, "%-24s: callback=0x%02x user=0x%02x operator=0x%02x admin=0x%02x oem=0x%02x",
  794. lp->desc, lp->data[0], lp->data[1], lp->data[2], lp->data[3], lp->data[4]);
  795. memset(data, 0, 5);
  796. memcpy(data, lp->data, 5);
  797. p = types;
  798. while (p) {
  799. if (strncasecmp(p, "none", 4) == 0)
  800. authtype |= 1 << IPMI_SESSION_AUTHTYPE_NONE;
  801. else if (strncasecmp(p, "md2", 3) == 0)
  802. authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD2;
  803. else if (strncasecmp(p, "md5", 3) == 0)
  804. authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD5;
  805. else if ((strncasecmp(p, "password", 8) == 0) ||
  806. (strncasecmp(p, "key", 3) == 0))
  807. authtype |= 1 << IPMI_SESSION_AUTHTYPE_KEY;
  808. else if (strncasecmp(p, "oem", 3) == 0)
  809. authtype |= 1 << IPMI_SESSION_AUTHTYPE_OEM;
  810. else
  811. lprintf(LOG_WARNING, "Invalid authentication type: %s", p);
  812. p = strchr(p, ',');
  813. if (p)
  814. p++;
  815. }
  816. p = level;
  817. while (p) {
  818. if (strncasecmp(p, "callback", 8) == 0)
  819. data[0] = authtype;
  820. else if (strncasecmp(p, "user", 4) == 0)
  821. data[1] = authtype;
  822. else if (strncasecmp(p, "operator", 8) == 0)
  823. data[2] = authtype;
  824. else if (strncasecmp(p, "admin", 5) == 0)
  825. data[3] = authtype;
  826. else
  827. lprintf(LOG_WARNING, "Invalid authentication level: %s", p);
  828. p = strchr(p, ',');
  829. if (p)
  830. p++;
  831. }
  832. if (verbose > 1)
  833. printbuf(data, 5, "authtype data");
  834. return set_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE, data, 5);
  835. }
  836. static int
  837. ipmi_lan_set_password(struct ipmi_intf *intf,
  838. uint8_t user_id, const char *password)
  839. {
  840. int ccode = 0;
  841. ccode = _ipmi_set_user_password(intf, user_id,
  842. IPMI_PASSWORD_SET_PASSWORD, password, 0);
  843. if (eval_ccode(ccode) != 0) {
  844. lprintf(LOG_ERR, "Unable to Set LAN Password for user %d",
  845. user_id);
  846. return (-1);
  847. }
  848. /* adjust our session password
  849. * or we will no longer be able to communicate with BMC
  850. */
  851. ipmi_intf_session_set_password(intf, (char *)password);
  852. printf("Password %s for user %d\n",
  853. (password == NULL) ? "cleared" : "set", user_id);
  854. return 0;
  855. }
  856. /* ipmi_set_alert_enable - enable/disable PEF alerting for given channel.
  857. *
  858. * @channel - IPMI channel
  859. * @enable - whether to enable/disable PEF alerting for given channel
  860. *
  861. * returns - 0 on success, (-1) on error.
  862. */
  863. static int
  864. ipmi_set_alert_enable(struct ipmi_intf *intf, uint8_t channel, uint8_t enable)
  865. {
  866. struct channel_access_t channel_access;
  867. int ccode = 0;
  868. memset(&channel_access, 0, sizeof(channel_access));
  869. channel_access.channel = channel;
  870. ccode = _ipmi_get_channel_access(intf, &channel_access, 0);
  871. if (eval_ccode(ccode) != 0) {
  872. lprintf(LOG_ERR,
  873. "Unable to Get Channel Access(non-volatile) for channel %d",
  874. channel);
  875. return (-1);
  876. }
  877. if (enable != 0) {
  878. channel_access.alerting = 1;
  879. } else {
  880. channel_access.alerting = 0;
  881. }
  882. /* non-volatile */
  883. ccode = _ipmi_set_channel_access(intf, channel_access, 1, 0);
  884. if (eval_ccode(ccode) != 0) {
  885. lprintf(LOG_ERR,
  886. "Unable to Set Channel Access(non-volatile) for channel %d",
  887. channel);
  888. return (-1);
  889. }
  890. /* volatile */
  891. ccode = _ipmi_set_channel_access(intf, channel_access, 2, 0);
  892. if (eval_ccode(ccode) != 0) {
  893. lprintf(LOG_ERR,
  894. "Unable to Set Channel Access(volatile) for channel %d",
  895. channel);
  896. return (-1);
  897. }
  898. printf("PEF alerts for channel %d %s.\n",
  899. channel,
  900. (enable) ? "enabled" : "disabled");
  901. return 0;
  902. }
  903. /* ipmi_set_channel_access - enable/disable IPMI messaging for given channel and
  904. * set Privilege Level to Administrator.
  905. *
  906. * @channel - IPMI channel
  907. * @enable - whether to enable/disable IPMI messaging for given channel.
  908. *
  909. * returns - 0 on success, (-1) on error
  910. */
  911. static int
  912. ipmi_set_channel_access(struct ipmi_intf *intf, uint8_t channel,
  913. uint8_t enable)
  914. {
  915. struct channel_access_t channel_access;
  916. int ccode = 0;
  917. memset(&channel_access, 0, sizeof(channel_access));
  918. channel_access.channel = channel;
  919. /* Get Non-Volatile Channel Access first */
  920. ccode = _ipmi_get_channel_access(intf, &channel_access, 0);
  921. if (eval_ccode(ccode) != 0) {
  922. lprintf(LOG_ERR,
  923. "Unable to Get Channel Access(non-volatile) for channel %d",
  924. channel);
  925. return (-1);
  926. }
  927. if (enable != 0) {
  928. channel_access.access_mode = 2;
  929. } else {
  930. channel_access.access_mode = 0;
  931. }
  932. channel_access.privilege_limit = 0x04;
  933. ccode = _ipmi_set_channel_access(intf, channel_access, 1, 1);
  934. if (eval_ccode(ccode) != 0) {
  935. lprintf(LOG_ERR,
  936. "Unable to Set Channel Access(non-volatile) for channel %d",
  937. channel);
  938. return (-1);
  939. }
  940. memset(&channel_access, 0, sizeof(channel_access));
  941. channel_access.channel = channel;
  942. /* Get Volatile Channel Access */
  943. ccode = _ipmi_get_channel_access(intf, &channel_access, 1);
  944. if (eval_ccode(ccode) != 0) {
  945. lprintf(LOG_ERR,
  946. "Unable to Get Channel Access(volatile) for channel %d",
  947. channel);
  948. return (-1);
  949. }
  950. if (enable != 0) {
  951. channel_access.access_mode = 2;
  952. } else {
  953. channel_access.access_mode = 0;
  954. }
  955. channel_access.privilege_limit = 0x04;
  956. ccode = _ipmi_set_channel_access(intf, channel_access, 2, 2);
  957. if (eval_ccode(ccode) != 0) {
  958. lprintf(LOG_ERR,
  959. "Unable to Set Channel Access(volatile) for channel %d",
  960. channel);
  961. return (-1);
  962. }
  963. /* can't send close session if access off so abort instead */
  964. if (enable == 0) {
  965. intf->abort = 1;
  966. }
  967. printf("Set Channel Access for channel %d was successful.\n",
  968. channel);
  969. return 0;
  970. }
  971. /* ipmi_set_user_access - set admin access for given user and channel.
  972. *
  973. * @intf - IPMI interface
  974. * @channel - IPMI channel
  975. * @user_id - IPMI User ID
  976. *
  977. * returns - 0 on success, (-1) on error.
  978. */
  979. static int
  980. ipmi_set_user_access(struct ipmi_intf *intf, uint8_t channel, uint8_t user_id)
  981. {
  982. struct user_access_t user_access;
  983. int ccode = 0;
  984. memset(&user_access, 0, sizeof(user_access));
  985. user_access.channel = channel;
  986. user_access.user_id = user_id;
  987. user_access.privilege_limit = 0x04;
  988. ccode = _ipmi_set_user_access(intf, &user_access, 1);
  989. if (eval_ccode(ccode) != 0) {
  990. lprintf(LOG_ERR, "Set User Access for channel %d failed",
  991. channel);
  992. return (-1);
  993. } else {
  994. printf("Set User Access for channel %d was successful.",
  995. channel);
  996. return 0;
  997. }
  998. }
  999. static int
  1000. get_cmdline_cipher_suite_priv_data(char * arg, uint8_t * buf)
  1001. {
  1002. int i, ret = 0;
  1003. if (strlen(arg) != 15)
  1004. {
  1005. lprintf(LOG_ERR, "Invalid privilege specification length: %d",
  1006. strlen(arg));
  1007. return -1;
  1008. }
  1009. /*
  1010. * The first byte is reserved (0). The rest of the buffer is setup
  1011. * so that each nibble holds the maximum privilege level available for
  1012. * that cipher suite number. The number of nibbles (15) matches the number
  1013. * of fixed cipher suite IDs. This command documentation mentions 16 IDs
  1014. * but table 22-19 shows that there are only 15 (0-14).
  1015. *
  1016. * data 1 - reserved
  1017. * data 2 - maximum priv level for first (LSN) and second (MSN) ciphers
  1018. * data 3 - maximum priv level for third (LSN) and fourth (MSN) ciphers
  1019. * data 9 - maximum priv level for 15th (LSN) cipher.
  1020. */
  1021. memset(buf, 0, 9);
  1022. for (i = 0; i < 15; ++i)
  1023. {
  1024. unsigned char priv_level = IPMI_SESSION_PRIV_ADMIN;
  1025. switch (arg[i])
  1026. {
  1027. case 'X':
  1028. priv_level = IPMI_SESSION_PRIV_UNSPECIFIED; /* 0 */
  1029. break;
  1030. case 'c':
  1031. priv_level = IPMI_SESSION_PRIV_CALLBACK; /* 1 */
  1032. break;
  1033. case 'u':
  1034. priv_level = IPMI_SESSION_PRIV_USER; /* 2 */
  1035. break;
  1036. case 'o':
  1037. priv_level = IPMI_SESSION_PRIV_OPERATOR; /* 3 */
  1038. break;
  1039. case 'a':
  1040. priv_level = IPMI_SESSION_PRIV_ADMIN; /* 4 */
  1041. break;
  1042. case 'O':
  1043. priv_level = IPMI_SESSION_PRIV_OEM; /* 5 */
  1044. break;
  1045. default:
  1046. lprintf(LOG_ERR, "Invalid privilege specification char: %c",
  1047. arg[i]);
  1048. ret = -1;
  1049. break;
  1050. }
  1051. if (ret != 0)
  1052. break;
  1053. else
  1054. {
  1055. if ((i + 1) % 2)
  1056. {
  1057. // Odd number cipher suites will be in the LSN
  1058. buf[1 + (i / 2)] += priv_level;
  1059. }
  1060. else
  1061. {
  1062. // Even number cipher suites will be in the MSN
  1063. buf[1 + (i / 2)] += (priv_level << 4);
  1064. }
  1065. }
  1066. }
  1067. return ret;
  1068. }
  1069. static int
  1070. get_cmdline_ipaddr(char * arg, uint8_t * buf)
  1071. {
  1072. uint32_t ip1, ip2, ip3, ip4;
  1073. if (sscanf(arg,
  1074. "%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32,
  1075. &ip1, &ip2, &ip3, &ip4) != 4) {
  1076. lprintf(LOG_ERR, "Invalid IP address: %s", arg);
  1077. return (-1);
  1078. }
  1079. if (ip1 > UINT8_MAX || ip2 > UINT8_MAX
  1080. || ip3 > UINT8_MAX || ip4 > UINT8_MAX) {
  1081. lprintf(LOG_ERR, "Invalid IP address: %s", arg);
  1082. return (-1);
  1083. }
  1084. buf[0] = (uint8_t)ip1;
  1085. buf[1] = (uint8_t)ip2;
  1086. buf[2] = (uint8_t)ip3;
  1087. buf[3] = (uint8_t)ip4;
  1088. return 0;
  1089. }
  1090. static int
  1091. ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
  1092. {
  1093. struct lan_param *p;
  1094. uint8_t data[2];
  1095. int rc;
  1096. if (string == NULL) {
  1097. lprintf(LOG_DEBUG, "Get current VLAN ID from BMC.");
  1098. p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
  1099. if (p != NULL && p->data != NULL && p->data_len > 1) {
  1100. int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
  1101. if (id < 1 || id > 4094) {
  1102. lprintf(LOG_ERR,
  1103. "Retrieved VLAN ID %i is out of range <1..4094>.",
  1104. id);
  1105. return (-1);
  1106. }
  1107. data[0] = p->data[0];
  1108. data[1] = p->data[1] & 0x0F;
  1109. } else {
  1110. data[0] = 0;
  1111. data[1] = 0;
  1112. }
  1113. }
  1114. else {
  1115. int id = 0;
  1116. if (str2int(string, &id) != 0) {
  1117. lprintf(LOG_ERR, "Given VLAN ID '%s' is invalid.", string);
  1118. return (-1);
  1119. }
  1120. if (id < 1 || id > 4094) {
  1121. lprintf(LOG_NOTICE, "VLAN ID must be between 1 and 4094.");
  1122. return (-1);
  1123. }
  1124. else {
  1125. data[0] = (uint8_t)id;
  1126. data[1] = (uint8_t)(id >> 8) | 0x80;
  1127. }
  1128. }
  1129. rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_ID, data, 2);
  1130. return rc;
  1131. }
  1132. static int
  1133. ipmi_lan_set_vlan_priority(struct ipmi_intf *intf, uint8_t chan, char *string)
  1134. {
  1135. uint8_t data;
  1136. int rc;
  1137. int priority = 0;
  1138. if (str2int(string, &priority) != 0) {
  1139. lprintf(LOG_ERR, "Given VLAN priority '%s' is invalid.", string);
  1140. return (-1);
  1141. }
  1142. if (priority < 0 || priority > 7) {
  1143. lprintf(LOG_NOTICE, "VLAN priority must be between 0 and 7.");
  1144. return (-1);
  1145. }
  1146. data = (uint8_t)priority;
  1147. rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY, &data, 1);
  1148. return rc;
  1149. }
  1150. static void
  1151. print_lan_set_bad_pass_thresh_usage(void)
  1152. {
  1153. lprintf(LOG_NOTICE,
  1154. "lan set <chanel> bad_pass_thresh <thresh_num> <1|0> <reset_interval> <lockout_interval>\n"
  1155. " <thresh_num> Bad Pasword Threshold number.\n"
  1156. " <1|0> 1 = generate a Session Audit sensor event.\n"
  1157. " 0 = do not generate an event.\n"
  1158. " <reset_interval> Attempt Count Reset Interval. In tens of seconds.\n"
  1159. " <lockount_interval> User Lockout Interval. In tens of seconds.");
  1160. }
  1161. /* get_cmdline_bad_pass_thresh - parse-out bad password threshold from given
  1162. * string and store it into buffer.
  1163. *
  1164. * @arg: string to be parsed.
  1165. * @buf: buffer of 6 to hold parsed Bad Password Threshold.
  1166. *
  1167. * returns zero on success, (-1) on error.
  1168. */
  1169. static int
  1170. get_cmdline_bad_pass_thresh(char *argv[], uint8_t *buf)
  1171. {
  1172. uint16_t reset, lockout;
  1173. if (str2uchar(argv[0], &buf[1])) {
  1174. return -1;
  1175. }
  1176. if (str2uchar(argv[1], &buf[0]) || buf[0] > 1) {
  1177. return -1;
  1178. }
  1179. if (str2ushort(argv[2], &reset)) {
  1180. return -1;
  1181. }
  1182. if (str2ushort(argv[3], &lockout)) {
  1183. return -1;
  1184. }
  1185. /* store parsed data */
  1186. buf[2] = reset & 0xFF;
  1187. buf[3] = reset >> 8;
  1188. buf[4] = lockout & 0xFF;
  1189. buf[5] = lockout >> 8;
  1190. return 0;
  1191. }
  1192. static int
  1193. ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
  1194. {
  1195. uint8_t data[32];
  1196. uint8_t chan;
  1197. int rc = 0;
  1198. if (argc < 2) {
  1199. print_lan_set_usage();
  1200. return (-1);
  1201. }
  1202. if (strncmp(argv[0], "help", 4) == 0 ||
  1203. strncmp(argv[1], "help", 4) == 0) {
  1204. print_lan_set_usage();
  1205. return 0;
  1206. }
  1207. if (str2uchar(argv[0], &chan) != 0) {
  1208. lprintf(LOG_ERR, "Invalid channel: %s", argv[0]);
  1209. return (-1);
  1210. }
  1211. /* find type of channel and only accept 802.3 LAN */
  1212. if (!is_lan_channel(intf, chan)) {
  1213. lprintf(LOG_ERR, "Channel %d is not a LAN channel!", chan);
  1214. print_lan_set_usage();
  1215. return -1;
  1216. }
  1217. memset(&data, 0, sizeof(data));
  1218. /* set user access */
  1219. if (strncmp(argv[1], "user", 4) == 0) {
  1220. rc = ipmi_set_user_access(intf, chan, 1);
  1221. }
  1222. /* set channel access mode */
  1223. else if (strncmp(argv[1], "access", 6) == 0) {
  1224. if (argc < 3) {
  1225. print_lan_set_access_usage();
  1226. return (-1);
  1227. }
  1228. else if (strncmp(argv[2], "help", 4) == 0) {
  1229. print_lan_set_access_usage();
  1230. return 0;
  1231. }
  1232. else if (strncmp(argv[2], "on", 2) == 0) {
  1233. rc = ipmi_set_channel_access(intf, chan, 1);
  1234. }
  1235. else if (strncmp(argv[2], "off", 3) == 0) {
  1236. rc = ipmi_set_channel_access(intf, chan, 0);
  1237. }
  1238. else {
  1239. print_lan_set_access_usage();
  1240. return (-1);
  1241. }
  1242. }
  1243. /* set ARP control */
  1244. else if (strncmp(argv[1], "arp", 3) == 0) {
  1245. if (argc < 3) {
  1246. print_lan_set_arp_usage();
  1247. return (-1);
  1248. }
  1249. else if (strncmp(argv[2], "help", 4) == 0) {
  1250. print_lan_set_arp_usage();
  1251. }
  1252. else if (strncmp(argv[2], "interval", 8) == 0) {
  1253. uint8_t interval = 0;
  1254. if (str2uchar(argv[3], &interval) != 0) {
  1255. lprintf(LOG_ERR, "Given ARP interval '%s' is invalid.", argv[3]);
  1256. return (-1);
  1257. }
  1258. rc = lan_set_arp_interval(intf, chan, interval);
  1259. }
  1260. else if (strncmp(argv[2], "generate", 8) == 0) {
  1261. if (argc < 4) {
  1262. print_lan_set_arp_usage();
  1263. return (-1);
  1264. }
  1265. else if (strncmp(argv[3], "on", 2) == 0)
  1266. rc = lan_set_arp_generate(intf, chan, 1);
  1267. else if (strncmp(argv[3], "off", 3) == 0)
  1268. rc = lan_set_arp_generate(intf, chan, 0);
  1269. else {
  1270. print_lan_set_arp_usage();
  1271. return (-1);
  1272. }
  1273. }
  1274. else if (strncmp(argv[2], "respond", 7) == 0) {
  1275. if (argc < 4) {
  1276. print_lan_set_arp_usage();
  1277. return (-1);
  1278. }
  1279. else if (strncmp(argv[3], "on", 2) == 0)
  1280. rc = lan_set_arp_respond(intf, chan, 1);
  1281. else if (strncmp(argv[3], "off", 3) == 0)
  1282. rc = lan_set_arp_respond(intf, chan, 0);
  1283. else {
  1284. print_lan_set_arp_usage();
  1285. return (-1);
  1286. }
  1287. }
  1288. else {
  1289. print_lan_set_arp_usage();
  1290. }
  1291. }
  1292. /* set authentication types */
  1293. else if (strncmp(argv[1], "auth", 4) == 0) {
  1294. if (argc < 3) {
  1295. print_lan_set_auth_usage();
  1296. return (-1);
  1297. }
  1298. else if (strncmp(argv[2], "help", 4) == 0) {
  1299. print_lan_set_auth_usage();
  1300. return 0;
  1301. } else {
  1302. rc = ipmi_lan_set_auth(intf, chan, argv[2], argv[3]);
  1303. }
  1304. }
  1305. /* ip address source */
  1306. else if (strncmp(argv[1], "ipsrc", 5) == 0) {
  1307. if (argc < 3) {
  1308. print_lan_set_ipsrc_usage();
  1309. return (-1);
  1310. }
  1311. else if (strncmp(argv[2], "help", 4) == 0) {
  1312. print_lan_set_ipsrc_usage();
  1313. return 0;
  1314. }
  1315. else if (strncmp(argv[2], "none", 4) == 0)
  1316. data[0] = 0;
  1317. else if (strncmp(argv[2], "static", 5) == 0)
  1318. data[0] = 1;
  1319. else if (strncmp(argv[2], "dhcp", 4) == 0)
  1320. data[0] = 2;
  1321. else if (strncmp(argv[2], "bios", 4) == 0)
  1322. data[0] = 3;
  1323. else {
  1324. print_lan_set_ipsrc_usage();
  1325. return -1;
  1326. }
  1327. rc = set_lan_param(intf, chan, IPMI_LANP_IP_ADDR_SRC, data, 1);
  1328. }
  1329. /* session password
  1330. * not strictly a lan setting, but its used for lan connections */
  1331. else if (strncmp(argv[1], "password", 8) == 0) {
  1332. rc = ipmi_lan_set_password(intf, 1, argv[2]);
  1333. }
  1334. /* snmp community string */
  1335. else if (strncmp(argv[1], "snmp", 4) == 0) {
  1336. if (argc < 3) {
  1337. print_lan_set_snmp_usage();
  1338. return (-1);
  1339. }
  1340. else if (strncmp(argv[2], "help", 4) == 0) {
  1341. print_lan_set_snmp_usage();
  1342. return 0;
  1343. } else {
  1344. memcpy(data, argv[2], __min(strlen(argv[2]), 18));
  1345. printf("Setting LAN %s to %s\n",
  1346. ipmi_lan_params[IPMI_LANP_SNMP_STRING].desc, data);
  1347. rc = set_lan_param(intf, chan, IPMI_LANP_SNMP_STRING, data, 18);
  1348. }
  1349. }
  1350. /* ip address */
  1351. else if (strncmp(argv[1], "ipaddr", 6) == 0) {
  1352. if(argc != 3)
  1353. {
  1354. print_lan_set_usage();
  1355. return -1;
  1356. }
  1357. rc = get_cmdline_ipaddr(argv[2], data);
  1358. if (rc == 0) {
  1359. printf("Setting LAN %s to %d.%d.%d.%d\n",
  1360. ipmi_lan_params[IPMI_LANP_IP_ADDR].desc,
  1361. data[0], data[1], data[2], data[3]);
  1362. rc = set_lan_param(intf, chan, IPMI_LANP_IP_ADDR, data, 4);
  1363. }
  1364. }
  1365. /* network mask */
  1366. else if (strncmp(argv[1], "netmask", 7) == 0) {
  1367. if(argc != 3)
  1368. {
  1369. print_lan_set_usage();
  1370. return -1;
  1371. }
  1372. rc = get_cmdline_ipaddr(argv[2], data);
  1373. if (rc == 0) {
  1374. printf("Setting LAN %s to %d.%d.%d.%d\n",
  1375. ipmi_lan_params[IPMI_LANP_SUBNET_MASK].desc,
  1376. data[0], data[1], data[2], data[3]);
  1377. rc = set_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK, data, 4);
  1378. }
  1379. }
  1380. /* mac address */
  1381. else if (strncmp(argv[1], "macaddr", 7) == 0) {
  1382. if(argc != 3)
  1383. {
  1384. print_lan_set_usage();
  1385. return -1;
  1386. }
  1387. rc = str2mac(argv[2], data);
  1388. if (rc == 0) {
  1389. printf("Setting LAN %s to %s\n",
  1390. ipmi_lan_params[IPMI_LANP_MAC_ADDR].desc,
  1391. mac2str(data));
  1392. rc = set_lan_param(intf, chan, IPMI_LANP_MAC_ADDR, data, 6);
  1393. }
  1394. }
  1395. /* default gateway settings */
  1396. else if (strncmp(argv[1], "defgw", 5) == 0) {
  1397. if (argc < 4) {
  1398. print_lan_set_defgw_usage();
  1399. return (-1);
  1400. }
  1401. else if (strncmp(argv[2], "help", 4) == 0) {
  1402. print_lan_set_defgw_usage();
  1403. return 0;
  1404. }
  1405. else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
  1406. (get_cmdline_ipaddr(argv[3], data) == 0)) {
  1407. printf("Setting LAN %s to %d.%d.%d.%d\n",
  1408. ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_IP].desc,
  1409. data[0], data[1], data[2], data[3]);
  1410. rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP, data, 4);
  1411. }
  1412. else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
  1413. (str2mac(argv[3], data) == 0)) {
  1414. printf("Setting LAN %s to %s\n",
  1415. ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_MAC].desc,
  1416. mac2str(data));
  1417. rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC, data, 6);
  1418. }
  1419. else {
  1420. print_lan_set_usage();
  1421. return -1;
  1422. }
  1423. }
  1424. /* backup gateway settings */
  1425. else if (strncmp(argv[1], "bakgw", 5) == 0) {
  1426. if (argc < 4) {
  1427. print_lan_set_bakgw_usage();
  1428. return (-1);
  1429. }
  1430. else if (strncmp(argv[2], "help", 4) == 0) {
  1431. print_lan_set_bakgw_usage();
  1432. return 0;
  1433. }
  1434. else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
  1435. (get_cmdline_ipaddr(argv[3], data) == 0)) {
  1436. printf("Setting LAN %s to %d.%d.%d.%d\n",
  1437. ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_IP].desc,
  1438. data[0], data[1], data[2], data[3]);
  1439. rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP, data, 4);
  1440. }
  1441. else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
  1442. (str2mac(argv[3], data) == 0)) {
  1443. printf("Setting LAN %s to %s\n",
  1444. ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_MAC].desc,
  1445. mac2str(data));
  1446. rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC, data, 6);
  1447. }
  1448. else {
  1449. print_lan_set_usage();
  1450. return -1;
  1451. }
  1452. }
  1453. else if (strncasecmp(argv[1], "vlan", 4) == 0) {
  1454. if (argc < 4) {
  1455. print_lan_set_vlan_usage();
  1456. return (-1);
  1457. }
  1458. else if (strncmp(argv[2], "help", 4) == 0) {
  1459. print_lan_set_vlan_usage();
  1460. return 0;
  1461. }
  1462. else if (strncasecmp(argv[2], "id", 2) == 0) {
  1463. if (strncasecmp(argv[3], "off", 3) == 0) {
  1464. ipmi_lan_set_vlan_id(intf, chan, NULL);
  1465. }
  1466. else {
  1467. ipmi_lan_set_vlan_id(intf, chan, argv[3]);
  1468. }
  1469. }
  1470. else if (strncasecmp(argv[2], "priority", 8) == 0) {
  1471. ipmi_lan_set_vlan_priority(intf, chan, argv[3]);
  1472. }
  1473. else {
  1474. print_lan_set_vlan_usage();
  1475. return (-1);
  1476. }
  1477. }
  1478. /* set PEF alerting on or off */
  1479. else if (strncasecmp(argv[1], "alert", 5) == 0) {
  1480. if (argc < 3) {
  1481. lprintf(LOG_NOTICE, "LAN set alert must be 'on' or 'off'");
  1482. return (-1);
  1483. }
  1484. else if (strncasecmp(argv[2], "on", 2) == 0 ||
  1485. strncasecmp(argv[2], "enable", 6) == 0) {
  1486. printf("Enabling PEF alerts for LAN channel %d\n", chan);
  1487. rc = ipmi_set_alert_enable(intf, chan, 1);
  1488. }
  1489. else if (strncasecmp(argv[2], "off", 3) == 0 ||
  1490. strncasecmp(argv[2], "disable", 7) == 0) {
  1491. printf("Disabling PEF alerts for LAN channel %d\n", chan);
  1492. rc = ipmi_set_alert_enable(intf, chan, 0);
  1493. }
  1494. else {
  1495. lprintf(LOG_NOTICE, "LAN set alert must be 'on' or 'off'");
  1496. return 0;
  1497. }
  1498. }
  1499. /* RMCP+ cipher suite privilege levels */
  1500. else if (strncmp(argv[1], "cipher_privs", 12) == 0)
  1501. {
  1502. if (argc != 3) {
  1503. print_lan_set_cipher_privs_usage();
  1504. return (-1);
  1505. }
  1506. else if ((strncmp(argv[2], "help", 4) == 0) ||
  1507. get_cmdline_cipher_suite_priv_data(argv[2], data))
  1508. {
  1509. print_lan_set_cipher_privs_usage();
  1510. return 0;
  1511. }
  1512. else
  1513. {
  1514. rc = set_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS, data, 9);
  1515. }
  1516. }
  1517. else if (strncmp(argv[1], "bad_pass_thresh", 15) == 0)
  1518. {
  1519. if (argc == 3 && strncmp(argv[2], "help", 4) == 0) {
  1520. print_lan_set_bad_pass_thresh_usage();
  1521. return 0;
  1522. }
  1523. if (argc < 6 || get_cmdline_bad_pass_thresh(&argv[2], data)) {
  1524. print_lan_set_bad_pass_thresh_usage();
  1525. return (-1);
  1526. }
  1527. rc = set_lan_param(intf, chan, IPMI_LANP_BAD_PASS_THRESH, data, 6);
  1528. }
  1529. else {
  1530. print_lan_set_usage();
  1531. return (-1);
  1532. }
  1533. return rc;
  1534. }
  1535. static int
  1536. is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
  1537. {
  1538. struct lan_param * p;
  1539. p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
  1540. if (p == NULL)
  1541. return 0;
  1542. if (p->data == NULL)
  1543. return 0;
  1544. if (alert <= (p->data[0] & 0xf))
  1545. return 1;
  1546. else
  1547. return 0;
  1548. }
  1549. static int
  1550. ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
  1551. {
  1552. # define PTYPE_LEN 4
  1553. # define PADDR_LEN 13
  1554. struct lan_param *lp_ptr = NULL;
  1555. int isack = 0;
  1556. uint8_t ptype[PTYPE_LEN];
  1557. uint8_t paddr[PADDR_LEN];
  1558. lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_TYPE, alert);
  1559. if (lp_ptr == NULL || lp_ptr->data == NULL
  1560. || lp_ptr->data_len < PTYPE_LEN) {
  1561. return (-1);
  1562. }
  1563. memcpy(ptype, lp_ptr->data, PTYPE_LEN);
  1564. lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_ADDR, alert);
  1565. if (lp_ptr == NULL || lp_ptr->data == NULL
  1566. || lp_ptr->data_len < PADDR_LEN) {
  1567. return (-1);
  1568. }
  1569. memcpy(paddr, lp_ptr->data, PADDR_LEN);
  1570. printf("%-24s: %d\n", "Alert Destination",
  1571. ptype[0]);
  1572. if (ptype[1] & 0x80) {
  1573. isack = 1;
  1574. }
  1575. printf("%-24s: %s\n", "Alert Acknowledge",
  1576. isack ? "Acknowledged" : "Unacknowledged");
  1577. printf("%-24s: ", "Destination Type");
  1578. switch (ptype[1] & 0x7) {
  1579. case 0:
  1580. printf("PET Trap\n");
  1581. break;
  1582. case 6:
  1583. printf("OEM 1\n");
  1584. break;
  1585. case 7:
  1586. printf("OEM 2\n");
  1587. break;
  1588. default:
  1589. printf("Unknown\n");
  1590. break;
  1591. }
  1592. printf("%-24s: %d\n",
  1593. isack ? "Acknowledge Timeout" : "Retry Interval",
  1594. ptype[2]);
  1595. printf("%-24s: %d\n", "Number of Retries",
  1596. ptype[3] & 0x7);
  1597. if ((paddr[1] & 0xf0) != 0) {
  1598. /* unknown address format */
  1599. printf("\n");
  1600. return 0;
  1601. }
  1602. printf("%-24s: %s\n", "Alert Gateway",
  1603. (paddr[2] & 1) ? "Backup" : "Default");
  1604. printf("%-24s: %d.%d.%d.%d\n", "Alert IP Address",
  1605. paddr[3], paddr[4], paddr[5], paddr[6]);
  1606. printf("%-24s: %s\n", "Alert MAC Address",
  1607. mac2str(&paddr[7]));
  1608. printf("\n");
  1609. return 0;
  1610. }
  1611. static int
  1612. ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel)
  1613. {
  1614. int j, ndest;
  1615. struct lan_param * p;
  1616. p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
  1617. if (p == NULL)
  1618. return -1;
  1619. if (p->data == NULL)
  1620. return -1;
  1621. ndest = p->data[0] & 0xf;
  1622. for (j=0; j<=ndest; j++) {
  1623. ipmi_lan_alert_print(intf, channel, j);
  1624. }
  1625. return 0;
  1626. }
  1627. static int
  1628. ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
  1629. int argc, char ** argv)
  1630. {
  1631. struct lan_param * p;
  1632. uint8_t data[32], temp[32];
  1633. int rc = 0;
  1634. if (argc < 2) {
  1635. print_lan_alert_set_usage();
  1636. return (-1);
  1637. }
  1638. if (strncmp(argv[0], "help", 4) == 0 ||
  1639. strncmp(argv[1], "help", 4) == 0) {
  1640. print_lan_alert_set_usage();
  1641. return 0;
  1642. }
  1643. memset(data, 0, sizeof(data));
  1644. memset(temp, 0, sizeof(temp));
  1645. /* alert destination ip address */
  1646. if (strncasecmp(argv[0], "ipaddr", 6) == 0 &&
  1647. (get_cmdline_ipaddr(argv[1], temp) == 0)) {
  1648. /* get current parameter */
  1649. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
  1650. if (p == NULL) {
  1651. return (-1);
  1652. }
  1653. memcpy(data, p->data, p->data_len);
  1654. /* set new ipaddr */
  1655. memcpy(data+3, temp, 4);
  1656. printf("Setting LAN Alert %d IP Address to %d.%d.%d.%d\n", alert,
  1657. data[3], data[4], data[5], data[6]);
  1658. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
  1659. }
  1660. /* alert destination mac address */
  1661. else if (strncasecmp(argv[0], "macaddr", 7) == 0 &&
  1662. (str2mac(argv[1], temp) == 0)) {
  1663. /* get current parameter */
  1664. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
  1665. if (p == NULL) {
  1666. return (-1);
  1667. }
  1668. memcpy(data, p->data, p->data_len);
  1669. /* set new macaddr */
  1670. memcpy(data+7, temp, 6);
  1671. printf("Setting LAN Alert %d MAC Address to "
  1672. "%s\n", alert, mac2str(&data[7]));
  1673. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
  1674. }
  1675. /* alert destination gateway selector */
  1676. else if (strncasecmp(argv[0], "gateway", 7) == 0) {
  1677. /* get current parameter */
  1678. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
  1679. if (p == NULL) {
  1680. return (-1);
  1681. }
  1682. memcpy(data, p->data, p->data_len);
  1683. if (strncasecmp(argv[1], "def", 3) == 0 ||
  1684. strncasecmp(argv[1], "default", 7) == 0) {
  1685. printf("Setting LAN Alert %d to use Default Gateway\n", alert);
  1686. data[2] = 0;
  1687. }
  1688. else if (strncasecmp(argv[1], "bak", 3) == 0 ||
  1689. strncasecmp(argv[1], "backup", 6) == 0) {
  1690. printf("Setting LAN Alert %d to use Backup Gateway\n", alert);
  1691. data[2] = 1;
  1692. }
  1693. else {
  1694. print_lan_alert_set_usage();
  1695. return -1;
  1696. }
  1697. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
  1698. }
  1699. /* alert acknowledgement */
  1700. else if (strncasecmp(argv[0], "ack", 3) == 0) {
  1701. /* get current parameter */
  1702. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
  1703. if (p == NULL) {
  1704. return (-1);
  1705. }
  1706. memcpy(data, p->data, p->data_len);
  1707. if (strncasecmp(argv[1], "on", 2) == 0 ||
  1708. strncasecmp(argv[1], "yes", 3) == 0) {
  1709. printf("Setting LAN Alert %d to Acknowledged\n", alert);
  1710. data[1] |= 0x80;
  1711. }
  1712. else if (strncasecmp(argv[1], "off", 3) == 0 ||
  1713. strncasecmp(argv[1], "no", 2) == 0) {
  1714. printf("Setting LAN Alert %d to Unacknowledged\n", alert);
  1715. data[1] &= ~0x80;
  1716. }
  1717. else {
  1718. print_lan_alert_set_usage();
  1719. return -1;
  1720. }
  1721. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
  1722. }
  1723. /* alert destination type */
  1724. else if (strncasecmp(argv[0], "type", 4) == 0) {
  1725. /* get current parameter */
  1726. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
  1727. if (p == NULL) {
  1728. return (-1);
  1729. }
  1730. memcpy(data, p->data, p->data_len);
  1731. if (strncasecmp(argv[1], "pet", 3) == 0) {
  1732. printf("Setting LAN Alert %d destination to PET Trap\n", alert);
  1733. data[1] &= ~0x07;
  1734. }
  1735. else if (strncasecmp(argv[1], "oem1", 4) == 0) {
  1736. printf("Setting LAN Alert %d destination to OEM 1\n", alert);
  1737. data[1] &= ~0x07;
  1738. data[1] |= 0x06;
  1739. }
  1740. else if (strncasecmp(argv[1], "oem2", 4) == 0) {
  1741. printf("Setting LAN Alert %d destination to OEM 2\n", alert);
  1742. data[1] |= 0x07;
  1743. }
  1744. else {
  1745. print_lan_alert_set_usage();
  1746. return -1;
  1747. }
  1748. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
  1749. }
  1750. /* alert acknowledge timeout or retry interval */
  1751. else if (strncasecmp(argv[0], "time", 4) == 0) {
  1752. /* get current parameter */
  1753. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
  1754. if (p == NULL) {
  1755. return (-1);
  1756. }
  1757. memcpy(data, p->data, p->data_len);
  1758. if (str2uchar(argv[1], &data[2]) != 0) {
  1759. lprintf(LOG_ERR, "Invalid time: %s", argv[1]);
  1760. return (-1);
  1761. }
  1762. printf("Setting LAN Alert %d timeout/retry to %d seconds\n", alert, data[2]);
  1763. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
  1764. }
  1765. /* number of retries */
  1766. else if (strncasecmp(argv[0], "retry", 5) == 0) {
  1767. /* get current parameter */
  1768. p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
  1769. if (p == NULL) {
  1770. return (-1);
  1771. }
  1772. memcpy(data, p->data, p->data_len);
  1773. if (str2uchar(argv[1], &data[3]) != 0) {
  1774. lprintf(LOG_ERR, "Invalid retry: %s", argv[1]);
  1775. return (-1);
  1776. }
  1777. data[3] = data[3] & 0x7;
  1778. printf("Setting LAN Alert %d number of retries to %d\n", alert, data[3]);
  1779. rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
  1780. }
  1781. else {
  1782. print_lan_alert_set_usage();
  1783. return -1;
  1784. }
  1785. return rc;
  1786. }
  1787. static int
  1788. ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
  1789. {
  1790. uint8_t alert;
  1791. uint8_t channel = 1;
  1792. if (argc < 1) {
  1793. print_lan_alert_print_usage();
  1794. print_lan_alert_set_usage();
  1795. return (-1);
  1796. }
  1797. else if (strncasecmp(argv[0], "help", 4) == 0) {
  1798. print_lan_alert_print_usage();
  1799. print_lan_alert_set_usage();
  1800. return 0;
  1801. }
  1802. /* alert print [channel] [alert] */
  1803. if (strncasecmp(argv[0], "print", 5) == 0) {
  1804. if (argc < 2) {
  1805. channel = find_lan_channel(intf, 1);
  1806. if (!is_lan_channel(intf, channel)) {
  1807. lprintf(LOG_ERR, "Channel %d is not a LAN channel", channel);
  1808. return -1;
  1809. }
  1810. return ipmi_lan_alert_print_all(intf, channel);
  1811. }
  1812. if (strncasecmp(argv[1], "help", 4) == 0) {
  1813. print_lan_alert_print_usage();
  1814. return 0;
  1815. }
  1816. if (str2uchar(argv[1], &channel) != 0) {
  1817. lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
  1818. return (-1);
  1819. }
  1820. if (!is_lan_channel(intf, channel)) {
  1821. lprintf(LOG_ERR, "Channel %d is not a LAN channel", channel);
  1822. return -1;
  1823. }
  1824. if (argc < 3)
  1825. return ipmi_lan_alert_print_all(intf, channel);
  1826. if (str2uchar(argv[2], &alert) != 0) {
  1827. lprintf(LOG_ERR, "Invalid alert: %s", argv[2]);
  1828. return (-1);
  1829. }
  1830. if (is_alert_destination(intf, channel, alert) == 0) {
  1831. lprintf(LOG_ERR, "Alert %d is not a valid destination", alert);
  1832. return -1;
  1833. }
  1834. return ipmi_lan_alert_print(intf, channel, alert);
  1835. }
  1836. /* alert set <channel> <alert> [option] */
  1837. if (strncasecmp(argv[0], "set", 3) == 0) {
  1838. if (argc < 5) {
  1839. print_lan_alert_set_usage();
  1840. return (-1);
  1841. }
  1842. else if (strncasecmp(argv[1], "help", 4) == 0) {
  1843. print_lan_alert_set_usage();
  1844. return 0;
  1845. }
  1846. if (str2uchar(argv[1], &channel) != 0) {
  1847. lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
  1848. return (-1);
  1849. }
  1850. if (!is_lan_channel(intf, channel)) {
  1851. lprintf(LOG_ERR, "Channel %d is not a LAN channel", channel);
  1852. return -1;
  1853. }
  1854. if (str2uchar(argv[2], &alert) != 0) {
  1855. lprintf(LOG_ERR, "Invalid alert: %s", argv[2]);
  1856. return (-1);
  1857. }
  1858. if (is_alert_destination(intf, channel, alert) == 0) {
  1859. lprintf(LOG_ERR, "Alert %d is not a valid destination", alert);
  1860. return -1;
  1861. }
  1862. return ipmi_lan_alert_set(intf, channel, alert, argc-3, &(argv[3]));
  1863. }
  1864. return 0;
  1865. }
  1866. static int
  1867. ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
  1868. {
  1869. int rc = 0;
  1870. struct ipmi_rs * rsp;
  1871. struct ipmi_rq req;
  1872. uint8_t msg_data[2];
  1873. uint16_t statsTemp;
  1874. if (!is_lan_channel(intf, chan)) {
  1875. lprintf(LOG_ERR, "Channel %d is not a LAN channel", chan);
  1876. return -1;
  1877. }
  1878. /* From here, we are ready to get the stats */
  1879. msg_data[0] = chan;
  1880. msg_data[1] = 0; /* Don't clear */
  1881. memset(&req, 0, sizeof(req));
  1882. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  1883. req.msg.cmd = IPMI_LAN_GET_STAT;
  1884. req.msg.data = msg_data;
  1885. req.msg.data_len = 2;
  1886. rsp = intf->sendrecv(intf, &req);
  1887. if (rsp == NULL) {
  1888. lprintf(LOG_ERR, "Get LAN Stats command failed");
  1889. return (-1);
  1890. }
  1891. if (rsp->ccode > 0) {
  1892. lprintf(LOG_ERR, "Get LAN Stats command failed: %s",
  1893. val2str(rsp->ccode, completion_code_vals));
  1894. return (-1);
  1895. }
  1896. if (verbose > 1) {
  1897. uint8_t counter;
  1898. printf("--- Rx Stats ---\n");
  1899. for (counter=0; counter<18; counter+=2) {
  1900. printf("%02X", *(rsp->data + counter));
  1901. printf(" %02X - ", *(rsp->data + counter+1));
  1902. }
  1903. printf("\n");
  1904. }
  1905. statsTemp = ((*(rsp->data + 0)) << 8) | (*(rsp->data + 1));
  1906. printf("IP Rx Packet : %d\n", statsTemp);
  1907. statsTemp = ((*(rsp->data + 2)) << 8) | (*(rsp->data + 3));
  1908. printf("IP Rx Header Errors : %u\n", statsTemp);
  1909. statsTemp = ((*(rsp->data + 4)) << 8) | (*(rsp->data + 5));
  1910. printf("IP Rx Address Errors : %u\n", statsTemp);
  1911. statsTemp = ((*(rsp->data + 6)) << 8) | (*(rsp->data + 7));
  1912. printf("IP Rx Fragmented : %u\n", statsTemp);
  1913. statsTemp = ((*(rsp->data + 8)) << 8) | (*(rsp->data + 9));
  1914. printf("IP Tx Packet : %u\n", statsTemp);
  1915. statsTemp = ((*(rsp->data +10)) << 8) | (*(rsp->data +11));
  1916. printf("UDP Rx Packet : %u\n", statsTemp);
  1917. statsTemp = ((*(rsp->data + 12)) << 8) | (*(rsp->data + 13));
  1918. printf("RMCP Rx Valid : %u\n", statsTemp);
  1919. statsTemp = ((*(rsp->data + 14)) << 8) | (*(rsp->data + 15));
  1920. printf("UDP Proxy Packet Received : %u\n", statsTemp);
  1921. statsTemp = ((*(rsp->data + 16)) << 8) | (*(rsp->data + 17));
  1922. printf("UDP Proxy Packet Dropped : %u\n", statsTemp);
  1923. return rc;
  1924. }
  1925. static int
  1926. ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan)
  1927. {
  1928. int rc = 0;
  1929. struct ipmi_rs * rsp;
  1930. struct ipmi_rq req;
  1931. uint8_t msg_data[2];
  1932. if (!is_lan_channel(intf, chan)) {
  1933. lprintf(LOG_ERR, "Channel %d is not a LAN channel", chan);
  1934. return -1;
  1935. }
  1936. /* From here, we are ready to get the stats */
  1937. msg_data[0] = chan;
  1938. msg_data[1] = 1; /* Clear */
  1939. memset(&req, 0, sizeof(req));
  1940. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  1941. req.msg.cmd = IPMI_LAN_GET_STAT;
  1942. req.msg.data = msg_data;
  1943. req.msg.data_len = 2;
  1944. rsp = intf->sendrecv(intf, &req);
  1945. if (rsp == NULL) {
  1946. lprintf(LOG_INFO, "Get LAN Stats command failed");
  1947. return (-1);
  1948. }
  1949. if (rsp->ccode > 0) {
  1950. lprintf(LOG_INFO, "Get LAN Stats command failed: %s",
  1951. val2str(rsp->ccode, completion_code_vals));
  1952. return (-1);
  1953. }
  1954. return rc;
  1955. }
  1956. static void
  1957. print_lan_alert_print_usage(void)
  1958. {
  1959. lprintf(LOG_NOTICE,
  1960. "");
  1961. lprintf(LOG_NOTICE,
  1962. "usage: lan alert print [channel number] [alert destination]");
  1963. lprintf(LOG_NOTICE,
  1964. "");
  1965. lprintf(LOG_NOTICE,
  1966. "Default will print all alerts for the first found LAN channel");
  1967. }
  1968. static void
  1969. print_lan_alert_set_usage(void)
  1970. {
  1971. lprintf(LOG_NOTICE,
  1972. "");
  1973. lprintf(LOG_NOTICE,
  1974. "usage: lan alert set <channel number> <alert destination> <command> <parameter>");
  1975. lprintf(LOG_NOTICE,
  1976. "");
  1977. lprintf(LOG_NOTICE,
  1978. " Command/parameter options:");
  1979. lprintf(LOG_NOTICE,
  1980. "");
  1981. lprintf(LOG_NOTICE,
  1982. " ipaddr <x.x.x.x> Set alert IP address");
  1983. lprintf(LOG_NOTICE,
  1984. " macaddr <x:x:x:x:x:x> Set alert MAC address");
  1985. lprintf(LOG_NOTICE,
  1986. " gateway <default|backup> Set channel gateway to use for alerts");
  1987. lprintf(LOG_NOTICE,
  1988. " ack <on|off> Set Alert Acknowledge on or off");
  1989. lprintf(LOG_NOTICE,
  1990. " type <pet|oem1|oem2> Set destination type as PET or OEM");
  1991. lprintf(LOG_NOTICE,
  1992. " time <seconds> Set ack timeout or unack retry interval");
  1993. lprintf(LOG_NOTICE,
  1994. " retry <number> Set number of alert retries");
  1995. lprintf(LOG_NOTICE,
  1996. "");
  1997. }
  1998. static void
  1999. print_lan_set_usage(void)
  2000. {
  2001. lprintf(LOG_NOTICE,
  2002. "");
  2003. lprintf(LOG_NOTICE,
  2004. "usage: lan set <channel> <command> <parameter>");
  2005. lprintf(LOG_NOTICE,
  2006. "");
  2007. lprintf(LOG_NOTICE,
  2008. "LAN set command/parameter options:");
  2009. lprintf(LOG_NOTICE,
  2010. " ipaddr <x.x.x.x> Set channel IP address");
  2011. lprintf(LOG_NOTICE,
  2012. " netmask <x.x.x.x> Set channel IP netmask");
  2013. lprintf(LOG_NOTICE,
  2014. " macaddr <x:x:x:x:x:x> Set channel MAC address");
  2015. lprintf(LOG_NOTICE,
  2016. " defgw ipaddr <x.x.x.x> Set default gateway IP address");
  2017. lprintf(LOG_NOTICE,
  2018. " defgw macaddr <x:x:x:x:x:x> Set default gateway MAC address");
  2019. lprintf(LOG_NOTICE,
  2020. " bakgw ipaddr <x.x.x.x> Set backup gateway IP address");
  2021. lprintf(LOG_NOTICE,
  2022. " bakgw macaddr <x:x:x:x:x:x> Set backup gateway MAC address");
  2023. lprintf(LOG_NOTICE,
  2024. " password <password> Set session password for this channel");
  2025. lprintf(LOG_NOTICE,
  2026. " snmp <community string> Set SNMP public community string");
  2027. lprintf(LOG_NOTICE,
  2028. " user Enable default user for this channel");
  2029. lprintf(LOG_NOTICE,
  2030. " access <on|off> Enable or disable access to this channel");
  2031. lprintf(LOG_NOTICE,
  2032. " alert <on|off> Enable or disable PEF alerting for this channel");
  2033. lprintf(LOG_NOTICE,
  2034. " arp respond <on|off> Enable or disable BMC ARP responding");
  2035. lprintf(LOG_NOTICE,
  2036. " arp generate <on|off> Enable or disable BMC gratuitous ARP generation");
  2037. lprintf(LOG_NOTICE,
  2038. " arp interval <seconds> Set gratuitous ARP generation interval");
  2039. lprintf(LOG_NOTICE,
  2040. " vlan id <off|<id>> Disable or enable VLAN and set ID (1-4094)");
  2041. lprintf(LOG_NOTICE,
  2042. " vlan priority <priority> Set vlan priority (0-7)");
  2043. lprintf(LOG_NOTICE,
  2044. " auth <level> <type,..> Set channel authentication types");
  2045. lprintf(LOG_NOTICE,
  2046. " level = CALLBACK, USER, OPERATOR, ADMIN");
  2047. lprintf(LOG_NOTICE,
  2048. " type = NONE, MD2, MD5, PASSWORD, OEM");
  2049. lprintf(LOG_NOTICE,
  2050. " ipsrc <source> Set IP Address source");
  2051. lprintf(LOG_NOTICE,
  2052. " none = unspecified source");
  2053. lprintf(LOG_NOTICE,
  2054. " static = address manually configured to be static");
  2055. lprintf(LOG_NOTICE,
  2056. " dhcp = address obtained by BMC running DHCP");
  2057. lprintf(LOG_NOTICE,
  2058. " bios = address loaded by BIOS or system software");
  2059. lprintf(LOG_NOTICE,
  2060. " cipher_privs XXXXXXXXXXXXXXX Set RMCP+ cipher suite privilege levels");
  2061. lprintf(LOG_NOTICE,
  2062. " X = Cipher Suite Unused");
  2063. lprintf(LOG_NOTICE,
  2064. " c = CALLBACK");
  2065. lprintf(LOG_NOTICE,
  2066. " u = USER");
  2067. lprintf(LOG_NOTICE,
  2068. " o = OPERATOR");
  2069. lprintf(LOG_NOTICE,
  2070. " a = ADMIN");
  2071. lprintf(LOG_NOTICE,
  2072. " O = OEM");
  2073. lprintf(LOG_NOTICE,
  2074. "");
  2075. lprintf(LOG_NOTICE,
  2076. " bad_pass_thresh <thresh_num> <1|0> <reset_interval> <lockout_interval>\n"
  2077. " Set bad password threshold");
  2078. }
  2079. static void
  2080. print_lan_set_access_usage(void)
  2081. {
  2082. lprintf(LOG_NOTICE,
  2083. "lan set access <on|off>");
  2084. }
  2085. static void
  2086. print_lan_set_arp_usage(void)
  2087. {
  2088. lprintf(LOG_NOTICE,
  2089. "lan set <channel> arp respond <on|off>");
  2090. lprintf(LOG_NOTICE,
  2091. "lan set <channel> arp generate <on|off>");
  2092. lprintf(LOG_NOTICE,
  2093. "lan set <channel> arp interval <seconds>");
  2094. lprintf(LOG_NOTICE,
  2095. "");
  2096. lprintf(LOG_NOTICE,
  2097. "example: lan set 7 arp gratuitous off");
  2098. }
  2099. static void
  2100. print_lan_set_auth_usage(void)
  2101. {
  2102. lprintf(LOG_NOTICE,
  2103. "lan set <channel> auth <level> <type,type,...>");
  2104. lprintf(LOG_NOTICE,
  2105. " level = CALLBACK, USER, OPERATOR, ADMIN");
  2106. lprintf(LOG_NOTICE,
  2107. " types = NONE, MD2, MD5, PASSWORD, OEM");
  2108. lprintf(LOG_NOTICE,
  2109. "example: lan set 7 auth ADMIN PASSWORD,MD5");
  2110. }
  2111. static void
  2112. print_lan_set_bakgw_usage(void)
  2113. {
  2114. lprintf(LOG_NOTICE,
  2115. "LAN set backup gateway commands: ipaddr, macaddr");
  2116. }
  2117. static void
  2118. print_lan_set_cipher_privs_usage(void)
  2119. {
  2120. lprintf(LOG_NOTICE,
  2121. "lan set <channel> cipher_privs XXXXXXXXXXXXXXX");
  2122. lprintf(LOG_NOTICE,
  2123. " X = Cipher Suite Unused");
  2124. lprintf(LOG_NOTICE,
  2125. " c = CALLBACK");
  2126. lprintf(LOG_NOTICE,
  2127. " u = USER");
  2128. lprintf(LOG_NOTICE,
  2129. " o = OPERATOR");
  2130. lprintf(LOG_NOTICE,
  2131. " a = ADMIN");
  2132. lprintf(LOG_NOTICE,
  2133. " O = OEM");
  2134. lprintf(LOG_NOTICE,
  2135. "");
  2136. }
  2137. static void
  2138. print_lan_set_defgw_usage(void)
  2139. {
  2140. lprintf(LOG_NOTICE,
  2141. "LAN set default gateway Commands: ipaddr, macaddr");
  2142. }
  2143. static void
  2144. print_lan_set_ipsrc_usage(void)
  2145. {
  2146. lprintf(LOG_NOTICE,
  2147. "lan set <channel> ipsrc <source>");
  2148. lprintf(LOG_NOTICE,
  2149. " none = unspecified");
  2150. lprintf(LOG_NOTICE,
  2151. " static = static address (manually configured)");
  2152. lprintf(LOG_NOTICE,
  2153. " dhcp = address obtained by BMC running DHCP");
  2154. lprintf(LOG_NOTICE,
  2155. " bios = address loaded by BIOS or system software");
  2156. }
  2157. static void
  2158. print_lan_set_snmp_usage(void)
  2159. {
  2160. lprintf(LOG_NOTICE,
  2161. "lan set <channel> snmp <community string>");
  2162. }
  2163. static void
  2164. print_lan_set_vlan_usage(void)
  2165. {
  2166. lprintf(LOG_NOTICE,
  2167. "lan set <channel> vlan id <id>");
  2168. lprintf(LOG_NOTICE,
  2169. "lan set <channel> vlan id off");
  2170. lprintf(LOG_NOTICE,
  2171. "lan set <channel> vlan priority <priority>");
  2172. }
  2173. /*
  2174. * print_lan_usage
  2175. */
  2176. static void
  2177. print_lan_usage(void)
  2178. {
  2179. lprintf(LOG_NOTICE,
  2180. "LAN Commands:");
  2181. lprintf(LOG_NOTICE,
  2182. " print [<channel number>]");
  2183. lprintf(LOG_NOTICE,
  2184. " set <channel number> <command> <parameter>");
  2185. lprintf(LOG_NOTICE,
  2186. " alert print <channel number> <alert destination>");
  2187. lprintf(LOG_NOTICE,
  2188. " alert set <channel number> <alert destination> <command> <parameter>");
  2189. lprintf(LOG_NOTICE,
  2190. " stats get [<channel number>]");
  2191. lprintf(LOG_NOTICE,
  2192. " stats clear [<channel number>]");
  2193. }
  2194. int
  2195. ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
  2196. {
  2197. int rc = 0;
  2198. uint8_t chan = 0;
  2199. if (argc == 0) {
  2200. print_lan_usage();
  2201. return (-1);
  2202. } else if (strncmp(argv[0], "help", 4) == 0) {
  2203. print_lan_usage();
  2204. return 0;
  2205. }
  2206. if (strncmp(argv[0], "printconf", 9) == 0 ||
  2207. strncmp(argv[0], "print", 5) == 0)
  2208. {
  2209. if (argc > 2) {
  2210. print_lan_usage();
  2211. return (-1);
  2212. } else if (argc == 2) {
  2213. if (str2uchar(argv[1], &chan) != 0) {
  2214. lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
  2215. return (-1);
  2216. }
  2217. } else {
  2218. chan = find_lan_channel(intf, 1);
  2219. }
  2220. if (!is_lan_channel(intf, chan)) {
  2221. lprintf(LOG_ERR, "Invalid channel: %d", chan);
  2222. return (-1);
  2223. }
  2224. rc = ipmi_lan_print(intf, chan);
  2225. } else if (strncmp(argv[0], "set", 3) == 0) {
  2226. rc = ipmi_lan_set(intf, argc-1, &(argv[1]));
  2227. } else if (strncmp(argv[0], "alert", 5) == 0) {
  2228. rc = ipmi_lan_alert(intf, argc-1, &(argv[1]));
  2229. } else if (strncmp(argv[0], "stats", 5) == 0) {
  2230. if (argc < 2) {
  2231. print_lan_usage();
  2232. return (-1);
  2233. } else if (argc == 3) {
  2234. if (str2uchar(argv[2], &chan) != 0) {
  2235. lprintf(LOG_ERR, "Invalid channel: %s", argv[2]);
  2236. return (-1);
  2237. }
  2238. } else {
  2239. chan = find_lan_channel(intf, 1);
  2240. }
  2241. if (!is_lan_channel(intf, chan)) {
  2242. lprintf(LOG_ERR, "Invalid channel: %d", chan);
  2243. return (-1);
  2244. }
  2245. if (strncmp(argv[1], "get", 3) == 0) {
  2246. rc = ipmi_lan_stats_get(intf, chan);
  2247. } else if (strncmp(argv[1], "clear", 5) == 0) {
  2248. rc = ipmi_lan_stats_clear(intf, chan);
  2249. } else {
  2250. print_lan_usage();
  2251. return (-1);
  2252. }
  2253. } else {
  2254. lprintf(LOG_NOTICE, "Invalid LAN command: %s", argv[0]);
  2255. return (-1);
  2256. }
  2257. return rc;
  2258. }