ipmi_lanp.c 64 KB

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