1 | /*
|
---|
2 | * pins - Print iLO Network Settings
|
---|
3 | *
|
---|
4 | * This utility program queries HP Proliant server's iLO processor nework settings,
|
---|
5 | * and prints them in an XML stream on standard output.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2012 Hewlett-Packard
|
---|
8 | *
|
---|
9 | * This program is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Dependencies : pins requires presence of the "hpilo" driver in host system.
|
---|
26 | *
|
---|
27 | * Arguments : <none>
|
---|
28 | *
|
---|
29 | * Release history
|
---|
30 | * - 1.0a, 11-Nov-2011, created.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include <unistd.h>
|
---|
34 | #include <fcntl.h>
|
---|
35 | #include <sys/types.h>
|
---|
36 | #include <stdlib.h>
|
---|
37 | #include <stdio.h>
|
---|
38 | #include <time.h>
|
---|
39 | #include <string.h>
|
---|
40 |
|
---|
41 | #define SLEEP nanosleep(&st, NULL);
|
---|
42 |
|
---|
43 | int main()
|
---|
44 | {
|
---|
45 | int fd, status, len;
|
---|
46 | struct timespec st;
|
---|
47 | int step, eof;
|
---|
48 | char *c1, *c2;
|
---|
49 | int trace;
|
---|
50 |
|
---|
51 | /* xml commands */
|
---|
52 | unsigned char h1[8] = {0x0,0x0,0x0,0x0,0x02,0x0,0x0,0x0};
|
---|
53 | unsigned char h2[12] = {0x0,0x0,0x0,0x0,0x50,0x0,0x0,0x0,0x04,0x0,0x0,0x0};
|
---|
54 | unsigned char h3[12] = {0x0,0x0,0x0,0x0,0x50,0x0,0x0,0x0,0x05,0x0,0x0,0x0};
|
---|
55 | unsigned char h4[12] = {0x0,0x0,0x0,0x0,0x50,0x0,0x0,0x0,0x06,0x0,0x0,0x0};
|
---|
56 | unsigned char h5[8] = {0x0,0x0,0x0,0x0,0x67,0x0,0x0,0x0};
|
---|
57 | unsigned char h6[8] = {0x0,0x0,0x0,0x0,0x43,0x0,0x0,0x0};
|
---|
58 | unsigned char h7[8] = {0x0,0x0,0x01,0x0,0x43,0x0,0x0,0x0};
|
---|
59 | unsigned char h8[8] = {0x0,0x0,0x02,0x0,0x43,0x0,0x0,0x0};
|
---|
60 | unsigned char h9[8] = {0x0,0x0,0x03,0x0,0x43,0x0,0x0,0x0};
|
---|
61 | char xml6[] = "<?xml version=\"1.0\"?>\r\n";
|
---|
62 | char xml7[] = "<LOCFG VERSION=\"2.24\">";
|
---|
63 | char xml8[] = "<RIBCL VERSION=\"2.0\"><LOGIN USER_LOGIN=\"anyBody\" PASSWORD=\"anyThing\"><RIB_INFO MODE=\"read\"><GET_NETWORK_SETTINGS/></RIB_INFO></LOGIN></RIBCL>\r\n";
|
---|
64 |
|
---|
65 | struct {
|
---|
66 | unsigned char header[8]; /* header[0:1] = iLO command length , header included */
|
---|
67 | char xml[4088];
|
---|
68 | } wBuf;
|
---|
69 | struct {
|
---|
70 | unsigned char header[12]; /* header[0:1] = iLO response length , header included */
|
---|
71 | char xml[4084];
|
---|
72 | } rBuf;
|
---|
73 |
|
---|
74 | char xmlOutput[8192];
|
---|
75 | char *xml;
|
---|
76 |
|
---|
77 | /* initialize */
|
---|
78 |
|
---|
79 | trace = 0;
|
---|
80 |
|
---|
81 | st.tv_sec = 0;
|
---|
82 | st.tv_nsec = 1000000;
|
---|
83 |
|
---|
84 | bzero(&xmlOutput, sizeof(xmlOutput));
|
---|
85 | xml = &xmlOutput[0];
|
---|
86 |
|
---|
87 | /* open iLO channel */
|
---|
88 | fd = open("/dev/hpilo/d0ccb0", O_RDWR|O_EXCL);
|
---|
89 | if (fd < 0) {
|
---|
90 | perror("iLO device open failed");
|
---|
91 | exit(1);
|
---|
92 | }
|
---|
93 | SLEEP
|
---|
94 |
|
---|
95 | /* T1 - no xml */
|
---|
96 | step = 10;
|
---|
97 | bzero(&wBuf, sizeof(wBuf));
|
---|
98 | bcopy(&h1, &wBuf.header, sizeof(h1));
|
---|
99 | len = sizeof(h1);
|
---|
100 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
101 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
102 | SLEEP
|
---|
103 | if ((len = read(fd, &rBuf, 72))< 0) goto read_error;
|
---|
104 | if(trace) printf("%s%d%s\n","t1: ", len," bytes read");
|
---|
105 | SLEEP
|
---|
106 |
|
---|
107 | /* T2 - no xml, but 4 extra-header bytes */
|
---|
108 | step = 20;
|
---|
109 | bzero(&wBuf, sizeof(wBuf));
|
---|
110 | bcopy(&h2, &wBuf.header, sizeof(h2));
|
---|
111 | len = sizeof(h2);
|
---|
112 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
113 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
114 | SLEEP
|
---|
115 | if ((len = read(fd, &rBuf, 189))< 0) goto read_error;
|
---|
116 | if(trace) printf("%s%d%s\n","t2: ", len," bytes read");
|
---|
117 | SLEEP
|
---|
118 |
|
---|
119 | /* T3 - no xml, but 4 extra-header bytes */
|
---|
120 | step = 30;
|
---|
121 | bzero(&wBuf, sizeof(wBuf));
|
---|
122 | bcopy(&h3, &wBuf.header, sizeof(h3));
|
---|
123 | len = sizeof(h3);
|
---|
124 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
125 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
126 | SLEEP
|
---|
127 | if ((len = read(fd, &rBuf, 189))< 0) goto read_error;
|
---|
128 | if(trace) printf("%s%d%s\n","t3: ", len," bytes read");
|
---|
129 | SLEEP
|
---|
130 |
|
---|
131 | /* T4 - no xml, but 4 extra-header bytes */
|
---|
132 | step = 40;
|
---|
133 | bzero(&wBuf, sizeof(wBuf));
|
---|
134 | bcopy(&h4, &wBuf.header, sizeof(h4));
|
---|
135 | len = sizeof(h4);
|
---|
136 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
137 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
138 | SLEEP
|
---|
139 | if ((len = read(fd, &rBuf, 189))< 0) goto read_error;
|
---|
140 | if(trace) printf("%s%d%s\n","t4: ", len," bytes read");
|
---|
141 | SLEEP
|
---|
142 |
|
---|
143 | /* T5 - no xml */
|
---|
144 | step = 50;
|
---|
145 | bzero(&wBuf, sizeof(wBuf));
|
---|
146 | bcopy(&h5, &wBuf.header, sizeof(h5));
|
---|
147 | len = sizeof(h5);
|
---|
148 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
149 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
150 | SLEEP
|
---|
151 | if ((len = read(fd, &rBuf, 104))< 0) goto read_error;
|
---|
152 | if(trace) printf("%s%d%s\n","t5: ", len," bytes read");
|
---|
153 | SLEEP
|
---|
154 |
|
---|
155 | /* T6- xml */
|
---|
156 | step = 60;
|
---|
157 | bzero(&wBuf, sizeof(wBuf));
|
---|
158 | bcopy(&h6, &wBuf.header, sizeof(h6));
|
---|
159 | bcopy(&xml6, &wBuf.xml, sizeof(xml6)-1);
|
---|
160 | len = sizeof(wBuf.header) + (sizeof(xml6)-1);
|
---|
161 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
162 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
163 | SLEEP
|
---|
164 | bzero(&wBuf, sizeof(wBuf));
|
---|
165 | do {
|
---|
166 | step++;
|
---|
167 | if ((len = read(fd, &rBuf, 2176))< 0) goto read_error;
|
---|
168 | if(trace) printf("%s%d%s%d%s\n","t",step,": ", len," bytes read");
|
---|
169 | SLEEP
|
---|
170 | eof = *(unsigned int *)&rBuf.header[8];
|
---|
171 | /* if(eof == 0) printf("%s\n",&rBuf.xml); */
|
---|
172 | } while(eof == 0);
|
---|
173 |
|
---|
174 | /* T7 - xml */
|
---|
175 | step = 70;
|
---|
176 | bzero(&wBuf, sizeof(wBuf));
|
---|
177 | bcopy(&h7, &wBuf.header, sizeof(h7));
|
---|
178 | bcopy(&xml7, &wBuf.xml, sizeof(xml7)-1);
|
---|
179 | len = sizeof(wBuf.header) + (sizeof(xml7)-1);
|
---|
180 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
181 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
182 | SLEEP
|
---|
183 | bzero(&wBuf, sizeof(wBuf));
|
---|
184 | do {
|
---|
185 | step++;
|
---|
186 | if ((len = read(fd, &rBuf, 2176))< 0) goto read_error;
|
---|
187 | if(trace) printf("%s%d%s%d%s\n","t",step,": ", len," bytes read");
|
---|
188 | SLEEP
|
---|
189 | eof = *(unsigned int *)&rBuf.header[8];
|
---|
190 | /* if(eof == 0) printf("%s\n",&rBuf.xml); */
|
---|
191 | } while(eof == 0);
|
---|
192 |
|
---|
193 | /* T8 - xml */
|
---|
194 | step = 80;
|
---|
195 | bzero(&wBuf, sizeof(wBuf));
|
---|
196 | bcopy(&h8, &wBuf.header, sizeof(h8));
|
---|
197 | bcopy(&xml8, &wBuf.xml, sizeof(xml8)-1);
|
---|
198 | len = sizeof(wBuf.header) + (sizeof(xml8)-1);
|
---|
199 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
200 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
201 | SLEEP
|
---|
202 | bzero(&wBuf, sizeof(wBuf));
|
---|
203 | do {
|
---|
204 | step++;
|
---|
205 | if ((len = read(fd, &rBuf, 2176))< 0) goto read_error;
|
---|
206 | if (trace) printf("%s%d%s%d%s\n","t",step,": ", len," bytes read");
|
---|
207 | SLEEP
|
---|
208 | eof = *(unsigned int *)&rBuf.header[8];
|
---|
209 | if(eof == 0) xml += sprintf(xml,"%s",&rBuf.xml);
|
---|
210 | } while(eof == 0);
|
---|
211 |
|
---|
212 | c1 = strstr(xmlOutput, "<GET_NETWORK_SETTINGS>");
|
---|
213 | c2 = strstr(xmlOutput, "</GET_NETWORK_SETTINGS>");
|
---|
214 | *(c2+sizeof("</GET_NETWORK_SETTINGS>")+1) = 0;
|
---|
215 | printf("%s\n", c1);
|
---|
216 |
|
---|
217 | /* T9 - no xml - last command to iLO, no response expected) */
|
---|
218 | step = 9;
|
---|
219 | bzero(&wBuf, sizeof(wBuf));
|
---|
220 | bcopy(&h9, &wBuf.header, sizeof(h9));
|
---|
221 | len = sizeof(h9);
|
---|
222 | *(unsigned short *)&wBuf.header[0] = (unsigned short) len;
|
---|
223 | if ((status = write(fd, &wBuf, len))!= len) goto write_error;
|
---|
224 | SLEEP
|
---|
225 | goto finish;
|
---|
226 |
|
---|
227 | write_error :
|
---|
228 | printf("%s%d\n", "iLO channel write failed in step", step);
|
---|
229 | goto finish;
|
---|
230 | read_error :
|
---|
231 | printf("%s%d\n", "iLO channel read failed in step", step);
|
---|
232 | goto finish;
|
---|
233 | finish :
|
---|
234 | close(fd);
|
---|
235 | printf("%s\n","finished.");
|
---|
236 | }
|
---|