ipmi_sol.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  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. #define _XOPEN_SOURCE
  33. #define _BSD_SOURCE || \
  34. (_XOPEN_SOURCE >= 500 || \
  35. _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
  36. !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <strings.h>
  40. #include <stdio.h>
  41. #include <sys/types.h>
  42. #include <sys/stat.h>
  43. #include <sys/select.h>
  44. #include <sys/time.h>
  45. #include <time.h>
  46. #include <signal.h>
  47. #include <unistd.h>
  48. #if defined(HAVE_CONFIG_H)
  49. # include <config.h>
  50. #endif
  51. #if defined(HAVE_TERMIOS_H)
  52. # include <termios.h>
  53. #elif defined (HAVE_SYS_TERMIOS_H)
  54. # include <sys/termios.h>
  55. #endif
  56. #include <ipmitool/helper.h>
  57. #include <ipmitool/log.h>
  58. #include <ipmitool/ipmi.h>
  59. #include <ipmitool/ipmi_intf.h>
  60. #include <ipmitool/ipmi_sol.h>
  61. #include <ipmitool/ipmi_strings.h>
  62. #include <ipmitool/bswap.h>
  63. #define SOL_PARAMETER_SET_IN_PROGRESS 0x00
  64. #define SOL_PARAMETER_SOL_ENABLE 0x01
  65. #define SOL_PARAMETER_SOL_AUTHENTICATION 0x02
  66. #define SOL_PARAMETER_CHARACTER_INTERVAL 0x03
  67. #define SOL_PARAMETER_SOL_RETRY 0x04
  68. #define SOL_PARAMETER_SOL_NON_VOLATILE_BIT_RATE 0x05
  69. #define SOL_PARAMETER_SOL_VOLATILE_BIT_RATE 0x06
  70. #define SOL_PARAMETER_SOL_PAYLOAD_CHANNEL 0x07
  71. #define SOL_PARAMETER_SOL_PAYLOAD_PORT 0x08
  72. #define MAX_SOL_RETRY 6
  73. const struct valstr sol_parameter_vals[] = {
  74. { SOL_PARAMETER_SET_IN_PROGRESS, "Set In Progress (0)" },
  75. { SOL_PARAMETER_SOL_ENABLE, "Enable (1)" },
  76. { SOL_PARAMETER_SOL_AUTHENTICATION, "Authentication (2)" },
  77. { SOL_PARAMETER_CHARACTER_INTERVAL, "Character Interval (3)" },
  78. { SOL_PARAMETER_SOL_RETRY, "Retry (4)" },
  79. { SOL_PARAMETER_SOL_NON_VOLATILE_BIT_RATE, "Nonvolatile Bitrate (5)" },
  80. { SOL_PARAMETER_SOL_VOLATILE_BIT_RATE, "Volatile Bitrate (6)" },
  81. { SOL_PARAMETER_SOL_PAYLOAD_CHANNEL, "Payload Channel (7)" },
  82. { SOL_PARAMETER_SOL_PAYLOAD_PORT, "Payload Port (8)" },
  83. { 0x00, NULL },
  84. };
  85. static struct timeval _start_keepalive;
  86. static struct termios _saved_tio;
  87. static int _in_raw_mode = 0;
  88. static int _disable_keepalive = 0;
  89. static int _use_sol_for_keepalive = 0;
  90. extern int verbose;
  91. /*
  92. * ipmi_sol_payload_access
  93. */
  94. int
  95. ipmi_sol_payload_access(struct ipmi_intf * intf, uint8_t channel,
  96. uint8_t userid, int enable)
  97. {
  98. struct ipmi_rq req;
  99. struct ipmi_rs *rsp;
  100. int rc = (-1);
  101. uint8_t data[6];
  102. memset(&req, 0, sizeof(req));
  103. req.msg.netfn = IPMI_NETFN_APP;
  104. req.msg.cmd = IPMI_SET_USER_PAYLOAD_ACCESS;
  105. req.msg.data = data;
  106. req.msg.data_len = 6;
  107. memset(data, 0, 6);
  108. /* channel */
  109. data[0] = channel & 0xf;
  110. /* user id */
  111. data[1] = userid & 0x3f;
  112. if (!enable) {
  113. /* disable */
  114. data[1] |= 0x40;
  115. }
  116. /* payload 1 is SOL */
  117. data[2] = 0x02;
  118. rsp = intf->sendrecv(intf, &req);
  119. if (rsp == NULL) {
  120. lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d",
  121. enable ? "en" : "dis", userid, channel);
  122. rc = (-1);
  123. } else if (rsp->ccode != 0) {
  124. lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d: %s",
  125. enable ? "en" : "dis", userid, channel,
  126. val2str(rsp->ccode, completion_code_vals));
  127. rc = (-1);
  128. } else {
  129. rc = 0;
  130. }
  131. return rc;
  132. }
  133. int
  134. ipmi_sol_payload_access_status(struct ipmi_intf * intf,
  135. uint8_t channel,
  136. uint8_t userid)
  137. {
  138. struct ipmi_rq req;
  139. struct ipmi_rs *rsp;
  140. uint8_t data[2];
  141. memset(&req, 0, sizeof(req));
  142. req.msg.netfn = IPMI_NETFN_APP;
  143. req.msg.cmd = IPMI_GET_USER_PAYLOAD_ACCESS;
  144. req.msg.data = data;
  145. req.msg.data_len = sizeof(data);
  146. data[0] = channel & 0xf; /* channel */
  147. data[1] = userid & 0x3f; /* user id */
  148. rsp = intf->sendrecv(intf, &req);
  149. if (rsp == NULL) {
  150. lprintf(LOG_ERR, "Error. No valid response received.");
  151. return -1;
  152. }
  153. switch(rsp->ccode) {
  154. case 0x00:
  155. if (rsp->data_len != 4) {
  156. lprintf(LOG_ERR, "Error parsing SOL payload status for user %d on channel %d",
  157. userid, channel);
  158. return -1;
  159. }
  160. printf("User %d on channel %d is %sabled\n",
  161. userid, channel, (rsp->data[0] & 0x02) ? "en":"dis");
  162. return 0;
  163. default:
  164. lprintf(LOG_ERR, "Error getting SOL payload status for user %d on channel %d: %s",
  165. userid, channel,
  166. val2str(rsp->ccode, completion_code_vals));
  167. return -1;
  168. }
  169. }
  170. /*
  171. * ipmi_get_sol_info
  172. */
  173. int
  174. ipmi_get_sol_info(
  175. struct ipmi_intf * intf,
  176. uint8_t channel,
  177. struct sol_config_parameters * params)
  178. {
  179. struct ipmi_rs * rsp;
  180. struct ipmi_rq req;
  181. uint8_t data[4];
  182. memset(&req, 0, sizeof(req));
  183. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  184. req.msg.cmd = IPMI_GET_SOL_CONFIG_PARAMETERS;
  185. req.msg.data_len = 4;
  186. req.msg.data = data;
  187. /*
  188. * set in progress
  189. */
  190. memset(data, 0, sizeof(data));
  191. data[0] = channel; /* channel number */
  192. data[1] = SOL_PARAMETER_SET_IN_PROGRESS; /* parameter selector */
  193. data[2] = 0x00; /* set selector */
  194. data[3] = 0x00; /* block selector */
  195. rsp = intf->sendrecv(intf, &req);
  196. if (rsp == NULL) {
  197. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  198. val2str(data[1], sol_parameter_vals));
  199. return (-1);
  200. }
  201. switch (rsp->ccode) {
  202. case 0x00:
  203. if (rsp->data_len == 2) {
  204. params->set_in_progress = rsp->data[1];
  205. } else {
  206. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  207. "for SOL parameter '%s'",
  208. rsp->data_len,
  209. val2str(data[1], sol_parameter_vals));
  210. }
  211. break;
  212. case 0x80:
  213. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  214. val2str(data[1], sol_parameter_vals));
  215. break;
  216. default:
  217. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  218. val2str(data[1], sol_parameter_vals),
  219. val2str(rsp->ccode, completion_code_vals));
  220. return (-1);
  221. }
  222. /*
  223. * SOL enable
  224. */
  225. memset(data, 0, sizeof(data));
  226. data[0] = channel; /* channel number */
  227. data[1] = SOL_PARAMETER_SOL_ENABLE; /* parameter selector */
  228. data[2] = 0x00; /* set selector */
  229. data[3] = 0x00; /* block selector */
  230. rsp = intf->sendrecv(intf, &req);
  231. if (rsp == NULL) {
  232. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  233. val2str(data[1], sol_parameter_vals));
  234. return (-1);
  235. }
  236. switch (rsp->ccode) {
  237. case 0x00:
  238. if (rsp->data_len == 2) {
  239. params->enabled = rsp->data[1];
  240. } else {
  241. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  242. "for SOL parameter '%s'",
  243. rsp->data_len,
  244. val2str(data[1], sol_parameter_vals));
  245. }
  246. break;
  247. case 0x80:
  248. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  249. val2str(data[1], sol_parameter_vals));
  250. break;
  251. default:
  252. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  253. val2str(data[1], sol_parameter_vals),
  254. val2str(rsp->ccode, completion_code_vals));
  255. return (-1);
  256. }
  257. /*
  258. * SOL authentication
  259. */
  260. memset(data, 0, sizeof(data));
  261. data[0] = channel; /* channel number */
  262. data[1] = SOL_PARAMETER_SOL_AUTHENTICATION; /* parameter selector */
  263. data[2] = 0x00; /* set selector */
  264. data[3] = 0x00; /* block selector */
  265. rsp = intf->sendrecv(intf, &req);
  266. if (rsp == NULL) {
  267. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  268. val2str(data[1], sol_parameter_vals));
  269. return (-1);
  270. }
  271. switch (rsp->ccode) {
  272. case 0x00:
  273. if (rsp->data_len == 2) {
  274. params->force_encryption = ((rsp->data[1] & 0x80)? 1 : 0);
  275. params->force_authentication = ((rsp->data[1] & 0x40)? 1 : 0);
  276. params->privilege_level = rsp->data[1] & 0x0F;
  277. } else {
  278. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  279. "for SOL parameter '%s'",
  280. rsp->data_len,
  281. val2str(data[1], sol_parameter_vals));
  282. }
  283. break;
  284. case 0x80:
  285. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  286. val2str(data[1], sol_parameter_vals));
  287. break;
  288. default:
  289. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  290. val2str(data[1], sol_parameter_vals),
  291. val2str(rsp->ccode, completion_code_vals));
  292. return (-1);
  293. }
  294. /*
  295. * Character accumulate interval and character send interval
  296. */
  297. memset(data, 0, sizeof(data));
  298. data[0] = channel; /* channel number */
  299. data[1] = SOL_PARAMETER_CHARACTER_INTERVAL; /* parameter selector */
  300. data[2] = 0x00; /* set selector */
  301. data[3] = 0x00; /* block selector */
  302. rsp = intf->sendrecv(intf, &req);
  303. if (rsp == NULL) {
  304. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  305. val2str(data[1], sol_parameter_vals));
  306. return (-1);
  307. }
  308. switch (rsp->ccode) {
  309. case 0x00:
  310. if (rsp->data_len == 3) {
  311. params->character_accumulate_level = rsp->data[1];
  312. params->character_send_threshold = rsp->data[2];
  313. } else {
  314. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  315. "for SOL parameter '%s'",
  316. rsp->data_len,
  317. val2str(data[1], sol_parameter_vals));
  318. }
  319. break;
  320. case 0x80:
  321. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  322. val2str(data[1], sol_parameter_vals));
  323. break;
  324. default:
  325. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  326. val2str(data[1], sol_parameter_vals),
  327. val2str(rsp->ccode, completion_code_vals));
  328. return (-1);
  329. }
  330. /*
  331. * SOL retry
  332. */
  333. memset(data, 0, sizeof(data));
  334. data[0] = channel; /* channel number */
  335. data[1] = SOL_PARAMETER_SOL_RETRY; /* parameter selector */
  336. data[2] = 0x00; /* set selector */
  337. data[3] = 0x00; /* block selector */
  338. rsp = intf->sendrecv(intf, &req);
  339. if (rsp == NULL) {
  340. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  341. val2str(data[1], sol_parameter_vals));
  342. return (-1);
  343. }
  344. switch (rsp->ccode) {
  345. case 0x00:
  346. if (rsp->data_len == 3) {
  347. params->retry_count = rsp->data[1];
  348. params->retry_interval = rsp->data[2];
  349. } else {
  350. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  351. "for SOL parameter '%s'",
  352. rsp->data_len,
  353. val2str(data[1], sol_parameter_vals));
  354. }
  355. break;
  356. case 0x80:
  357. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  358. val2str(data[1], sol_parameter_vals));
  359. break;
  360. default:
  361. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  362. val2str(data[1], sol_parameter_vals),
  363. val2str(rsp->ccode, completion_code_vals));
  364. return (-1);
  365. }
  366. /*
  367. * SOL non-volatile bit rate
  368. */
  369. memset(data, 0, sizeof(data));
  370. data[0] = channel; /* channel number */
  371. data[1] = SOL_PARAMETER_SOL_NON_VOLATILE_BIT_RATE; /* parameter selector */
  372. data[2] = 0x00; /* set selector */
  373. data[3] = 0x00; /* block selector */
  374. rsp = intf->sendrecv(intf, &req);
  375. if (rsp == NULL) {
  376. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  377. val2str(data[1], sol_parameter_vals));
  378. return (-1);
  379. }
  380. switch (rsp->ccode) {
  381. case 0x00:
  382. if (rsp->data_len == 2) {
  383. params->non_volatile_bit_rate = rsp->data[1] & 0x0F;
  384. } else {
  385. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  386. "for SOL parameter '%s'",
  387. rsp->data_len,
  388. val2str(data[1], sol_parameter_vals));
  389. }
  390. break;
  391. case 0x80:
  392. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  393. val2str(data[1], sol_parameter_vals));
  394. break;
  395. default:
  396. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  397. val2str(data[1], sol_parameter_vals),
  398. val2str(rsp->ccode, completion_code_vals));
  399. return (-1);
  400. }
  401. /*
  402. * SOL volatile bit rate
  403. */
  404. memset(data, 0, sizeof(data));
  405. data[0] = channel; /* channel number */
  406. data[1] = SOL_PARAMETER_SOL_VOLATILE_BIT_RATE; /* parameter selector */
  407. data[2] = 0x00; /* set selector */
  408. data[3] = 0x00; /* block selector */
  409. rsp = intf->sendrecv(intf, &req);
  410. if (rsp == NULL) {
  411. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  412. val2str(data[1], sol_parameter_vals));
  413. return (-1);
  414. }
  415. switch (rsp->ccode) {
  416. case 0x00:
  417. if (rsp->data_len == 2) {
  418. params->volatile_bit_rate = rsp->data[1] & 0x0F;
  419. } else {
  420. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  421. "for SOL parameter '%s'",
  422. rsp->data_len,
  423. val2str(data[1], sol_parameter_vals));
  424. }
  425. break;
  426. case 0x80:
  427. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported",
  428. val2str(data[1], sol_parameter_vals));
  429. break;
  430. default:
  431. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  432. val2str(data[1], sol_parameter_vals),
  433. val2str(rsp->ccode, completion_code_vals));
  434. return (-1);
  435. }
  436. /*
  437. * SOL payload channel
  438. */
  439. memset(data, 0, sizeof(data));
  440. data[0] = channel; /* channel number */
  441. data[1] = SOL_PARAMETER_SOL_PAYLOAD_CHANNEL; /* parameter selector */
  442. data[2] = 0x00; /* set selector */
  443. data[3] = 0x00; /* block selector */
  444. rsp = intf->sendrecv(intf, &req);
  445. if (rsp == NULL) {
  446. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  447. val2str(data[1], sol_parameter_vals));
  448. return (-1);
  449. }
  450. switch (rsp->ccode) {
  451. case 0x00:
  452. if (rsp->data_len == 2) {
  453. params->payload_channel = rsp->data[1];
  454. } else {
  455. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  456. "for SOL parameter '%s'",
  457. rsp->data_len,
  458. val2str(data[1], sol_parameter_vals));
  459. }
  460. break;
  461. case 0x80:
  462. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported - defaulting to 0x%02x",
  463. val2str(data[1], sol_parameter_vals), channel);
  464. params->payload_channel = channel;
  465. break;
  466. default:
  467. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  468. val2str(data[1], sol_parameter_vals),
  469. val2str(rsp->ccode, completion_code_vals));
  470. return (-1);
  471. }
  472. /*
  473. * SOL payload port
  474. */
  475. memset(data, 0, sizeof(data));
  476. data[0] = channel; /* channel number */
  477. data[1] = SOL_PARAMETER_SOL_PAYLOAD_PORT; /* parameter selector */
  478. data[2] = 0x00; /* set selector */
  479. data[3] = 0x00; /* block selector */
  480. rsp = intf->sendrecv(intf, &req);
  481. if (rsp == NULL) {
  482. lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
  483. val2str(data[1], sol_parameter_vals));
  484. return (-1);
  485. }
  486. switch (rsp->ccode) {
  487. case 0x00:
  488. if (rsp->data_len == 3) {
  489. params->payload_port = (rsp->data[1]) | (rsp->data[2] << 8);
  490. } else {
  491. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  492. "for SOL parameter '%s'",
  493. rsp->data_len,
  494. val2str(data[1], sol_parameter_vals));
  495. }
  496. break;
  497. case 0x80:
  498. if( intf->session != NULL ) {
  499. lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported - defaulting to %d",
  500. val2str(data[1], sol_parameter_vals), intf->ssn_params.port);
  501. params->payload_port = intf->ssn_params.port;
  502. } else {
  503. lprintf(LOG_ERR,
  504. "Info: SOL parameter '%s' not supported - can't determine which "
  505. "payload port to use on NULL session",
  506. val2str(data[1], sol_parameter_vals));
  507. return (-1);
  508. }
  509. break;
  510. default:
  511. lprintf(LOG_ERR, "Error requesting SOL parameter '%s': %s",
  512. val2str(data[1], sol_parameter_vals),
  513. val2str(rsp->ccode, completion_code_vals));
  514. return (-1);
  515. }
  516. return 0;
  517. }
  518. /*
  519. * ipmi_print_sol_info
  520. */
  521. static int
  522. ipmi_print_sol_info(struct ipmi_intf * intf, uint8_t channel)
  523. {
  524. struct sol_config_parameters params = {0};
  525. if (ipmi_get_sol_info(intf, channel, &params))
  526. return -1;
  527. if (csv_output)
  528. {
  529. printf("%s,",
  530. val2str(params.set_in_progress & 0x03,
  531. ipmi_set_in_progress_vals));
  532. printf("%s,", params.enabled?"true": "false");
  533. printf("%s,", params.force_encryption?"true":"false");
  534. printf("%s,", params.force_encryption?"true":"false");
  535. printf("%s,",
  536. val2str(params.privilege_level, ipmi_privlvl_vals));
  537. printf("%d,", params.character_accumulate_level * 5);
  538. printf("%d,", params.character_send_threshold);
  539. printf("%d,", params.retry_count);
  540. printf("%d,", params.retry_interval * 10);
  541. printf("%s,",
  542. val2str(params.volatile_bit_rate, ipmi_bit_rate_vals));
  543. printf("%s,",
  544. val2str(params.non_volatile_bit_rate, ipmi_bit_rate_vals));
  545. printf("%d,", params.payload_channel);
  546. printf("%d\n", params.payload_port);
  547. }
  548. else
  549. {
  550. printf("Set in progress : %s\n",
  551. val2str(params.set_in_progress & 0x03,
  552. ipmi_set_in_progress_vals));
  553. printf("Enabled : %s\n",
  554. params.enabled?"true": "false");
  555. printf("Force Encryption : %s\n",
  556. params.force_encryption?"true":"false");
  557. printf("Force Authentication : %s\n",
  558. params.force_authentication?"true":"false");
  559. printf("Privilege Level : %s\n",
  560. val2str(params.privilege_level, ipmi_privlvl_vals));
  561. printf("Character Accumulate Level (ms) : %d\n",
  562. params.character_accumulate_level * 5);
  563. printf("Character Send Threshold : %d\n",
  564. params.character_send_threshold);
  565. printf("Retry Count : %d\n",
  566. params.retry_count);
  567. printf("Retry Interval (ms) : %d\n",
  568. params.retry_interval * 10);
  569. printf("Volatile Bit Rate (kbps) : %s\n",
  570. val2str(params.volatile_bit_rate, ipmi_bit_rate_vals));
  571. printf("Non-Volatile Bit Rate (kbps) : %s\n",
  572. val2str(params.non_volatile_bit_rate, ipmi_bit_rate_vals));
  573. printf("Payload Channel : %d (0x%02x)\n",
  574. params.payload_channel, params.payload_channel);
  575. printf("Payload Port : %d\n",
  576. params.payload_port);
  577. }
  578. return 0;
  579. }
  580. /*
  581. * Small function to validate that user-supplied SOL
  582. * configuration parameter values we store in uint8_t
  583. * data type falls within valid range. With minval
  584. * and maxval parameters we can use the same function
  585. * to validate parameters that have different ranges
  586. * of values.
  587. *
  588. * function will return -1 if value is not valid, or
  589. * will return 0 if valid.
  590. */
  591. int ipmi_sol_set_param_isvalid_uint8_t( const char *strval,
  592. const char *name,
  593. int base,
  594. uint8_t minval,
  595. uint8_t maxval,
  596. uint8_t *out_value)
  597. {
  598. if (str2uchar(strval, out_value) != 0 || (*out_value < minval)
  599. || (*out_value > maxval)) {
  600. lprintf(LOG_ERR, "Invalid value %s for parameter %s",
  601. strval, name);
  602. lprintf(LOG_ERR, "Valid values are %d-%d", minval, maxval);
  603. return -1;
  604. }
  605. return 0;
  606. }
  607. /*
  608. * ipmi_sol_set_param
  609. *
  610. * Set the specified Serial Over LAN value to the specified
  611. * value
  612. *
  613. * return 0 on success,
  614. * -1 on failure
  615. */
  616. static int
  617. ipmi_sol_set_param(struct ipmi_intf * intf,
  618. uint8_t channel,
  619. const char * param,
  620. const char * value,
  621. uint8_t guarded)
  622. {
  623. struct ipmi_rs * rsp;
  624. struct ipmi_rq req;
  625. uint8_t data[4];
  626. int bGuarded = guarded; /* Use set-in-progress indicator? */
  627. memset(&req, 0, sizeof(req));
  628. req.msg.netfn = IPMI_NETFN_TRANSPORT; /* 0x0c */
  629. req.msg.cmd = IPMI_SET_SOL_CONFIG_PARAMETERS; /* 0x21 */
  630. req.msg.data = data;
  631. data[0] = channel;
  632. /*
  633. * set-in-progress
  634. */
  635. if (! strcmp(param, "set-in-progress"))
  636. {
  637. bGuarded = 0; /* We _ARE_ the set-in-progress indicator */
  638. req.msg.data_len = 3;
  639. data[1] = SOL_PARAMETER_SET_IN_PROGRESS;
  640. if (! strcmp(value, "set-complete"))
  641. data[2] = 0x00;
  642. else if (! strcmp(value, "set-in-progress"))
  643. data[2] = 0x01;
  644. else if (! strcmp(value, "commit-write"))
  645. data[2] = 0x02;
  646. else
  647. {
  648. lprintf(LOG_ERR, "Invalid value %s for parameter %s",
  649. value, param);
  650. lprintf(LOG_ERR, "Valid values are set-complete, set-in-progress "
  651. "and commit-write");
  652. return -1;
  653. }
  654. }
  655. /*
  656. * enabled
  657. */
  658. else if (! strcmp(param, "enabled"))
  659. {
  660. req.msg.data_len = 3;
  661. data[1] = SOL_PARAMETER_SOL_ENABLE;
  662. if (! strcmp(value, "true"))
  663. data[2] = 0x01;
  664. else if (! strcmp(value, "false"))
  665. data[2] = 0x00;
  666. else
  667. {
  668. lprintf(LOG_ERR, "Invalid value %s for parameter %s",
  669. value, param);
  670. lprintf(LOG_ERR, "Valid values are true and false");
  671. return -1;
  672. }
  673. }
  674. /*
  675. * force-payload-encryption
  676. */
  677. else if (! strcmp(param, "force-encryption"))
  678. {
  679. struct sol_config_parameters params;
  680. req.msg.data_len = 3;
  681. data[1] = SOL_PARAMETER_SOL_AUTHENTICATION;
  682. if (! strcmp(value, "true"))
  683. data[2] = 0x80;
  684. else if (! strcmp(value, "false"))
  685. data[2] = 0x00;
  686. else
  687. {
  688. lprintf(LOG_ERR, "Invalid value %s for parameter %s",
  689. value, param);
  690. lprintf(LOG_ERR, "Valid values are true and false");
  691. return -1;
  692. }
  693. /* We need other values to complete the request */
  694. if (ipmi_get_sol_info(intf, channel, &params))
  695. {
  696. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  697. param);
  698. return -1;
  699. }
  700. data[2] |= params.force_authentication? 0x40 : 0x00;
  701. data[2] |= params.privilege_level;
  702. }
  703. /*
  704. * force-payload-authentication
  705. */
  706. else if (! strcmp(param, "force-authentication"))
  707. {
  708. struct sol_config_parameters params;
  709. req.msg.data_len = 3;
  710. data[1] = SOL_PARAMETER_SOL_AUTHENTICATION;
  711. if (! strcmp(value, "true"))
  712. data[2] = 0x40;
  713. else if (! strcmp(value, "false"))
  714. data[2] = 0x00;
  715. else
  716. {
  717. lprintf(LOG_ERR, "Invalid value %s for parameter %s",
  718. value, param);
  719. lprintf(LOG_ERR, "Valid values are true and false");
  720. return -1;
  721. }
  722. /* We need other values to complete the request */
  723. if (ipmi_get_sol_info(intf, channel, &params))
  724. {
  725. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  726. param);
  727. return -1;
  728. }
  729. data[2] |= params.force_encryption? 0x80 : 0x00;
  730. data[2] |= params.privilege_level;
  731. }
  732. /*
  733. * privilege-level
  734. */
  735. else if (! strcmp(param, "privilege-level"))
  736. {
  737. struct sol_config_parameters params;
  738. req.msg.data_len = 3;
  739. data[1] = SOL_PARAMETER_SOL_AUTHENTICATION;
  740. if (! strcmp(value, "user"))
  741. data[2] = 0x02;
  742. else if (! strcmp(value, "operator"))
  743. data[2] = 0x03;
  744. else if (! strcmp(value, "admin"))
  745. data[2] = 0x04;
  746. else if (! strcmp(value, "oem"))
  747. data[2] = 0x05;
  748. else
  749. {
  750. lprintf(LOG_ERR, "Invalid value %s for parameter %s",
  751. value, param);
  752. lprintf(LOG_ERR, "Valid values are user, operator, admin, and oem");
  753. return -1;
  754. }
  755. /* We need other values to complete the request */
  756. if (ipmi_get_sol_info(intf, channel, &params))
  757. {
  758. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  759. param);
  760. return -1;
  761. }
  762. data[2] |= params.force_encryption? 0x80 : 0x00;
  763. data[2] |= params.force_authentication? 0x40 : 0x00;
  764. }
  765. /*
  766. * character-accumulate-level
  767. */
  768. else if (! strcmp(param, "character-accumulate-level"))
  769. {
  770. struct sol_config_parameters params;
  771. req.msg.data_len = 4;
  772. data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
  773. /* validate user-supplied input */
  774. if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 1, 255, &data[2]))
  775. return -1;
  776. /* We need other values to complete the request */
  777. if (ipmi_get_sol_info(intf, channel, &params))
  778. {
  779. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  780. param);
  781. return -1;
  782. }
  783. data[3] = params.character_send_threshold;
  784. }
  785. /*
  786. * character-send-threshold
  787. */
  788. else if (! strcmp(param, "character-send-threshold"))
  789. {
  790. struct sol_config_parameters params;
  791. req.msg.data_len = 4;
  792. data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
  793. /* validate user-supplied input */
  794. if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
  795. return -1;
  796. /* We need other values to complete the request */
  797. if (ipmi_get_sol_info(intf, channel, &params))
  798. {
  799. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  800. param);
  801. return -1;
  802. }
  803. data[2] = params.character_accumulate_level;
  804. }
  805. /*
  806. * retry-count
  807. */
  808. else if (! strcmp(param, "retry-count"))
  809. {
  810. struct sol_config_parameters params;
  811. req.msg.data_len = 4;
  812. data[1] = SOL_PARAMETER_SOL_RETRY;
  813. /* validate user input, 7 is max value */
  814. if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 7, &data[2]))
  815. return -1;
  816. /* We need other values to complete the request */
  817. if (ipmi_get_sol_info(intf, channel, &params))
  818. {
  819. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  820. param);
  821. return -1;
  822. }
  823. data[3] = params.retry_interval;
  824. }
  825. /*
  826. * retry-interval
  827. */
  828. else if (! strcmp(param, "retry-interval"))
  829. {
  830. struct sol_config_parameters params;
  831. req.msg.data_len = 4;
  832. data[1] = SOL_PARAMETER_SOL_RETRY;
  833. /* validate user-supplied input */
  834. if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
  835. return -1;
  836. /* We need other values to complete the request */
  837. if (ipmi_get_sol_info(intf, channel, &params))
  838. {
  839. lprintf(LOG_ERR, "Error fetching SOL parameters for %s update",
  840. param);
  841. return -1;
  842. }
  843. data[2] = params.retry_count;
  844. }
  845. /*
  846. * non-volatile-bit-rate
  847. */
  848. else if (! strcmp(param, "non-volatile-bit-rate"))
  849. {
  850. req.msg.data_len = 3;
  851. data[1] = SOL_PARAMETER_SOL_NON_VOLATILE_BIT_RATE;
  852. if (!strcmp(value, "serial"))
  853. {
  854. data[2] = 0x00;
  855. }
  856. else if (!strcmp(value, "9.6"))
  857. {
  858. data[2] = 0x06;
  859. }
  860. else if (!strcmp(value, "19.2"))
  861. {
  862. data[2] = 0x07;
  863. }
  864. else if (!strcmp(value, "38.4"))
  865. {
  866. data[2] = 0x08;
  867. }
  868. else if (!strcmp(value, "57.6"))
  869. {
  870. data[2] = 0x09;
  871. }
  872. else if (!strcmp(value, "115.2"))
  873. {
  874. data[2] = 0x0A;
  875. }
  876. else
  877. {
  878. lprintf(LOG_ERR, "Invalid value \"%s\" for parameter \"%s\"",
  879. value,
  880. param);
  881. lprintf(LOG_ERR, "Valid values are serial, 9.6 19.2, 38.4, 57.6 and 115.2");
  882. return -1;
  883. }
  884. }
  885. /*
  886. * volatile-bit-rate
  887. */
  888. else if (! strcmp(param, "volatile-bit-rate"))
  889. {
  890. req.msg.data_len = 3;
  891. data[1] = SOL_PARAMETER_SOL_VOLATILE_BIT_RATE;
  892. if (!strcmp(value, "serial"))
  893. {
  894. data[2] = 0x00;
  895. }
  896. else if (!strcmp(value, "9.6"))
  897. {
  898. data[2] = 0x06;
  899. }
  900. else if (!strcmp(value, "19.2"))
  901. {
  902. data[2] = 0x07;
  903. }
  904. else if (!strcmp(value, "38.4"))
  905. {
  906. data[2] = 0x08;
  907. }
  908. else if (!strcmp(value, "57.6"))
  909. {
  910. data[2] = 0x09;
  911. }
  912. else if (!strcmp(value, "115.2"))
  913. {
  914. data[2] = 0x0A;
  915. }
  916. else
  917. {
  918. lprintf(LOG_ERR, "Invalid value \"%s\" for parameter \"%s\"",
  919. value,
  920. param);
  921. lprintf(LOG_ERR, "Valid values are serial, 9.6 19.2, 38.4, 57.6 and 115.2");
  922. return -1;
  923. }
  924. }
  925. else
  926. {
  927. lprintf(LOG_ERR, "Error: invalid SOL parameter %s", param);
  928. return -1;
  929. }
  930. /*
  931. * Execute the request
  932. */
  933. if (bGuarded &&
  934. (ipmi_sol_set_param(intf,
  935. channel,
  936. "set-in-progress",
  937. "set-in-progress",
  938. bGuarded)))
  939. {
  940. lprintf(LOG_ERR, "Error: set of parameter \"%s\" failed", param);
  941. return -1;
  942. }
  943. /* The command proper */
  944. rsp = intf->sendrecv(intf, &req);
  945. if (rsp == NULL) {
  946. lprintf(LOG_ERR, "Error setting SOL parameter '%s'", param);
  947. return -1;
  948. }
  949. if (!(!strncmp(param, "set-in-progress", 15) && !strncmp(value, "commit-write", 12)) &&
  950. rsp->ccode > 0) {
  951. switch (rsp->ccode) {
  952. case 0x80:
  953. lprintf(LOG_ERR, "Error setting SOL parameter '%s': "
  954. "Parameter not supported", param);
  955. break;
  956. case 0x81:
  957. lprintf(LOG_ERR, "Error setting SOL parameter '%s': "
  958. "Attempt to set set-in-progress when not in set-complete state",
  959. param);
  960. break;
  961. case 0x82:
  962. lprintf(LOG_ERR, "Error setting SOL parameter '%s': "
  963. "Attempt to write read-only parameter", param);
  964. break;
  965. case 0x83:
  966. lprintf(LOG_ERR, "Error setting SOL parameter '%s': "
  967. "Attempt to read write-only parameter", param);
  968. break;
  969. default:
  970. lprintf(LOG_ERR, "Error setting SOL parameter '%s' to '%s': %s",
  971. param, value, val2str(rsp->ccode, completion_code_vals));
  972. break;
  973. }
  974. if (bGuarded &&
  975. (ipmi_sol_set_param(intf,
  976. channel,
  977. "set-in-progress",
  978. "set-complete",
  979. bGuarded)))
  980. {
  981. lprintf(LOG_ERR, "Error could not set \"set-in-progress\" "
  982. "to \"set-complete\"");
  983. }
  984. return -1;
  985. }
  986. /*
  987. * The commit write could very well fail, but that's ok.
  988. * It may not be implemented.
  989. */
  990. if (bGuarded)
  991. ipmi_sol_set_param(intf,
  992. channel,
  993. "set-in-progress",
  994. "commit-write",
  995. bGuarded);
  996. if (bGuarded &&
  997. ipmi_sol_set_param(intf,
  998. channel,
  999. "set-in-progress",
  1000. "set-complete",
  1001. bGuarded))
  1002. {
  1003. lprintf(LOG_ERR, "Error could not set \"set-in-progress\" "
  1004. "to \"set-complete\"");
  1005. return -1;
  1006. }
  1007. return 0;
  1008. }
  1009. void
  1010. leave_raw_mode(void)
  1011. {
  1012. if (!_in_raw_mode)
  1013. return;
  1014. if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1)
  1015. perror("tcsetattr");
  1016. else
  1017. _in_raw_mode = 0;
  1018. }
  1019. void
  1020. enter_raw_mode(void)
  1021. {
  1022. struct termios tio;
  1023. if (tcgetattr(fileno(stdin), &tio) == -1) {
  1024. perror("tcgetattr");
  1025. return;
  1026. }
  1027. _saved_tio = tio;
  1028. tio.c_iflag |= IGNPAR;
  1029. tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
  1030. tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
  1031. // #ifdef IEXTEN
  1032. tio.c_lflag &= ~IEXTEN;
  1033. // #endif
  1034. tio.c_oflag &= ~OPOST;
  1035. tio.c_cc[VMIN] = 1;
  1036. tio.c_cc[VTIME] = 0;
  1037. if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
  1038. perror("tcsetattr");
  1039. else
  1040. _in_raw_mode = 1;
  1041. }
  1042. static void
  1043. sendBreak(struct ipmi_intf * intf)
  1044. {
  1045. struct ipmi_v2_payload v2_payload;
  1046. memset(&v2_payload, 0, sizeof(v2_payload));
  1047. v2_payload.payload.sol_packet.character_count = 0;
  1048. v2_payload.payload.sol_packet.generate_break = 1;
  1049. intf->send_sol(intf, &v2_payload);
  1050. }
  1051. /*
  1052. * suspendSelf
  1053. *
  1054. * Put ourself in the background
  1055. *
  1056. * param bRestoreTty specifies whether we will put our self back
  1057. * in raw mode when we resume
  1058. */
  1059. static void
  1060. suspendSelf(int bRestoreTty)
  1061. {
  1062. leave_raw_mode();
  1063. kill(getpid(), SIGTSTP);
  1064. if (bRestoreTty)
  1065. enter_raw_mode();
  1066. }
  1067. /*
  1068. * printSolEscapeSequences
  1069. *
  1070. * Send some useful documentation to the user
  1071. */
  1072. static void
  1073. printSolEscapeSequences(struct ipmi_intf * intf)
  1074. {
  1075. printf(
  1076. "%c?\n\
  1077. Supported escape sequences:\n\
  1078. %c. - terminate connection\n\
  1079. %c^Z - suspend ipmitool\n\
  1080. %c^X - suspend ipmitool, but don't restore tty on restart\n\
  1081. %cB - send break\n\
  1082. %c? - this message\n\
  1083. %c%c - send the escape character by typing it twice\n\
  1084. (Note that escapes are only recognized immediately after newline.)\n",
  1085. intf->ssn_params.sol_escape_char,
  1086. intf->ssn_params.sol_escape_char,
  1087. intf->ssn_params.sol_escape_char,
  1088. intf->ssn_params.sol_escape_char,
  1089. intf->ssn_params.sol_escape_char,
  1090. intf->ssn_params.sol_escape_char,
  1091. intf->ssn_params.sol_escape_char,
  1092. intf->ssn_params.sol_escape_char);
  1093. }
  1094. /*
  1095. * output
  1096. *
  1097. * Send the specified data to stdout
  1098. */
  1099. static void
  1100. output(struct ipmi_rs * rsp)
  1101. {
  1102. /* Add checks to make sure it is actually SOL data, in general I see
  1103. * outside code mostly trying to guard against this happening, but
  1104. * some places fail to do so, so I do so here to make sure nothing gets
  1105. * through. If non-sol data comes through here, there is probably
  1106. * a packet that won't get processed somewhere else, but the alternative
  1107. * of outputting corrupt data is worse. Generally I see the get device
  1108. * id response make it here somehow. I assume it is a heartbeat and the
  1109. * other code will retry if it cares about the response and misses it.
  1110. */
  1111. if (rsp &&
  1112. (rsp->session.authtype == IPMI_SESSION_AUTHTYPE_RMCP_PLUS) &&
  1113. (rsp->session.payloadtype == IPMI_PAYLOAD_TYPE_SOL))
  1114. {
  1115. int i;
  1116. for (i = 0; i < rsp->data_len; ++i)
  1117. putc(rsp->data[i], stdout);
  1118. fflush(stdout);
  1119. }
  1120. }
  1121. /*
  1122. * ipmi_sol_deactivate
  1123. */
  1124. static int
  1125. ipmi_sol_deactivate(struct ipmi_intf * intf, int instance)
  1126. {
  1127. struct ipmi_rs * rsp;
  1128. struct ipmi_rq req;
  1129. uint8_t data[6];
  1130. if ((instance <= 0) || (instance > 15)) {
  1131. lprintf(LOG_ERR, "Error: Instance must range from 1 to 15");
  1132. return -1;
  1133. }
  1134. memset(&req, 0, sizeof(req));
  1135. req.msg.netfn = IPMI_NETFN_APP;
  1136. req.msg.cmd = IPMI_DEACTIVATE_PAYLOAD;
  1137. req.msg.data_len = 6;
  1138. req.msg.data = data;
  1139. memset(data, 0, sizeof(data));
  1140. data[0] = IPMI_PAYLOAD_TYPE_SOL; /* payload type */
  1141. data[1] = instance; /* payload instance. */
  1142. /* Lots of important data */
  1143. data[2] = 0;
  1144. data[3] = 0;
  1145. data[4] = 0;
  1146. data[5] = 0;
  1147. rsp = intf->sendrecv(intf, &req);
  1148. if (NULL != rsp) {
  1149. switch (rsp->ccode) {
  1150. case 0x00:
  1151. return 0;
  1152. case 0x80:
  1153. lprintf(LOG_ERR, "Info: SOL payload already de-activated");
  1154. break;
  1155. case 0x81:
  1156. lprintf(LOG_ERR, "Info: SOL payload type disabled");
  1157. break;
  1158. default:
  1159. lprintf(LOG_ERR, "Error de-activating SOL payload: %s",
  1160. val2str(rsp->ccode, completion_code_vals));
  1161. break;
  1162. }
  1163. } else {
  1164. lprintf(LOG_ERR, "Error: No response de-activating SOL payload");
  1165. }
  1166. return -1;
  1167. }
  1168. /*
  1169. * processSolUserInput
  1170. *
  1171. * Act on user input into the SOL session. The only reason this
  1172. * is complicated is that we have to process escape sequences.
  1173. *
  1174. * return 0 on success
  1175. * 1 if we should exit
  1176. * < 0 on error (BMC probably closed the session)
  1177. */
  1178. static int
  1179. processSolUserInput(
  1180. struct ipmi_intf * intf,
  1181. uint8_t * input,
  1182. uint16_t buffer_length)
  1183. {
  1184. static int escape_pending = 0;
  1185. static int last_was_cr = 1;
  1186. struct ipmi_v2_payload v2_payload;
  1187. int length = 0;
  1188. int retval = 0;
  1189. char ch;
  1190. int i;
  1191. memset(&v2_payload, 0, sizeof(v2_payload));
  1192. /*
  1193. * Our first order of business is to check the input for escape
  1194. * sequences to act on.
  1195. */
  1196. for (i = 0; i < buffer_length; ++i)
  1197. {
  1198. ch = input[i];
  1199. if (escape_pending){
  1200. escape_pending = 0;
  1201. /*
  1202. * Process a possible escape sequence.
  1203. */
  1204. switch (ch) {
  1205. case '.':
  1206. printf("%c. [terminated ipmitool]\n",
  1207. intf->ssn_params.sol_escape_char);
  1208. retval = 1;
  1209. break;
  1210. case 'Z' - 64:
  1211. printf("%c^Z [suspend ipmitool]\n",
  1212. intf->ssn_params.sol_escape_char);
  1213. suspendSelf(1); /* Restore tty back to raw */
  1214. continue;
  1215. case 'X' - 64:
  1216. printf("%c^Z [suspend ipmitool]\n",
  1217. intf->ssn_params.sol_escape_char);
  1218. suspendSelf(0); /* Don't restore to raw mode */
  1219. continue;
  1220. case 'B':
  1221. printf("%cB [send break]\n",
  1222. intf->ssn_params.sol_escape_char);
  1223. sendBreak(intf);
  1224. continue;
  1225. case '?':
  1226. printSolEscapeSequences(intf);
  1227. continue;
  1228. default:
  1229. if (ch != intf->ssn_params.sol_escape_char)
  1230. v2_payload.payload.sol_packet.data[length++] =
  1231. intf->ssn_params.sol_escape_char;
  1232. v2_payload.payload.sol_packet.data[length++] = ch;
  1233. }
  1234. }
  1235. else
  1236. {
  1237. if (last_was_cr && (ch == intf->ssn_params.sol_escape_char)) {
  1238. escape_pending = 1;
  1239. continue;
  1240. }
  1241. v2_payload.payload.sol_packet.data[length++] = ch;
  1242. }
  1243. /*
  1244. * Normal character. Record whether it was a newline.
  1245. */
  1246. last_was_cr = (ch == '\r' || ch == '\n');
  1247. }
  1248. /*
  1249. * If there is anything left to process we dispatch it to the BMC,
  1250. * send intf->session->sol_data.max_outbound_payload_size bytes
  1251. * at a time.
  1252. */
  1253. if (length)
  1254. {
  1255. struct ipmi_rs * rsp = NULL;
  1256. int try = 0;
  1257. while (try < intf->ssn_params.retry) {
  1258. v2_payload.payload.sol_packet.character_count = length;
  1259. rsp = intf->send_sol(intf, &v2_payload);
  1260. if (rsp)
  1261. {
  1262. break;
  1263. }
  1264. usleep(5000);
  1265. try++;
  1266. }
  1267. if (! rsp)
  1268. {
  1269. lprintf(LOG_ERR, "Error sending SOL data: FAIL");
  1270. retval = -1;
  1271. }
  1272. /* If the sequence number is set we know we have new data */
  1273. if (retval == 0)
  1274. if ((rsp->session.authtype == IPMI_SESSION_AUTHTYPE_RMCP_PLUS) &&
  1275. (rsp->session.payloadtype == IPMI_PAYLOAD_TYPE_SOL) &&
  1276. (rsp->payload.sol_packet.packet_sequence_number))
  1277. output(rsp);
  1278. }
  1279. return retval;
  1280. }
  1281. static int
  1282. ipmi_sol_keepalive_using_sol(struct ipmi_intf * intf)
  1283. {
  1284. struct ipmi_v2_payload v2_payload;
  1285. struct timeval end;
  1286. if (_disable_keepalive)
  1287. return 0;
  1288. gettimeofday(&end, 0);
  1289. if (end.tv_sec - _start_keepalive.tv_sec > SOL_KEEPALIVE_TIMEOUT) {
  1290. memset(&v2_payload, 0, sizeof(v2_payload));
  1291. v2_payload.payload.sol_packet.character_count = 0;
  1292. if (intf->send_sol(intf, &v2_payload) == NULL)
  1293. return -1;
  1294. /* good return, reset start time */
  1295. gettimeofday(&_start_keepalive, 0);
  1296. }
  1297. return 0;
  1298. }
  1299. static int
  1300. ipmi_sol_keepalive_using_getdeviceid(struct ipmi_intf * intf)
  1301. {
  1302. struct timeval end;
  1303. if (_disable_keepalive)
  1304. return 0;
  1305. gettimeofday(&end, 0);
  1306. if (end.tv_sec - _start_keepalive.tv_sec > SOL_KEEPALIVE_TIMEOUT) {
  1307. if (intf->keepalive(intf) != 0)
  1308. return -1;
  1309. /* good return, reset start time */
  1310. gettimeofday(&_start_keepalive, 0);
  1311. }
  1312. return 0;
  1313. }
  1314. /*
  1315. * ipmi_sol_red_pill
  1316. */
  1317. static int
  1318. ipmi_sol_red_pill(struct ipmi_intf * intf, int instance)
  1319. {
  1320. char * buffer;
  1321. int numRead;
  1322. int bShouldExit = 0;
  1323. int bBmcClosedSession = 0;
  1324. fd_set read_fds;
  1325. struct timeval tv;
  1326. int retval;
  1327. int buffer_size = intf->session->sol_data.max_inbound_payload_size;
  1328. int keepAliveRet = 0;
  1329. int retrySol = 0;
  1330. /* Subtract SOL header from max_inbound_payload_size */
  1331. if (buffer_size > 4)
  1332. buffer_size -= 4;
  1333. buffer = (char*)malloc(buffer_size);
  1334. if (buffer == NULL) {
  1335. lprintf(LOG_ERR, "ipmitool: malloc failure");
  1336. return -1;
  1337. }
  1338. /* Initialize keepalive start time */
  1339. gettimeofday(&_start_keepalive, 0);
  1340. enter_raw_mode();
  1341. while (! bShouldExit)
  1342. {
  1343. FD_ZERO(&read_fds);
  1344. FD_SET(0, &read_fds);
  1345. FD_SET(intf->fd, &read_fds);
  1346. if (!ipmi_oem_active(intf,"i82571spt"))
  1347. {
  1348. /* Send periodic keepalive packet */
  1349. if(_use_sol_for_keepalive == 0)
  1350. {
  1351. keepAliveRet = ipmi_sol_keepalive_using_getdeviceid(intf);
  1352. }
  1353. else
  1354. {
  1355. keepAliveRet = ipmi_sol_keepalive_using_sol(intf);
  1356. }
  1357. if (keepAliveRet != 0)
  1358. {
  1359. /*
  1360. * Retrying the keep Alive before declaring a communication
  1361. * lost state with the IPMC. Helpful when the payload is
  1362. * reset and brings down the connection temporarily. Otherwise,
  1363. * if we send getDevice Id to check the status of IPMC during
  1364. * this down time when the connection is restarting, SOL will
  1365. * exit even though the IPMC is available and the session is open.
  1366. */
  1367. if (retrySol == MAX_SOL_RETRY)
  1368. {
  1369. /* no response to Get Device ID keepalive message */
  1370. bShouldExit = 1;
  1371. continue;
  1372. }
  1373. else
  1374. {
  1375. retrySol++;
  1376. }
  1377. }
  1378. else
  1379. {
  1380. /* if the keep Alive is successful reset retries to zero */
  1381. retrySol = 0;
  1382. }
  1383. } /* !oem="i82571spt" */
  1384. /* Wait up to half a second */
  1385. tv.tv_sec = 0;
  1386. tv.tv_usec = 500000;
  1387. retval = select(intf->fd + 1, &read_fds, NULL, NULL, &tv);
  1388. if (retval)
  1389. {
  1390. if (retval == -1)
  1391. {
  1392. /* ERROR */
  1393. perror("select");
  1394. return -1;
  1395. }
  1396. /*
  1397. * Process input from the user
  1398. */
  1399. if (FD_ISSET(0, &read_fds))
  1400. {
  1401. memset(buffer, 0, buffer_size);
  1402. numRead = read(fileno(stdin),
  1403. buffer,
  1404. buffer_size);
  1405. if (numRead > 0)
  1406. {
  1407. int rc = processSolUserInput(intf, (uint8_t *)buffer, numRead);
  1408. if (rc)
  1409. {
  1410. if (rc < 0)
  1411. bShouldExit = bBmcClosedSession = 1;
  1412. else
  1413. bShouldExit = 1;
  1414. }
  1415. }
  1416. else
  1417. {
  1418. bShouldExit = 1;
  1419. }
  1420. }
  1421. /*
  1422. * Process input from the BMC
  1423. */
  1424. else if (FD_ISSET(intf->fd, &read_fds))
  1425. {
  1426. struct ipmi_rs * rs =intf->recv_sol(intf);
  1427. if (rs) {
  1428. output(rs);
  1429. } else {
  1430. bShouldExit = bBmcClosedSession = 1;
  1431. }
  1432. }
  1433. /*
  1434. * ERROR in select
  1435. */
  1436. else
  1437. {
  1438. lprintf(LOG_ERR, "Error: Select returned with nothing to read");
  1439. bShouldExit = 1;
  1440. }
  1441. }
  1442. }
  1443. leave_raw_mode();
  1444. if (keepAliveRet != 0)
  1445. {
  1446. lprintf(LOG_ERR, "Error: No response to keepalive - Terminating session");
  1447. /* attempt to clean up anyway */
  1448. ipmi_sol_deactivate(intf, instance);
  1449. exit(1);
  1450. }
  1451. if (bBmcClosedSession)
  1452. {
  1453. lprintf(LOG_ERR, "SOL session closed by BMC");
  1454. exit(1);
  1455. }
  1456. else
  1457. ipmi_sol_deactivate(intf, instance);
  1458. return 0;
  1459. }
  1460. /*
  1461. * ipmi_sol_activate
  1462. */
  1463. static int
  1464. ipmi_sol_activate(struct ipmi_intf * intf, int looptest, int interval,
  1465. int instance)
  1466. {
  1467. struct ipmi_rs * rsp;
  1468. struct ipmi_rq req;
  1469. struct activate_payload_rsp ap_rsp;
  1470. uint8_t data[6];
  1471. uint8_t bSolEncryption = 1;
  1472. uint8_t bSolAuthentication = 1;
  1473. /*
  1474. * This command is only available over RMCP+ (the lanplus
  1475. * interface).
  1476. */
  1477. if (strncmp(intf->name, "lanplus", 7) != 0)
  1478. {
  1479. lprintf(LOG_ERR, "Error: This command is only available over the "
  1480. "lanplus interface");
  1481. return -1;
  1482. }
  1483. if ((instance <= 0) || (instance > 15)) {
  1484. lprintf(LOG_ERR, "Error: Instance must range from 1 to 15");
  1485. return -1;
  1486. }
  1487. /*
  1488. * Setup a callback so that the lanplus processing knows what
  1489. * to do with packets that come unexpectedly (while waiting for
  1490. * an ACK, perhaps.
  1491. */
  1492. intf->session->sol_data.sol_input_handler = output;
  1493. memset(&req, 0, sizeof(req));
  1494. req.msg.netfn = IPMI_NETFN_APP;
  1495. req.msg.cmd = IPMI_ACTIVATE_PAYLOAD;
  1496. req.msg.data_len = 6;
  1497. req.msg.data = data;
  1498. data[0] = IPMI_PAYLOAD_TYPE_SOL; /* payload type */
  1499. data[1] = instance; /* payload instance */
  1500. /* Lots of important data. Most is default */
  1501. data[2] = bSolEncryption? 0x80 : 0;
  1502. data[2] |= bSolAuthentication? 0x40 : 0;
  1503. data[2] |= IPMI_SOL_SERIAL_ALERT_MASK_DEFERRED;
  1504. if (ipmi_oem_active(intf, "intelplus")) {
  1505. data[2] |= IPMI_SOL_BMC_ASSERTS_CTS_MASK_TRUE;
  1506. } else if (ipmi_oem_active(intf, "i82571spt")) {
  1507. /*
  1508. * A quote from Intel: "Engineering believes the problem
  1509. * lies within the Auxiliary data being sent with the
  1510. * 'Activate Payload' command from IPMITool. IPMITool
  1511. * sends a C6h which sets some bits having to do with
  1512. * encryption and some behavior dealing with CTS DCD/DSR.
  1513. * I recommend that the customer modify this request
  1514. * to send 08h instead. This is what our internal utility
  1515. * sends and it works without issue. I will work with
  1516. * engineering to ensure the settings that IPMITool uses
  1517. * (C6h) are supported in the future.
  1518. */
  1519. data[2] = 0x08;
  1520. } else {
  1521. data[2] |= IPMI_SOL_BMC_ASSERTS_CTS_MASK_FALSE;
  1522. }
  1523. data[3] = 0x00; /* reserved */
  1524. data[4] = 0x00; /* reserved */
  1525. data[5] = 0x00; /* reserved */
  1526. rsp = intf->sendrecv(intf, &req);
  1527. if (NULL != rsp) {
  1528. switch (rsp->ccode) {
  1529. case 0x00:
  1530. if (rsp->data_len == 12) {
  1531. break;
  1532. } else {
  1533. lprintf(LOG_ERR, "Error: Unexpected data length (%d) received "
  1534. "in payload activation response",
  1535. rsp->data_len);
  1536. return -1;
  1537. }
  1538. break;
  1539. case 0x80:
  1540. lprintf(LOG_ERR, "Info: SOL payload already active on another session");
  1541. return -1;
  1542. case 0x81:
  1543. lprintf(LOG_ERR, "Info: SOL payload disabled");
  1544. return -1;
  1545. case 0x82:
  1546. lprintf(LOG_ERR, "Info: SOL payload activation limit reached");
  1547. return -1;
  1548. case 0x83:
  1549. lprintf(LOG_ERR, "Info: cannot activate SOL payload with encryption");
  1550. return -1;
  1551. case 0x84:
  1552. lprintf(LOG_ERR, "Info: cannot activate SOL payload without encryption");
  1553. return -1;
  1554. default:
  1555. lprintf(LOG_ERR, "Error activating SOL payload: %s",
  1556. val2str(rsp->ccode, completion_code_vals));
  1557. return -1;
  1558. }
  1559. } else {
  1560. lprintf(LOG_ERR, "Error: No response activating SOL payload");
  1561. return -1;
  1562. }
  1563. memcpy(&ap_rsp, rsp->data, sizeof(struct activate_payload_rsp));
  1564. intf->session->sol_data.max_inbound_payload_size =
  1565. (ap_rsp.inbound_payload_size[1] << 8) |
  1566. ap_rsp.inbound_payload_size[0];
  1567. intf->session->sol_data.max_outbound_payload_size =
  1568. (ap_rsp.outbound_payload_size[1] << 8) |
  1569. ap_rsp.outbound_payload_size[0];
  1570. intf->session->sol_data.port =
  1571. (ap_rsp.payload_udp_port[1] << 8) |
  1572. ap_rsp.payload_udp_port[0];
  1573. intf->session->timeout = 1;
  1574. /* NOTE: the spec does allow for SOL traffic to be sent on
  1575. * a different port. we do not yet support that feature. */
  1576. if (intf->session->sol_data.port != intf->ssn_params.port)
  1577. {
  1578. /* try byteswapping port in case BMC sent it incorrectly */
  1579. uint16_t portswap = BSWAP_16(intf->session->sol_data.port);
  1580. if (portswap == intf->ssn_params.port) {
  1581. intf->session->sol_data.port = portswap;
  1582. }
  1583. else {
  1584. lprintf(LOG_ERR, "Error: BMC requests SOL session on different port");
  1585. return -1;
  1586. }
  1587. }
  1588. printf("[SOL Session operational. Use %c? for help]\n",
  1589. intf->ssn_params.sol_escape_char);
  1590. if(looptest == 1)
  1591. {
  1592. ipmi_sol_deactivate(intf, instance);
  1593. usleep(interval*1000);
  1594. return 0;
  1595. }
  1596. /*
  1597. * At this point we are good to go with our SOL session. We
  1598. * need to listen to
  1599. * 1) STDIN for user input
  1600. * 2) The FD for incoming SOL packets
  1601. */
  1602. if (ipmi_sol_red_pill(intf, instance))
  1603. {
  1604. lprintf(LOG_ERR, "Error in SOL session");
  1605. return -1;
  1606. }
  1607. return 0;
  1608. }
  1609. /*
  1610. * print_sol_usage
  1611. */
  1612. static void
  1613. print_sol_usage(void)
  1614. {
  1615. lprintf(LOG_NOTICE, "SOL Commands: info [<channel number>]");
  1616. lprintf(LOG_NOTICE, " set <parameter> <value> [channel]");
  1617. lprintf(LOG_NOTICE, " payload <enable|disable|status> [channel] [userid]");
  1618. lprintf(LOG_NOTICE, " activate [<usesolkeepalive|nokeepalive>] [instance=<number>]");
  1619. lprintf(LOG_NOTICE, " deactivate [instance=<number>]");
  1620. lprintf(LOG_NOTICE, " looptest [<loop times> [<loop interval(in ms)> [<instance>]]]");
  1621. }
  1622. /*
  1623. * print_sol_set_usage
  1624. */
  1625. static void
  1626. print_sol_set_usage(void)
  1627. {
  1628. lprintf(LOG_NOTICE, "\nSOL set parameters and values: \n");
  1629. lprintf(LOG_NOTICE, " set-in-progress set-complete | "
  1630. "set-in-progress | commit-write");
  1631. lprintf(LOG_NOTICE, " enabled true | false");
  1632. lprintf(LOG_NOTICE, " force-encryption true | false");
  1633. lprintf(LOG_NOTICE, " force-authentication true | false");
  1634. lprintf(LOG_NOTICE, " privilege-level user | operator | admin | oem");
  1635. lprintf(LOG_NOTICE, " character-accumulate-level <in 5 ms increments>");
  1636. lprintf(LOG_NOTICE, " character-send-threshold N");
  1637. lprintf(LOG_NOTICE, " retry-count N");
  1638. lprintf(LOG_NOTICE, " retry-interval <in 10 ms increments>");
  1639. lprintf(LOG_NOTICE, " non-volatile-bit-rate "
  1640. "serial | 9.6 | 19.2 | 38.4 | 57.6 | 115.2");
  1641. lprintf(LOG_NOTICE, " volatile-bit-rate "
  1642. "serial | 9.6 | 19.2 | 38.4 | 57.6 | 115.2");
  1643. lprintf(LOG_NOTICE, "");
  1644. }
  1645. /* ipmi_sol_main */
  1646. int
  1647. ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
  1648. {
  1649. int retval = 0;
  1650. if (!argc || !strncmp(argv[0], "help", 4)) {
  1651. /* Help */
  1652. print_sol_usage();
  1653. } else if (!strncmp(argv[0], "info", 4)) {
  1654. /* Info */
  1655. uint8_t channel;
  1656. if (argc == 1) {
  1657. /* Ask about the current channel */
  1658. channel = 0x0E;
  1659. } else if (argc == 2) {
  1660. if (is_ipmi_channel_num(argv[1], &channel) != 0) {
  1661. return (-1);
  1662. }
  1663. } else {
  1664. print_sol_usage();
  1665. return -1;
  1666. }
  1667. retval = ipmi_print_sol_info(intf, channel);
  1668. } else if (!strncmp(argv[0], "payload", 7)) {
  1669. /* Payload enable or disable */
  1670. uint8_t channel = 0xe;
  1671. uint8_t userid = 1;
  1672. int enable = -1;
  1673. if (argc == 1 || argc > 4) {
  1674. print_sol_usage();
  1675. return -1;
  1676. }
  1677. if (argc >= 3) {
  1678. if (is_ipmi_channel_num(argv[2], &channel) != 0) {
  1679. return (-1);
  1680. }
  1681. }
  1682. if (argc == 4) {
  1683. if (is_ipmi_user_id(argv[3], &userid) != 0) {
  1684. return (-1);
  1685. }
  1686. }
  1687. if (!strncmp(argv[1], "enable", 6)) {
  1688. enable = 1;
  1689. } else if (!strncmp(argv[1], "disable", 7)) {
  1690. enable = 0;
  1691. } else if (!strncmp(argv[1], "status", 6)) {
  1692. return ipmi_sol_payload_access_status(intf, channel, userid);
  1693. } else {
  1694. print_sol_usage();
  1695. return -1;
  1696. }
  1697. retval = ipmi_sol_payload_access(intf, channel, userid, enable);
  1698. } else if (!strncmp(argv[0], "set", 3)) {
  1699. /* Set a parameter value */
  1700. uint8_t channel = 0xe;
  1701. uint8_t guard = 1;
  1702. if (argc == 3) {
  1703. channel = 0xe;
  1704. } else if (argc == 4) {
  1705. if (!strncmp(argv[3], "noguard", 7)) {
  1706. guard = 0;
  1707. } else {
  1708. if (is_ipmi_channel_num(argv[3], &channel) != 0) {
  1709. return (-1);
  1710. }
  1711. }
  1712. } else if (argc == 5) {
  1713. if (is_ipmi_channel_num(argv[3], &channel) != 0) {
  1714. return (-1);
  1715. }
  1716. if (!strncmp(argv[4], "noguard", 7)) {
  1717. guard = 0;
  1718. }
  1719. } else {
  1720. print_sol_set_usage();
  1721. return -1;
  1722. }
  1723. retval = ipmi_sol_set_param(intf, channel, argv[1], argv[2], guard);
  1724. } else if (!strncmp(argv[0], "activate", 8)) {
  1725. /* Activate */
  1726. int i;
  1727. uint8_t instance = 1;
  1728. for (i = 1; i < argc; i++) {
  1729. if (!strncmp(argv[i], "usesolkeepalive", 15)) {
  1730. _use_sol_for_keepalive = 1;
  1731. } else if (!strncmp(argv[i], "nokeepalive", 11)) {
  1732. _disable_keepalive = 1;
  1733. } else if (!strncmp(argv[i], "instance=", 9)) {
  1734. if (str2uchar(argv[i] + 9, &instance) != 0) {
  1735. lprintf(LOG_ERR, "Given instance '%s' is invalid.", argv[i] + 9);
  1736. print_sol_usage();
  1737. return -1;
  1738. }
  1739. } else {
  1740. print_sol_usage();
  1741. return -1;
  1742. }
  1743. }
  1744. retval = ipmi_sol_activate(intf, 0, 0, instance);
  1745. } else if (!strncmp(argv[0], "deactivate", 10)) {
  1746. /* Dectivate */
  1747. int i;
  1748. uint8_t instance = 1;
  1749. for (i = 1; i < argc; i++) {
  1750. if (!strncmp(argv[i], "instance=", 9)) {
  1751. if (str2uchar(argv[i] + 9, &instance) != 0) {
  1752. lprintf(LOG_ERR,
  1753. "Given instance '%s' is invalid.",
  1754. argv[i] + 9);
  1755. print_sol_usage();
  1756. return -1;
  1757. }
  1758. } else {
  1759. print_sol_usage();
  1760. return -1;
  1761. }
  1762. }
  1763. retval = ipmi_sol_deactivate(intf, instance);
  1764. } else if (!strncmp(argv[0], "looptest", 8)) {
  1765. /* SOL loop test: Activate and then Dectivate */
  1766. int cnt = 200;
  1767. int interval = 100; /* Unit is: ms */
  1768. uint8_t instance = 1;
  1769. if (argc > 4) {
  1770. print_sol_usage();
  1771. return -1;
  1772. }
  1773. if (argc != 1) {
  1774. /* at least 2 */
  1775. if (str2int(argv[1], &cnt) != 0) {
  1776. lprintf(LOG_ERR, "Given cnt '%s' is invalid.",
  1777. argv[1]);
  1778. return (-1);
  1779. }
  1780. if (cnt <= 0) {
  1781. cnt = 200;
  1782. }
  1783. }
  1784. if (argc >= 3) {
  1785. if (str2int(argv[2], &interval) != 0) {
  1786. lprintf(LOG_ERR, "Given interval '%s' is invalid.",
  1787. argv[2]);
  1788. return (-1);
  1789. }
  1790. if (interval < 0) {
  1791. interval = 0;
  1792. }
  1793. }
  1794. if (argc >= 4) {
  1795. if (str2uchar(argv[3], &instance) != 0) {
  1796. lprintf(LOG_ERR, "Given instance '%s' is invalid.",
  1797. argv[3]);
  1798. print_sol_usage();
  1799. return -1;
  1800. }
  1801. }
  1802. while (cnt > 0) {
  1803. printf("remain loop test counter: %d\n", cnt);
  1804. retval = ipmi_sol_activate(intf, 1, interval, instance);
  1805. if (retval) {
  1806. printf("SOL looptest failed: %d\n",
  1807. retval);
  1808. break;
  1809. }
  1810. cnt -= 1;
  1811. }
  1812. } else {
  1813. print_sol_usage();
  1814. retval = -1;
  1815. }
  1816. return retval;
  1817. }