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