1 /* 2 * Copyright (C) 2003-2015 FreeIPMI Core Team 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 19 #ifndef IPMI_LAN_INTERFACE_H 20 #define IPMI_LAN_INTERFACE_H 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #include <stdint.h> 27 #include <freeipmi/fiid/fiid.h> 28 29 #include <sys/types.h> 30 #include <sys/socket.h> 31 32 #define IPMI_LAN_REQUESTER_SEQUENCE_NUMBER_MAX 0x3F /* 111111b */ 33 34 /* 35 * fill* functions return 0 on success, -1 on error. 36 * 37 * object must be for the fill function's respective fiid 38 * template. 39 * 40 * assemble/unassemble functions must be passed fiid objects of the 41 * respective expected header/trailer templates. 42 * 43 * see freeipmi/templates/ for template definitions 44 */ 45 46 extern fiid_template_t tmpl_lan_session_hdr; 47 extern fiid_template_t tmpl_lan_msg_hdr_rq; 48 extern fiid_template_t tmpl_lan_msg_hdr_rs; 49 extern fiid_template_t tmpl_lan_msg_trlr; 50 51 int fill_lan_session_hdr (uint8_t authentication_type, 52 uint32_t session_sequence_number, 53 uint32_t session_id, 54 fiid_obj_t obj_lan_session_hdr); 55 56 int fill_lan_msg_hdr (uint8_t rs_addr, 57 uint8_t net_fn, 58 uint8_t rs_lun, 59 uint8_t rq_seq, 60 fiid_obj_t obj_lan_msg_hdr); 61 62 /* returns length written to pkt on success, -1 on error */ 63 int assemble_ipmi_lan_pkt (fiid_obj_t obj_rmcp_hdr, 64 fiid_obj_t obj_lan_session_hdr, 65 fiid_obj_t obj_lan_msg_hdr, 66 fiid_obj_t obj_cmd, 67 const void *authentication_code_data, 68 unsigned int authentication_code_data_len, 69 void *pkt, 70 unsigned int pkt_len, 71 unsigned int flags); 72 73 /* returns 1 if fully unparsed, 0 if not, -1 on error */ 74 int unassemble_ipmi_lan_pkt (const void *pkt, 75 unsigned int pkt_len, 76 fiid_obj_t obj_rmcp_hdr, 77 fiid_obj_t obj_lan_session_hdr, 78 fiid_obj_t obj_lan_msg_hdr, 79 fiid_obj_t obj_cmd, 80 fiid_obj_t obj_lan_msg_trlr, 81 unsigned int flags); 82 83 /* returns length sent on success, -1 on error */ 84 /* A few extra error checks, but nearly identical to system sendto() */ 85 ssize_t ipmi_lan_sendto (int s, 86 const void *buf, 87 size_t len, 88 int flags, 89 const struct sockaddr *to, 90 socklen_t tolen); 91 92 /* returns length received on success, 0 on orderly shutdown, -1 on error */ 93 /* A few extra error checks, but nearly identical to system recvfrom() */ 94 ssize_t ipmi_lan_recvfrom (int s, 95 void *buf, 96 size_t len, 97 int flags, 98 struct sockaddr *from, 99 socklen_t *fromlen); 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* IPMI_LAN_INTERFACE_H */ 106