1 /* $NetBSD: dnload.c,v 1.6 2008/04/28 20:24:16 martin Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/types.h>
38 #include <sys/ioctl.h>
39 #include <netisdn/i4b_ioctl.h>
43 download(fd
, controller
, filename
)
48 struct isdn_download_request dr
;
49 struct isdn_dr_prot prots
[4];
50 msg_ctrl_info_req_t info
;
56 memset(&info
, 0, sizeof info
);
57 info
.controller
= controller
;
58 if (ioctl(fd
, I4B_CTRL_INFO_REQ
, &info
) == -1) {
59 perror("ctrl info req");
62 if (strncmp(info
.devname
, "daic", 4) != 0) {
63 fprintf(stderr
, "this is not a Diehl active isdn card...\n");
66 if (strcmp(info
.devname
, "daic0 port0") == 0)
69 memset(&dr
, 0, sizeof dr
);
70 dr
.controller
= controller
;
71 dr
.numprotos
= num_ports
;
73 if (stat(filename
, &sb
)) {
77 f
= fopen(filename
, "r");
82 data
= (u_int8_t
*)malloc(sb
.st_size
);
84 fprintf(stderr
, "could not allocate memory for microcode!\n");
87 rlen
= fread(data
, 1, sb
.st_size
, f
);
88 if ((off_t
)rlen
!= sb
.st_size
) {
89 fprintf(stderr
, "error reading microcode, read %lu bytes: %s\n",
90 (unsigned long)rlen
, strerror(errno
));
94 for (i
= 0; i
< num_ports
; i
++) {
95 prots
[i
].bytecount
= sb
.st_size
;
96 prots
[i
].microcode
= data
;
98 if (ioctl(fd
, I4B_CTRL_DOWNLOAD
, &dr
) == -1) {
99 fprintf(stderr
, "downloading microcode to controller %d failed: %s\n",
100 controller
, strerror(errno
));
103 printf("download successful\n");