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 
33 #ifndef IPMI_FIREWALL_H
34 #define IPMI_FIREWALL_H
35 
36 #include <ipmitool/ipmi.h>
37 
38 int ipmi_firewall_main(struct ipmi_intf *, int, char **);
39 
40 #define BMC_GET_NETFN_SUPPORT				0x09
41 #define BMC_GET_COMMAND_SUPPORT				0x0A
42 #define BMC_GET_COMMAND_SUBFUNCTION_SUPPORT		0x0B
43 #define BMC_GET_CONFIGURABLE_COMMANDS			0x0C
44 #define BMC_GET_CONFIGURABLE_COMMAND_SUBFUNCTIONS 	0x0D
45 #define BMC_SET_COMMAND_ENABLES				0x60
46 #define BMC_GET_COMMAND_ENABLES				0x61
47 #define BMC_SET_COMMAND_SUBFUNCTION_ENABLES		0x62
48 #define BMC_GET_COMMAND_SUBFUNCTION_ENABLES		0x63
49 #define BMC_OEM_NETFN_IANA_SUPPORT			0x64
50 
51 #define SET_COMMAND_ENABLE_BYTE (BMC_SET_COMMAND_ENABLES / 8)
52 #define SET_COMMAND_ENABLE_BIT (BMC_SET_COMMAND_ENABLES % 8)
53 
54 #define MAX_LUN 4
55 #define MAX_NETFN 64
56 #define MAX_NETFN_PAIR (MAX_NETFN/2)
57 #define MAX_COMMAND 256
58 #define MAX_SUBFN 32
59 #define MAX_COMMAND_BYTES (MAX_COMMAND>>3)
60 #define MAX_SUBFN_BYTES (MAX_SUBFN>>3)
61 
62 // support is a bitfield with the following bits set...
63 #define BIT_AVAILABLE 0x01
64 #define BIT_CONFIGURABLE 0x02
65 #define BIT_ENABLED 0x04
66 
67 extern int verbose;
68 
69 struct command_support {
70 	unsigned char support;
71 	unsigned char version[3];
72 	unsigned char subfn_support[MAX_SUBFN_BYTES];
73 	unsigned char subfn_config[MAX_SUBFN_BYTES];
74 	unsigned char subfn_enable[MAX_SUBFN_BYTES];
75 };
76 struct lun_netfn_support {
77 	unsigned char support;
78 	struct command_support command[MAX_COMMAND];
79 	unsigned char command_mask[MAX_COMMAND_BYTES];
80 	unsigned char config_mask[MAX_COMMAND_BYTES];
81 	unsigned char enable_mask[MAX_COMMAND_BYTES];
82 };
83 struct lun_support {
84 	unsigned char support;
85 	struct lun_netfn_support netfn[MAX_NETFN_PAIR];
86 };
87 struct bmc_fn_support {
88 	struct lun_support lun[MAX_LUN];
89 };
90 struct ipmi_function_params {
91 	int channel;
92 	int lun;
93 	int netfn;
94 	int command;
95 	int subfn;
96 	unsigned char force;
97 };
98 
bit_test(const unsigned char * bf,int n)99 static inline int bit_test(const unsigned char * bf, int n) {
100 	return !!(bf[n>>3]&(1<<(n%8)));
101 }
bit_set(unsigned char * bf,int n,int v)102 static inline void bit_set(unsigned char * bf, int n, int v) {
103 	bf[n>>3] = (bf[n>>3] & ~(1<<(n%8))) | ((v?1:0)<<(n%8));
104 }
105 
106 #endif				/*IPMI_FIREWALL_H */
107