~ubuntu-branches/ubuntu/maverick/ipmitool/maverick

« back to all changes in this revision

Viewing changes to src/plugins/ipmi_intf.c

  • Committer: Bazaar Package Importer
  • Author(s): Petter Reinholdtsen
  • Date: 2005-04-07 01:18:44 UTC
  • Revision ID: james.westby@ubuntu.com-20050407011844-a1b206z5iefiu5vi
Tags: upstream-1.8.1
ImportĀ upstreamĀ versionĀ 1.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * You acknowledge that this software is not designed or intended for use
 
33
 * in the design, construction, operation or maintenance of any nuclear
 
34
 * facility.
 
35
 */
 
36
 
 
37
#include <stdio.h>
 
38
#include <stdlib.h>
 
39
#include <string.h>
 
40
 
 
41
#include <config.h>
 
42
#include <ipmitool/ipmi_intf.h>
 
43
#include <ipmitool/ipmi.h>
 
44
#include <ipmitool/ipmi_sdr.h>
 
45
#include <ipmitool/log.h>
 
46
 
 
47
#ifdef IPMI_INTF_OPEN
 
48
extern struct ipmi_intf ipmi_open_intf;
 
49
#endif
 
50
#ifdef IPMI_INTF_IMB
 
51
extern struct ipmi_intf ipmi_imb_intf;
 
52
#endif
 
53
#ifdef IPMI_INTF_LIPMI
 
54
extern struct ipmi_intf ipmi_lipmi_intf;
 
55
#endif
 
56
#ifdef IPMI_INTF_BMC
 
57
extern struct ipmi_intf ipmi_bmc_intf;
 
58
#endif
 
59
#ifdef IPMI_INTF_LAN
 
60
extern struct ipmi_intf ipmi_lan_intf;
 
61
#endif
 
62
#ifdef IPMI_INTF_LANPLUS
 
63
extern struct ipmi_intf ipmi_lanplus_intf;
 
64
#endif
 
65
 
 
66
struct ipmi_intf * ipmi_intf_table[] = {
 
67
#ifdef IPMI_INTF_OPEN
 
68
        &ipmi_open_intf,
 
69
#endif
 
70
#ifdef IPMI_INTF_IMB
 
71
        &ipmi_imb_intf,
 
72
#endif
 
73
#ifdef IPMI_INTF_LIPMI
 
74
        &ipmi_lipmi_intf,
 
75
#endif
 
76
#ifdef IPMI_INTF_BMC
 
77
        &ipmi_bmc_intf,
 
78
#endif
 
79
#ifdef IPMI_INTF_LAN
 
80
        &ipmi_lan_intf,
 
81
#endif
 
82
#ifdef IPMI_INTF_LANPLUS
 
83
        &ipmi_lanplus_intf,
 
84
#endif
 
85
        NULL
 
86
};
 
87
 
 
88
/* ipmi_intf_print  -  Print list of interfaces
 
89
 *
 
90
 * no meaningful return code
 
91
 */
 
92
void ipmi_intf_print(void)
 
93
{
 
94
        struct ipmi_intf ** intf;
 
95
        int def = 1;
 
96
 
 
97
        lprintf(LOG_NOTICE, "Interfaces:");
 
98
 
 
99
        for (intf = ipmi_intf_table; intf && *intf; intf++) {
 
100
                lprintf(LOG_NOTICE, "\t%-12s %s %s",
 
101
                        (*intf)->name, (*intf)->desc,
 
102
                        def ? "[default]" : "");
 
103
                def = 0;
 
104
        }
 
105
        lprintf(LOG_NOTICE, "");
 
106
}
 
107
 
 
108
/* ipmi_intf_load  -  Load an interface from the interface table above
 
109
 *                    If no interface name is given return first entry
 
110
 *
 
111
 * @name:       interface name to try and load
 
112
 *
 
113
 * returns pointer to inteface structure if found
 
114
 * returns NULL on error
 
115
 */
 
