ipmi_lanp.c 64 KB

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