1 /*
2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject
3 * to license terms.
4 */
5
6 /*
7 * BSD 3 Clause License
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * - Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * - Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. ''AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
37 */
38
39 /*
40 * The SCSI Interface provides low-level control of SCSI devices. This files
41 * implements all the scsi interfaces. There are four type of methods for
42 * each interface. These methods types are extract request, extract reply,
43 * print reply and compare reply.
44 */
45
46 #include <stdio.h>
47 #include <string.h>
48
49 #include <ndmp.h>
50 #include <log.h>
51 #include <ndmp_conv.h>
52 #include <ndmp_lib.h>
53 #include <ndmp_comm_lib.h>
54 #include <ndmp_connect.h>
55
56 #include <scsi_tester.h>
57
58 /*
59 * ndmp_scsi_open_reply_print(): Prints the reply object.
60 *
61 * Arguments: FILE * - Handle to the log file. void *ndmpMsg - Reply object to
62 * be printed in the log file.
63 */
64 void
65 ndmp_scsi_open_reply_print(FILE * out, void *ndmpMsg)
66 {
67 ndmp_scsi_open_reply *reply;
68 if (ndmpMsg != NULL) {
69 reply = ndmpMsg;
70 (void) ndmp_lprintf(out, "ndmp_error %s \n",
71 ndmpErrorCodeToStr(reply->error));
72 }
73 }
74
75 /*
76 * ndmp_scsi_close_reply_print(): Prints the reply object.
77 *
78 * Arguments: FILE * - Handle to the log file. void *ndmpMsg - Reply object to
79 * be printed in the log file.
80 */
81 void
82 ndmp_scsi_close_reply_print(FILE * out, void *ndmpMsg)
83 {
84 ndmp_scsi_close_reply *reply;
85 if (ndmpMsg != NULL) {
86 reply = (ndmp_scsi_close_reply *) ndmpMsg;
87 (void) ndmp_lprintf(out, "error %s \n",
88 ndmpErrorCodeToStr(reply->error));
89 }
90 }
91
92 /*
93 * ndmp_scsi_get_state_reply_print(): Prints the reply object.
94 *
95 * Arguments: FILE * - Handle to the log file. void *ndmpMsg - Reply object to
96 * be printed in the log file.
97 */
98 void
99 ndmp_scsi_get_state_reply_print(FILE * out, void *ndmpMsg)
100 {
101 ndmp_scsi_get_state_reply *reply;
102
103 if (ndmpMsg != NULL) {
104 reply = (ndmp_scsi_get_state_reply *) ndmpMsg;
105 (void) ndmp_lprintf(out, "error %s \n",
106 ndmpErrorCodeToStr(reply->error));
107 (void) ndmp_lprintf(out, "target_controller %d \n",
108 reply->target_controller);
109 (void) ndmp_lprintf(out, "target_id %d \n", reply->target_id);
110 (void) ndmp_lprintf(out, "target_lun %d \n", reply->target_lun);
111 } else {
112 (void) printf("ndmp_scsi_get_state_reply_print:"
113 " reply is null\n");
114 }
115 }
116
117 /*
118 * ndmp_scsi_reset_device_reply_print(): Prints the reply object.
119 *
120 * Arguments: FILE * - Handle to the log file. void *ndmpMsg - Reply object to
121 * be printed in the log file.
122 */
123 void
124 ndmp_scsi_reset_device_reply_print(FILE * out, void *ndmpMsg)
125 {
126 ndmp_scsi_reset_device_reply *reply;
127
128 if (ndmpMsg != NULL) {
129 reply = (ndmp_scsi_reset_device_reply *) ndmpMsg;
130 (void) ndmp_lprintf(out, "error %s \n",
131 ndmpErrorCodeToStr(reply->error));
132 }
133 }
134
135 /*
136 * ndmp_scsi_execute_cdb_reply_print(): Prints the reply object.
137 *
138 * Arguments: FILE * - Handle to the log file. void *ndmpMsg - Reply object to
139 * be printed in the log file.
140 */
141 void
142 ndmp_scsi_execute_cdb_reply_print(FILE * out, void *ndmpMsg, int cdb)
143 {
144 ndmp_scsi_execute_cdb_reply *reply;
145 if (ndmpMsg != NULL) {
146 reply = (ndmp_scsi_execute_cdb_reply *) ndmpMsg;
147 (void) ndmp_lprintf(out, "error %s \n",
148 ndmpErrorCodeToStr(reply->error));
149 (void) ndmp_lprintf(out, "status %c \n", reply->status);
150 (void) ndmp_lprintf(out, "dataout_len %d \n",
151 (int) reply->dataout_len);
152 print_datain(out, reply, cdb);
153 print_ext_sense(out, &(reply->ext_sense));
154 }
155 }
156
157 /*
158 * scsi_execute_cdb_core() : This message behaves in exactly the same way as
159 * the NDMP_TAPE_EXECUTE_CDB request except that it sends the CDB to the scsi
160 * device. This request SHOULD not be used to change the state of the scsi
161 * device.
162 */
163 int
164 scsi_execute_cdb_core(ndmp_error error,
165 char *cdb, FILE * outfile, conn_handle * conn)
166 {
167 void *reply_mem;
168 /* Create and print the object start */
169 ndmp_scsi_execute_cdb_request *request =
170 (ndmp_scsi_execute_cdb_request *) malloc
171 (sizeof (ndmp_scsi_execute_cdb_request));
172 request->flags = 1;
173 request->timeout = 0;
174 request->datain_len = 36;
175 request->cdb.cdb_len = CDB_SIZE;
176 if (error == NDMP_ILLEGAL_ARGS_ERR)
177 request->flags = (ushort_t) ~0;
178 request->cdb.cdb_val = (char *) malloc(CDB_SIZE);
179 (void) create_cdb((struct cdb *)(&(request->cdb)), getCdbNum(cdb));
180 request->dataout.dataout_len = 0;
181 request->dataout.dataout_val = 0;
182 ndmp_lprintf(outfile, "REQUEST : NDMP_SCSI_EXECUTE_CDB\n");
183 /* Create and print the object end */
184
185 /* send the request start */
186 if (!process_request((void *) request,
187 NDMP_SCSI_EXECUTE_CDB, conn, &reply_mem, outfile)) {
188 if (reply_mem != NULL &&
189 error == ((ndmp_scsi_execute_cdb_reply *)
190 reply_mem)->error) {
191 ndmp_scsi_execute_cdb_reply_print(outfile,
192 ((ndmp_scsi_execute_cdb_reply *) reply_mem),
193 getCdbNum(cdb));
194 return (SUCCESS);
195 }
196 }
197 return (ERROR);
198 }
199
200 /*
201 * scsi_reset_device_core() Basic method to send scsi reset device request to
202 * the ndmp server
203 */
204 int
205 scsi_reset_device_core(ndmp_error error, FILE * outfile, conn_handle * conn)
206 {
207 void *reply_mem = NULL;
208 /* Create and print the object end */
209 ndmp_lprintf(outfile, "REQUEST : NDMP_SCSI_RESET_DEVICE\n");
210 /* send the request start */
211 if (!process_request(NULL,
212 NDMP_SCSI_RESET_DEVICE, conn, &reply_mem, outfile)) {
213 if (reply_mem != NULL &&
214 error == ((ndmp_scsi_reset_device_reply *)
215 reply_mem)->error) {
216 ndmp_scsi_reset_device_reply_print(outfile,
217 ((ndmp_scsi_execute_cdb_reply *) reply_mem));
218 return (SUCCESS);
219 }
220 }
221 return (ERROR);
222 /* Compare and print the reply end */
223 }
224
225 /*
226 * scsi_get_state_core() Basic method to send scsi get state request to the
227 * ndmp server
228 */
229 int
230 scsi_get_state_core(ndmp_error error, FILE * outfile, conn_handle * conn)
231 {
232 void *reply_mem;
233 /* Create and print the object end */
234 ndmp_lprintf(outfile, "REQUEST : NDMP_SCSI_GET_STATE\n");
235 /* send the request start */
236 if (!process_request(NULL,
237 NDMP_SCSI_GET_STATE, conn, &reply_mem, outfile)) {
238 if (reply_mem != NULL &&
239 error == ((ndmp_scsi_get_state_reply *)
240 reply_mem)->error) {
241 ndmp_scsi_get_state_reply_print(outfile,
242 ((ndmp_scsi_get_state_reply *) reply_mem));
243 return (SUCCESS);
244 }
245 }
246 return (ERROR);
247 /* Compare and print the reply end */
248 }
249
250 /*
251 * tape_open_core() Basic method to send tape open request to the ndmp server
252 */
253 int
254 scsi_open_core(ndmp_error error,
255 char *device, FILE * outfile, conn_handle * conn)
256 {
257 void *reply_mem = NULL;
258 ndmp_scsi_open_request *request = (ndmp_scsi_open_request *)
259 malloc(sizeof (ndmp_scsi_open_request));
260 /* Create and print the object start */
261 request->device = strdup(device);
262 /* Create and print the object end */
263 ndmp_lprintf(outfile, "REQUEST : NDMP_SCSI_OPEN\n");
264 /* Send the request start */
265 if (!process_request((void *) request,
266 NDMP_SCSI_OPEN, conn, &reply_mem, outfile)) {
267 if (reply_mem != NULL &&
268 error == ((ndmp_scsi_open_reply *) reply_mem)->error) {
269 ndmp_scsi_open_reply_print(outfile,
270 ((ndmp_scsi_open_reply *) reply_mem));
271 return (SUCCESS);
272 }
273 }
274 free(request->device);
275 free(request);
276 return (ERROR);
277 /* Compare and print the reply end */
278 }
279
280 /*
281 * scsi_close_core() Basic method to send scsi open request to the ndmp
282 * server
283 */
284 int
285 scsi_close_core(ndmp_error error, FILE * outfile, conn_handle * conn)
286 {
287 void *reply_mem = NULL;
288 /* Create and print the object start */
289 ndmp_lprintf(outfile, "REQUEST : NDMP_SCSI_CLOSE\n");
290 /* send the request start */
291 if (!process_request(NULL,
292 NDMP_SCSI_CLOSE, conn, &reply_mem, outfile)) {
293 if (reply_mem != NULL && error != 0)
294 ndmp_scsi_close_reply_print(outfile,
295 ((ndmp_scsi_close_reply *) reply_mem));
296 return (SUCCESS);
297 }
298 return (ERROR);
299 }
300
301 /*
302 * Intialize and Cleanup methods
303 */
304
305 /*
306 * scsi_close_intl() Do the initialization for the scsi close. Arguments :
307 * device - scsi device to be opened.
308 */
309 int
310 scsi_close_intl(ndmp_error error,
311 char **device, conn_handle * conn, FILE * outfile)
312 {
313 int ret = 0;
314 if (error == NDMP_DEV_NOT_OPEN_ERR)
315 return (ret);
316 if (error == NDMP_NOT_AUTHORIZED_ERR) {
317 scsi_open_core(NDMP_NO_ERR, *device, outfile, conn);
318 return (ret);
319 }
320 ret = scsi_open_core(NDMP_NO_ERR, *device, outfile, conn);
321 return (ret);
322 }
323
324 /*
325 * scsi_open_intl() Do the initialization for the scsi open. Arguments :
326 * device - scsi device to be opened.
327 */
328 int
329 scsi_open_intl(ndmp_error error, char **device,
330 conn_handle * conn, FILE * outfile)
331 {
332 int ret = 0;
333 if (error == NDMP_NOT_AUTHORIZED_ERR) {
334 return (ret);
335 }
336 if (error == NDMP_NO_DEVICE_ERR)
337 *device = strdup("no dev err");
338 if (error == NDMP_DEVICE_OPENED_ERR)
339 ret = scsi_open_core(NDMP_NO_ERR, *device, outfile, conn);
340 return (ret);
341 }
342
343 /*
344 * scsi_open_cleanup() Cleanup method for scsi open interface. Arguments :
345 * error - ndmp Error device - Device to open. conn - Connection. outfile -
346 * Log file.
347 */
348 int
349 scsi_open_cleanup(ndmp_error error,
350 char *device, conn_handle * conn, FILE * outfile)
351 {
352 int ret = 0;
353
354 if (error == NDMP_NO_DEVICE_ERR) {
355 if (device != NULL)
356 free(device);
357 return (ret);
358 }
359 if (error == NDMP_NOT_AUTHORIZED_ERR)
360 return (ret);
361 /* this peice of code is for scsi get state */
362 if (error == NDMP_DEV_NOT_OPEN_ERR)
363 return (ret);
364 ret = scsi_close_core(NDMP_NO_ERR, outfile, conn);
365
366 return (ret);
367 }
368
369 /*
370 * Interface level methods
371 */
372
373 /*
374 * inf_scsi_execute_cdb() : This message behaves in exactly the same way as
375 * the NDMP_TAPE_EXECUTE_CDB request except that it sends the CDB to the scsi
376 * device.
377 */
378 int
379 inf_scsi_execute_cdb(ndmp_error error,
380 char *cdb, char *dev, FILE * outfile, conn_handle * conn)
381 {
382 int ret = 0;
383 (void) ndmp_fprintf(outfile,
384 "Test case name : ndmp_scsi_execute_cdb\n");
385 (void) ndmp_fprintf(outfile,
386 "Error condition : %s\n", ndmpErrorCodeToStr(error));
387 /* Initialization */
388 ret = scsi_close_intl(error, &dev, conn, outfile);
389 print_intl_result(ret, outfile);
390
391 /* Send the request */
392 if (error == NDMP_ILLEGAL_ARGS_ERR)
393 cdb = strdup("illegal");
394 ret = scsi_execute_cdb_core(error, cdb, outfile, conn);
395 if (error == NDMP_ILLEGAL_ARGS_ERR)
396 free(cdb);
397 print_test_result(ret, outfile);
398
399 /* Clean up */
400 ret = scsi_open_cleanup(error, dev, conn, outfile);
401 print_cleanup_result(ret, outfile);
402 return (ret);
403 }
404
405 /*
406 * inf_scsi_reset_device() : The flow of the test case is decided by this
407 * method.
408 */
409 int
410 inf_scsi_reset_device(ndmp_error error,
411 char *device, FILE * outfile, conn_handle * conn)
412 {
413 int ret = 0;
414 (void) ndmp_fprintf(outfile,
415 "Test case name : ndmp_scsi_reset_device\n");
416 (void) ndmp_fprintf(outfile,
417 "Error condition : %s\n", ndmpErrorCodeToStr(error));
418
419 /* Initialization */
420 ret = scsi_close_intl(error, &device, conn, outfile);
421 print_intl_result(ret, outfile);
422
423 /* Send the request */
424 ret = scsi_reset_device_core(error, outfile, conn);
425 print_test_result(ret, outfile);
426
427 /* Clean up */
428 ret = scsi_open_cleanup(error, device, conn, outfile);
429 print_cleanup_result(ret, outfile);
430
431 return (ret);
432 }
433
434 /*
435 * inf_scsi_get_state() : The flow of the test case is decided by this
436 * method.
437 */
438 int
439 inf_scsi_get_state(ndmp_error error,
440 char *device, FILE * outfile, conn_handle * conn)
441 {
442 int ret = 0;
443 (void) ndmp_fprintf(outfile,
444 "Test case name : ndmp_scsi_get_state\n");
445 (void) ndmp_fprintf(outfile,
446 "Error condition : %s\n", ndmpErrorCodeToStr(error));
447
448 /* Initialization */
449 ret = scsi_close_intl(error, &device, conn, outfile);
450 print_intl_result(ret, outfile);
451
452 /* Send the request */
453 ret = scsi_get_state_core(error, outfile, conn);
454 print_test_result(ret, outfile);
455
456 /* Clean up */
457 ret = scsi_open_cleanup(error, device, conn, outfile);
458 print_cleanup_result(ret, outfile);
459
460 return (ret);
461 }
462
463 /*
464 * inf_scsi_open() : The flow of the test case is decided by this method.
465 */
466 int
467 inf_scsi_open(ndmp_error error,
468 char *device, FILE * outfile, conn_handle * conn)
469 {
470 int ret = 0;
471 (void) ndmp_fprintf(outfile,
472 "Test case name : ndmp_scsi_open\n");
473 (void) ndmp_fprintf(outfile,
474 "Error condition : %s\n", ndmpErrorCodeToStr(error));
475
476 /* Initialization */
477 ret = scsi_open_intl(error, &device, conn, outfile);
478 print_intl_result(ret, outfile);
479
480 /* Send the request */
481 ret = scsi_open_core(error, device, outfile, conn);
482 print_test_result(ret, outfile);
483
484 /* Clean up */
485 ret = scsi_open_cleanup(error, device, conn, outfile);
486 print_cleanup_result(ret, outfile);
487
488 return (ret);
489 }
490
491 /*
492 * inf_scsi_close() : The flow of the test case is decided by this method.
493 */
494 int
495 inf_scsi_close(ndmp_error error,
496 char *device, FILE * outfile, conn_handle * conn)
497 {
498 int ret = 0;
499 (void) ndmp_fprintf(outfile,
500 "Test case name : ndmp_scsi_close\n");
501 (void) ndmp_fprintf(outfile,
502 "Error condition : %s\n", ndmpErrorCodeToStr(error));
503 /* Initialization */
504 ret = scsi_close_intl(error, &device, conn, outfile);
505 print_intl_result(ret, outfile);
506
507 /* Send the request */
508 ret = scsi_close_core(error, outfile, conn);
509 print_test_result(ret, outfile);
510 return (ret);
511 }
512
513 /*
514 * Unit test code
515 */
516
517 /*
518 * NDMP_SCSI_CLOSE
519 */
520 int
521 unit_test_scsi_close(host_info * auth,
522 char *device, FILE * logfile)
523 {
524 conn_handle conn;
525
526 /* Test 1: NDMP_NOT_AUTHORIZED_ERR */
527 (void) ndmp_dprintf(logfile,
528 "unit_test_scsi_close: "
529 "Test 1: NDMP_NOT_AUTHORIZED_ERR start\n");
530 strcpy(auth->password, "admn");
531 (void) open_connection(auth, &conn, logfile);
532 inf_scsi_close(NDMP_NOT_AUTHORIZED_ERR, device, logfile, &conn);
533 close_connection(&conn, logfile);
534 strcpy(auth->password, "admin");
535 (void) ndmp_dprintf(logfile,
536 "unit_test_scsi_close: "
537 "Test 1: NDMP_NOT_AUTHORIZED_ERR end\n");
538
539 (void) open_connection(auth, &conn, logfile);
540
541 /* Test 2: NDMP_NO_ERR */
542 (void) ndmp_dprintf(logfile,
543 "unit_test_scsi_close: "
544 "Test 2: NDMP_NO_ERR start\n");
545 inf_scsi_close(NDMP_NO_ERR, device, logfile, &conn);
546 (void) ndmp_dprintf(logfile,
547 "unit_test_scsi_close: "
548 "Test 2: NDMP_NO_ERR end\n");
549
550 /* Test 3: NDMP_DEV_NOT_OPEN_ERR */
551 (void) ndmp_dprintf(logfile,
552 "unit_test_scsi_close: "
553 "Test 3: NDMP_DEV_NOT_OPEN_ERR start\n");
554 inf_scsi_close(NDMP_DEV_NOT_OPEN_ERR, device, logfile, &conn);
555 (void) ndmp_dprintf(logfile,
556 "unit_test_scsi_close: "
557 "Test 3: NDMP_DEV_NOT_OPEN_ERR end\n");
558
559 close_connection(&conn, logfile);
560 return (1);
561 }
562
563 /*
564 * NDMP_SCSI_RESET_DEVICE
565 */
566 int
567 unit_test_scsi_reset_device(host_info * auth,
568 char *device, FILE * logfile)
569 {
570 conn_handle conn;
571
572 /* Test 1: NDMP_NOT_AUTHORIZED_ERR */
573 (void) ndmp_dprintf(logfile,
574 "unit_test_scsi_reset_device: "
575 "Test 1: NDMP_NOT_AUTHORIZED_ERR start\n");
576 strcpy(auth->password, "admn");
577 (void) open_connection(auth, &conn, logfile);
578 inf_scsi_reset_device(NDMP_NOT_AUTHORIZED_ERR, device, logfile, &conn);
579 close_connection(&conn, logfile);
580 strcpy(auth->password, "admin");
581 (void) ndmp_dprintf(logfile,
582 "unit_test_scsi_reset_device: "
583 "Test 1: NDMP_NOT_AUTHORIZED_ERR end\n");
584
585 (void) open_connection(auth, &conn, logfile);
586
587 /* Test 2: NDMP_NO_ERR */
588 (void) ndmp_dprintf(logfile,
589 "unit_test_scsi_reset_device: "
590 "Test 2: NDMP_NO_ERR start\n");
591 inf_scsi_reset_device(NDMP_NO_ERR, device, logfile, &conn);
592 (void) ndmp_dprintf(logfile,
593 "unit_test_scsi_reset_device: "
594 "Test 2: NDMP_NO_ERR end\n");
595
596 /* Test 3: NDMP_DEV_NOT_OPEN_ERR */
597 (void) ndmp_dprintf(logfile,
598 "unit_test_scsi_reset_device: "
599 "Test 3: NDMP_DEV_NOT_OPEN_ERR start\n");
600 inf_scsi_reset_device(NDMP_DEV_NOT_OPEN_ERR, device, logfile, &conn);
601 (void) ndmp_dprintf(logfile,
602 "unit_test_scsi_reset_device: "
603 "Test 3: NDMP_DEV_NOT_OPEN_ERR end\n");
604
605 close_connection(&conn, logfile);
606
607 return (1);
608 }
609
610 /*
611 * NDMP_SCSI_GET_STATE
612 */
613 int
614 unit_test_scsi_get_state(struct host_info * auth,
615 char *device, FILE * logfile)
616 {
617 conn_handle conn;
618
619 /* Test 1: NDMP_NOT_AUTHORIZED_ERR */
620 (void) ndmp_dprintf(logfile,
621 "unit_test_scsi_get_state: "
622 "Test 1: NDMP_NOT_AUTHORIZED_ERR start\n");
623 strcpy(auth->password, "admn");
624 (void) open_connection(auth, &conn, logfile);
625 inf_scsi_get_state(NDMP_NOT_AUTHORIZED_ERR, device, logfile, &conn);
626 close_connection(&conn, logfile);
627 strcpy(auth->password, "admin");
628 (void) ndmp_dprintf(logfile,
629 "unit_test_scsi_get_state: "
630 "Test 1: NDMP_NOT_AUTHORIZED_ERR end\n");
631
632 (void) open_connection(auth, &conn, logfile);
633
634 /* Test 2: NDMP_NO_ERR */
635 (void) ndmp_dprintf(logfile,
636 "unit_test_scsi_get_state: "
637 "Test 2: NDMP_NO_ERR start\n");
638 inf_scsi_get_state(NDMP_NO_ERR, device, logfile, &conn);
639 (void) ndmp_dprintf(logfile,
640 "unit_test_scsi_get_state: "
641 "Test 2: NDMP_NO_ERR end\n");
642
643 /* Test 3: NDMP_DEV_NOT_OPEN_ERR */
644 (void) ndmp_dprintf(logfile,
645 "unit_test_scsi_get_state: "
646 "Test 3: NDMP_DEV_NOT_OPEN_ERR start\n");
647 inf_scsi_get_state(NDMP_DEV_NOT_OPEN_ERR, device, logfile, &conn);
648 (void) ndmp_dprintf(logfile,
649 "unit_test_scsi_get_state: "
650 "Test 3: NDMP_DEV_NOT_OPEN_ERR end\n");
651
652 close_connection(&conn, logfile);
653
654 return (1);
655 }
656
657 /*
658 * NDMP_SCSI_OPEN
659 */
660 int
661 unit_test_scsi_open(host_info * auth, char *device, FILE * logfile)
662 {
663 conn_handle conn;
664
665 /* Test 1: NDMP_NOT_AUTHORIZED_ERR */
666 (void) ndmp_dprintf(logfile,
667 "unit_test_scsi_open: "
668 "Test 1: NDMP_NOT_AUTHORIZED_ERR start\n");
669 strcpy(auth->password, "admn");
670 (void) open_connection(auth, &conn, logfile);
671 inf_scsi_open(NDMP_NOT_AUTHORIZED_ERR, device, logfile, &conn);
672 close_connection(&conn, logfile);
673 strcpy(auth->password, "admin");
674 (void) ndmp_dprintf(logfile,
675 "unit_test_scsi_open: "
676 "Test 1: NDMP_NOT_AUTHORIZED_ERR end\n");
677
678 (void) open_connection(auth, &conn, logfile);
679
680 /* Test 2: NDMP_NO_ERR */
681 (void) ndmp_dprintf(logfile,
682 "unit_test_scsi_open: "
683 "Test 2: NDMP_NO_ERR start\n");
684 inf_scsi_open(NDMP_NO_ERR, device, logfile, &conn);
685 (void) ndmp_dprintf(logfile,
686 "unit_test_scsi_open: "
687 "Test 2: NDMP_NO_ERR end\n");
688
689 /* Test 3: NDMP_DEVICE_OPENED_ERR */
690 (void) ndmp_dprintf(logfile,
691 "unit_test_scsi_open: "
692 "Test 3: NDMP_DEVICE_OPENED_ERR start\n");
693 inf_scsi_open(NDMP_DEVICE_OPENED_ERR, device, logfile, &conn);
694 (void) ndmp_dprintf(logfile,
695 "unit_test_scsi_open: "
696 "Test 3: NDMP_DEVICE_OPENED_ERR end\n");
697
698 /* Test 4: NDMP_NO_DEVICE_ERR */
699 (void) ndmp_dprintf(logfile,
700 "unit_test_scsi_open: "
701 "Test 4: NDMP_NO_DEVICE_ERR start\n");
702 inf_scsi_open(NDMP_NO_DEVICE_ERR, device, logfile, &conn);
703 (void) ndmp_dprintf(logfile,
704 "unit_test_scsi_open: "
705 "Test 4: NDMP_NO_DEVICE_ERR end\n");
706
707 /* Test 5: NDMP_DEVICE_BUSY_ERR */
708 (void) ndmp_dprintf(logfile,
709 "unit_test_scsi_open: "
710 "Test 5: NDMP_DEVICE_BUSY_ERR start\n");
711 inf_scsi_open(NDMP_DEVICE_BUSY_ERR, device, logfile, &conn);
712 (void) ndmp_dprintf(logfile,
713 "unit_test_scsi_open: "
714 "Test 5: NDMP_DEVICE_BUSY_ERR end\n");
715
716 close_connection(&conn, logfile);
717
718 return (1);
719 }
720
721 /*
722 * NDMP_SCSI_EXECUTE_CDB
723 */
724 int
725 unit_test_scsi_execute_cdb(host_info * auth, char *dev, FILE * logfile)
726 {
727 conn_handle conn;
728 char *cdb = "INQUIRY";
729
730 /* Test 1: NDMP_NOT_AUTHORIZED_ERR */
731 (void) ndmp_dprintf(logfile,
732 "unit_test_scsi_execute_cdb: "
733 "Test 1: NDMP_NOT_AUTHORIZED_ERR start\n");
734 strcpy(auth->password, "admn");
735 (void) open_connection(auth, &conn, logfile);
736 inf_scsi_execute_cdb(NDMP_NOT_AUTHORIZED_ERR, cdb, dev, logfile, &conn);
737 close_connection(&conn, logfile);
738 strcpy(auth->password, "admin");
739 (void) ndmp_dprintf(logfile,
740 "unit_test_scsi_execute_cdb: "
741 "Test 1: NDMP_NOT_AUTHORIZED_ERR end\n");
742
743 (void) open_connection(auth, &conn, logfile);
744
745 /* Test 2: NDMP_NO_ERR */
746 (void) ndmp_dprintf(logfile,
747 "unit_test_scsi_execute_cdb: "
748 "Test 2: NDMP_NO_ERR start\n");
749 inf_scsi_execute_cdb(NDMP_NO_ERR, cdb, dev, logfile, &conn);
750 (void) ndmp_dprintf(logfile,
751 "unit_test_scsi_execute_cdb: "
752 "Test 2: NDMP_NO_ERR end\n");
753
754 /* Test 3: NDMP_DEV_NOT_OPEN_ERR */
755 (void) ndmp_dprintf(logfile,
756 "unit_test_scsi_execute_cdb: "
757 "Test 3: NDMP_DEV_NOT_OPEN_ERR start\n");
758 inf_scsi_execute_cdb(NDMP_DEV_NOT_OPEN_ERR, cdb, dev, logfile, &conn);
759 (void) ndmp_dprintf(logfile,
760 "unit_test_scsi_execute_cdb: "
761 "Test 3: NDMP_DEV_NOT_OPEN_ERR end\n");
762
763 /* Test 4: NDMP_ILLEGAL_ARGS_ERR */
764 (void) ndmp_dprintf(logfile,
765 "unit_test_scsi_execute_cdb: "
766 "Test 4: NDMP_ILLEGAL_ARGS start\n");
767 inf_scsi_execute_cdb(NDMP_ILLEGAL_ARGS_ERR, cdb, dev, logfile, &conn);
768 (void) ndmp_dprintf(logfile,
769 "unit_test_scsi_execute_cdb: "
770 "Test 4: NDMP_ILLEGAL_ARGS_ERR end\n");
771
772 /* Test 5: NDMP_TIMEOUT_ERR */
773 (void) ndmp_dprintf(logfile,
774 "unit_test_scsi_execute_cdb: "
775 "Test 5: NDMP_TIMEOUT_ERR start\n");
776 inf_scsi_execute_cdb(NDMP_TIMEOUT_ERR, cdb, dev, logfile, &conn);
777 (void) ndmp_dprintf(logfile,
778 "unit_test_scsi_execute_cdb: "
779 "Test 5: NDMP_TIMEOUT_ERR end\n");
780
781 close_connection(&conn, logfile);
782
783 return (1);
784 }
785
786 #ifdef UNIT_TEST_SCSI
787
788 int
789 main(int argc, char *argv[])
790 {
791 FILE *logfile = NULL;
792 host_info auth;
793 auth.ipAddr = strdup("10.12.178.122");
794 auth.userName = strdup("admin");
795 auth.password = strdup("admin");
796 auth.auth_type = NDMP_AUTH_TEXT;
797 char *device = "/dev/rmt/2n";
798
799 /* Open Log file */
800 logfile = fopen("unit_test_scsi.log", "w");
801 (void) ndmp_dprintf(logfile, "main: start\n");
802
803 /* unit test scsi open */
804 unit_test_scsi_open(&auth, device, logfile);
805 /* unit test scsi close */
806 unit_test_scsi_close(&auth, device, logfile);
807
808 /* unit test scsi get state */
809 unit_test_scsi_get_state(&auth, device, logfile);
810
811 /* unit test scsi reset device */
812 unit_test_scsi_reset_device(&auth, device, logfile);
813
814 /* unit test scsi execute cdb */
815 unit_test_scsi_execute_cdb(&auth, device, logfile);
816
817 (void) ndmp_dprintf(stdout, "main: end\n");
818 free(auth.ipAddr);
819 free(auth.userName);
820 free(auth.password);
821 fclose(logfile);
822 return (1);
823 }
824 #endif