116
struct ipmi_intf * ipmi_intf_load(char * name)
 
117
{
 
118
        struct ipmi_intf ** intf;
 
119
        struct ipmi_intf * i;
 
120
 
 
121
        if (name == NULL) {
 
122
                i = ipmi_intf_table[0];
 
123
                if (i->setup != NULL && (i->setup(i) < 0)) {
 
124
                        lprintf(LOG_ERR, "Unable to setup "
 
125
                                "interface %s", name);
 
126
                        return NULL;
 
127
                }
 
128
                return i;
 
129
        }
 
130
 
 
131
        for (intf = ipmi_intf_table;
 
132
             ((intf != NULL) && (*intf != NULL));
 
133
             intf++) {
 
134
                i = *intf;
 
135
                if (strncmp(name, i->name, strlen(name)) == 0) {
 
136
                        if (i->setup != NULL && (i->setup(i) < 0)) {
 
137
                                lprintf(LOG_ERR, "Unable to setup "
 
138
                                        "interface %s", name);
 
139
                                return NULL;
 
140
                        }
 
141
                        return i;
 
142
                }
 
143
        }
 
144
 
 
145
        return NULL;
 
146
}
 
147
 
 
148
void
 
149
ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname)
 
150
{
 
151
        if (intf->session == NULL)
 
152
                return;
 
153
 
 
154
        memset(intf->session->hostname, 0, 16);
 
155
 
 
156
        if (hostname != NULL) {
 
157
                memcpy(intf->session->hostname, hostname,
 
158
                       __min(strlen(hostname), 64));
 
159
        }
 
160
}
 
161
 
 
162
void
 
163
ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
 
164
{
 
165
        if (intf->session == NULL)
 
166
                return;
 
167
 
 
168
        memset(intf->session->username, 0, 16);
 
169
 
 
170
        if (username == NULL)
 
171
                return;
 
172
 
 
173
        memcpy(intf->session->username, username, __min(strlen(username), 16));
 
174
}
 
175
 
 
176
void
 
177
ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
 
178
{
 
179
        if (intf->session == NULL)
 
180
                return;
 
181
 
 
182
        memset(intf->session->authcode, 0, IPMI_AUTHCODE_BUFFER_SIZE);
 
183
 
 
184
        if (password == NULL) {
 
185
                intf->session->password = 0;
 
186
                return;
 
187
        }
 
188
 
 
189
        intf->session->password = 1;
 
190
        memcpy(intf->session->authcode, password,
 
191
               __min(strlen(password), IPMI_AUTHCODE_BUFFER_SIZE));
 
192
}
 
193
 
 
194
void
 
195
ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, uint8_t level)
 
196
{
 
197
        if (intf->session == NULL)
 
198
                return;
 
199
 
 
200
        intf->session->privlvl = level;
 
201
}
 
202
 
 
203
void
 
204
ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf, uint8_t cipher_suite_id)
 
205
{
 
206
        if (intf->session == NULL)
 
207
                return;
 
208
 
 
209
        intf->session->cipher_suite_id = cipher_suite_id;
 
210
}
 
211
 
 
212
void
 
213
ipmi_intf_session_set_port(struct ipmi_intf * intf, int port)
 
214
{
 
215
        if (intf->session == NULL)
 
216
                return;
 
217
 
 
218
        intf->session->port = port;
 
219
}
 
220
 
 
221
void
 
222
ipmi_intf_session_set_authtype(struct ipmi_intf * intf, uint8_t authtype)
 
223
{
 
224
        if (intf->session == NULL)
 
225
                return;
 
226
 
 
227
        intf->session->authtype_set = authtype;
 
228
}
 
229
 
 
230
void
 
231
ipmi_cleanup(struct ipmi_intf * intf)
 
232
{
 
233
        ipmi_sdr_list_empty(intf);
 
234
}