static int _api_ipmi_cmd_post (ipmi_ctx_t ctx, fiid_obj_t obj_cmd_rs) { int ret; assert (ctx && ctx->magic == IPMI_CTX_MAGIC && fiid_obj_valid (obj_cmd_rs)); if (ctx->flags & IPMI_FLAGS_NO_LEGAL_CHECK) { uint64_t val; /* Do not check completion code if data not available * (i.e. FIID_ERR_DATA_NOT_AVAILABLE completion code). * * Fallthrough to normal error if it's an alternate fiid error * (invalid packet, field not found, etc.) */ if (FIID_OBJ_GET (obj_cmd_rs, "comp_code", &val) < 0) { if (fiid_obj_errnum (obj_cmd_rs) == FIID_ERR_DATA_NOT_AVAILABLE) goto skip_comp_code_check; } } if ((ret = ipmi_check_completion_code_success (obj_cmd_rs)) < 0) { API_ERRNO_TO_API_ERRNUM (ctx, errno); return (-1); } if (!ret) { API_BAD_RESPONSE_TO_API_ERRNUM (ctx, obj_cmd_rs); return (-1); } skip_comp_code_check: if (!(ctx->flags & IPMI_FLAGS_NO_VALID_CHECK) && !(ctx->flags & IPMI_FLAGS_NO_LEGAL_CHECK)) { if ((ret = fiid_obj_packet_valid (obj_cmd_rs)) < 0) { API_FIID_OBJECT_ERROR_TO_API_ERRNUM (ctx, obj_cmd_rs); return (-1); } if (!ret) { API_SET_ERRNUM (ctx, IPMI_ERR_IPMI_ERROR); return (-1); } } return (0); }
int parsepacket (const char *destination, const void *buf, unsigned int buflen, const char *from, unsigned int sequence_number, int verbose, int version, int debug) { fiid_obj_t obj_rmcp_hdr = NULL; fiid_obj_t obj_lan_session_hdr = NULL; fiid_obj_t obj_lan_msg_hdr = NULL; fiid_obj_t obj_cmd = NULL; fiid_obj_t obj_lan_msg_trlr = NULL; uint8_t req_seq, none, md2, md5, straight_password_key, oem, anonymous_login, null_username, non_null_username, user_level_authentication, per_message_authentication, k_g, ipmi_v20_extended_capabilities_available, ipmi_v15, ipmi_v20; uint64_t val; int ret, rv = -1; assert (destination); assert (buf); assert (from); assert (version == IPMI_PING_VERSION_1_5 || version == IPMI_PING_VERSION_2_0); if (!buflen) return (0); if (!(obj_rmcp_hdr = fiid_obj_create (tmpl_rmcp_hdr))) ipmi_ping_err_exit ("fiid_obj_create: %s", strerror (errno)); if (!(obj_lan_session_hdr = fiid_obj_create (tmpl_lan_session_hdr))) ipmi_ping_err_exit ("fiid_obj_create: %s", strerror (errno)); if (!(obj_lan_msg_hdr = fiid_obj_create (tmpl_lan_msg_hdr_rs))) ipmi_ping_err_exit ("fiid_obj_create: %s", strerror (errno)); if (!(obj_cmd = fiid_obj_create (tmpl_cmd_get_channel_authentication_capabilities_rs))) ipmi_ping_err_exit ("fiid_obj_create: %s", strerror (errno)); if (!(obj_lan_msg_trlr = fiid_obj_create (tmpl_lan_msg_trlr))) ipmi_ping_err_exit ("fiid_obj_create: %s", strerror (errno)); if (debug) { char hdrbuf[DEBUG_UTIL_HDR_BUFLEN]; debug_hdr_cmd ((version == IPMI_PING_VERSION_1_5) ? DEBUG_UTIL_TYPE_IPMI_1_5 : DEBUG_UTIL_TYPE_IPMI_2_0, DEBUG_UTIL_DIRECTION_RESPONSE, IPMI_NET_FN_APP_RQ, IPMI_CMD_GET_CHANNEL_AUTHENTICATION_CAPABILITIES, 0, hdrbuf, DEBUG_UTIL_HDR_BUFLEN); if (ipmi_dump_lan_packet (STDERR_FILENO, destination, hdrbuf, NULL, buf, buflen, tmpl_lan_msg_hdr_rs, tmpl_cmd_get_channel_authentication_capabilities_rs) < 0) ipmi_ping_err_exit ("ipmi_dump_lan_packet: %s", strerror (errno)); } if ((ret = ipmi_lan_check_packet_checksum (buf, buflen)) < 0) ipmi_ping_err_exit ("ipmi_lan_check_checksum: %s", strerror (errno)); if (!ret) { if (debug) fprintf (stderr, "%s(%d): checksum failed\n", __FUNCTION__, __LINE__); rv = 0; goto cleanup; } if ((ret = unassemble_ipmi_lan_pkt (buf, buflen, obj_rmcp_hdr, obj_lan_session_hdr, obj_lan_msg_hdr, obj_cmd, obj_lan_msg_trlr, IPMI_INTERFACE_FLAGS_DEFAULT)) < 0) ipmi_ping_err_exit ("unassemble_ipmi_lan_pkt: %s", strerror (errno)); if (!ret) { if (debug) fprintf (stderr, "%s(%d): Could not unassemble packet\n", __FUNCTION__, __LINE__); rv = 0; goto cleanup; } if ((ret = ipmi_lan_check_net_fn (obj_lan_msg_hdr, IPMI_NET_FN_APP_RS)) < 0) ipmi_ping_err_exit ("ipmi_lan_check_net_fn: %s", strerror (errno)); if (!ret) { if (debug) fprintf (stderr, "%s(%d): net_fn failed\n", __FUNCTION__, __LINE__); rv = 0; goto cleanup; } if ((ret = ipmi_check_cmd (obj_cmd, IPMI_CMD_GET_CHANNEL_AUTHENTICATION_CAPABILITIES)) < 0) ipmi_ping_err_exit ("ipmi_check_cmd: %s", strerror (errno)); if (!ret) { if (debug) fprintf (stderr, "%s(%d): cmd failed\n", __FUNCTION__, __LINE__); rv = 0; goto cleanup; } if ((ret = ipmi_check_completion_code_success (obj_cmd)) < 0) ipmi_ping_err_exit ("ipmi_check_comp_code: %s", strerror (errno)); if (!ret) { if (debug) fprintf (stderr, "%s(%d): comp_code failed\n", __FUNCTION__, __LINE__); rv = 0; goto cleanup; } if (FIID_OBJ_GET (obj_lan_msg_hdr, "rq_seq", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'rq_seq': %s", fiid_obj_errormsg (obj_lan_msg_hdr)); req_seq = val; if (req_seq != sequence_number % (IPMI_RQ_SEQ_MAX + 1)) { if (debug) fprintf (stderr, "%s(%d): req_seq failed\n", __FUNCTION__, __LINE__); rv = 0; goto cleanup; } printf ("response received from %s: rq_seq=%u", from, req_seq); if (verbose) { if (FIID_OBJ_GET (obj_cmd, "authentication_type.none", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_type.none': %s", fiid_obj_errormsg (obj_cmd)); none = val; if (FIID_OBJ_GET (obj_cmd, "authentication_type.md2", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_type.md2': %s", fiid_obj_errormsg (obj_cmd)); md2 = val; if (FIID_OBJ_GET (obj_cmd, "authentication_type.md5", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_type.md5': %s", fiid_obj_errormsg (obj_cmd)); md5 = val; if (FIID_OBJ_GET (obj_cmd, "authentication_type.straight_password_key", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_type.straight_password_key': %s", fiid_obj_errormsg (obj_cmd)); straight_password_key = val; if (FIID_OBJ_GET (obj_cmd, "authentication_type.oem_prop", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_type.oem_prop': %s", fiid_obj_errormsg (obj_cmd)); oem = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.anonymous_login", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.anonymous_login': %s", fiid_obj_errormsg (obj_cmd)); anonymous_login = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.null_username", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.null_username': %s", fiid_obj_errormsg (obj_cmd)); null_username = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.non_null_username", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.non_null_username': %s", fiid_obj_errormsg (obj_cmd)); non_null_username = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.user_level_authentication", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.user_level_authentication': %s", fiid_obj_errormsg (obj_cmd)); user_level_authentication = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.per_message_authentication", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.per_message_authentication': %s", fiid_obj_errormsg (obj_cmd)); per_message_authentication = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.per_message_authentication", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.per_message_authentication': %s", fiid_obj_errormsg (obj_cmd)); per_message_authentication = val; printf (", auth: none=%s md2=%s md5=%s password=%s oem=%s anon=%s null=%s non-null=%s user=%s permsg=%s ", _setstr (none), _setstr (md2), _setstr (md5), _setstr (straight_password_key),_setstr (oem), _setstr (anonymous_login), _setstr (null_username), _setstr (non_null_username), _setstr (user_level_authentication), _setstr (per_message_authentication)); if (version == IPMI_PING_VERSION_2_0) { if (FIID_OBJ_GET (obj_cmd, "authentication_type.ipmi_v2.0_extended_capabilities_available", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_type.ipmi_v2.0_extended_capabilities_available': %s", fiid_obj_errormsg (obj_cmd)); ipmi_v20_extended_capabilities_available = val; if (FIID_OBJ_GET (obj_cmd, "authentication_status.k_g", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'authentication_status.k_g': %s", fiid_obj_errormsg (obj_cmd)); k_g = val; printf ("k_g=%s ipmi_v2.0_extended_capabilities_available=%s ", _setstr (k_g), _setstr (ipmi_v20_extended_capabilities_available)); if (ipmi_v20_extended_capabilities_available) { if (FIID_OBJ_GET (obj_cmd, "channel_supports_ipmi_v1.5_connections", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'channel_supports_ipmi_v1.5_connections': %s", fiid_obj_errormsg (obj_cmd)); ipmi_v15 = val; if (FIID_OBJ_GET (obj_cmd, "channel_supports_ipmi_v2.0_connections", &val) < 0) ipmi_ping_err_exit ("fiid_obj_get: 'channel_supports_ipmi_v2.0_connections': %s", fiid_obj_errormsg (obj_cmd)); ipmi_v20 = val; printf ("ipmi_v1.5=%s ipmi_v2.0=%s ", _setstr (ipmi_v15), _setstr (ipmi_v20)); } } } printf ("\n"); rv = 1; cleanup: fiid_obj_destroy (obj_rmcp_hdr); fiid_obj_destroy (obj_lan_session_hdr); fiid_obj_destroy (obj_lan_msg_hdr); fiid_obj_destroy (obj_cmd); fiid_obj_destroy (obj_lan_msg_trlr); return (rv); }