bt3cfw.c (122758) | bt3cfw.c (128079) |
---|---|
1/* 2 * bt3cfw.c 3 * 4 * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 12 unchanged lines hidden (view full) --- 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: bt3cfw.c,v 1.2 2003/05/21 22:40:29 max Exp $ | 1/* 2 * bt3cfw.c 3 * 4 * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 12 unchanged lines hidden (view full) --- 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: bt3cfw.c,v 1.2 2003/05/21 22:40:29 max Exp $ |
29 * $FreeBSD: head/usr.sbin/bluetooth/bt3cfw/bt3cfw.c 122758 2003-11-15 15:26:35Z harti $ | 29 * $FreeBSD: head/usr.sbin/bluetooth/bt3cfw/bt3cfw.c 128079 2004-04-09 23:58:53Z emax $ |
30 */ 31 32#include <sys/types.h> 33#include <errno.h> 34#include <netgraph.h> 35#include <netgraph/bluetooth/include/ng_bt3c.h> 36#include <stdarg.h> 37#include <stdio.h> --- 50 unchanged lines hidden (view full) --- 88 syslog(LOG_ERR, "Usage: %s -f FirmwareFile -n NodeName", BT3CFW_IDENT); 89 exit(255); 90} 91 92/* Main */ 93int 94main(int argc, char *argv[]) 95{ | 30 */ 31 32#include <sys/types.h> 33#include <errno.h> 34#include <netgraph.h> 35#include <netgraph/bluetooth/include/ng_bt3c.h> 36#include <stdarg.h> 37#include <stdio.h> --- 50 unchanged lines hidden (view full) --- 88 syslog(LOG_ERR, "Usage: %s -f FirmwareFile -n NodeName", BT3CFW_IDENT); 89 exit(255); 90} 91 92/* Main */ 93int 94main(int argc, char *argv[]) 95{ |
96 FILE *firmware_file = NULL; 97 char buffer[80], path[NG_PATHSIZ], 98 *firmware_filename = NULL; 99 u_int8_t *firmware = NULL; 100 int firmware_size, opt, cs, ds; | 96 FILE *firmware_file = NULL; 97 char buffer[80], path[NG_PATHSIZ], 98 *firmware_filename = NULL; 99 uint8_t *firmware = NULL; 100 int firmware_size, opt, cs, ds; |
101 102 memset(path, 0, sizeof(path)); 103 openlog(BT3CFW_IDENT, LOG_NDELAY|LOG_PID|LOG_PERROR, LOG_USER); 104 105 while ((opt = getopt(argc, argv, "f:hn:")) != -1) { 106 switch (opt) { 107 case 'f': 108 firmware_filename = optarg; --- 9 unchanged lines hidden (view full) --- 118 /* NOT REACHED */ 119 } 120 } 121 122 if (firmware_filename == NULL || path[0] == 0) 123 usage(); 124 /* NOT REACHED */ 125 | 101 102 memset(path, 0, sizeof(path)); 103 openlog(BT3CFW_IDENT, LOG_NDELAY|LOG_PID|LOG_PERROR, LOG_USER); 104 105 while ((opt = getopt(argc, argv, "f:hn:")) != -1) { 106 switch (opt) { 107 case 'f': 108 firmware_filename = optarg; --- 9 unchanged lines hidden (view full) --- 118 /* NOT REACHED */ 119 } 120 } 121 122 if (firmware_filename == NULL || path[0] == 0) 123 usage(); 124 /* NOT REACHED */ 125 |
126 firmware = (u_int8_t *) calloc(BT3CFW_MAX_FIRMWARE_SIZE, 127 sizeof(u_int8_t)); | 126 firmware = (uint8_t *) calloc(BT3CFW_MAX_FIRMWARE_SIZE, 127 sizeof(uint8_t)); |
128 if (firmware == NULL) { 129 syslog(LOG_ERR, "Could not allocate firmware buffer"); 130 exit(255); 131 } 132 133 if ((firmware_file = fopen(firmware_filename, "r")) == NULL) { 134 syslog(LOG_ERR, "Could not open BT3C firmware file %s. %s (%d)", 135 firmware_filename, strerror(errno), errno); --- 6 unchanged lines hidden (view full) --- 142 int i, size, address, cs, fcs; 143 144 size = hexa2int8(buffer + 2); 145 address = hexa2int32(buffer + 4); 146 fcs = hexa2int8(buffer + 2 + size * 2); 147 148 if (buffer[1] == '3') { 149 ng_bt3c_firmware_block_ep *block = NULL; | 128 if (firmware == NULL) { 129 syslog(LOG_ERR, "Could not allocate firmware buffer"); 130 exit(255); 131 } 132 133 if ((firmware_file = fopen(firmware_filename, "r")) == NULL) { 134 syslog(LOG_ERR, "Could not open BT3C firmware file %s. %s (%d)", 135 firmware_filename, strerror(errno), errno); --- 6 unchanged lines hidden (view full) --- 142 int i, size, address, cs, fcs; 143 144 size = hexa2int8(buffer + 2); 145 address = hexa2int32(buffer + 4); 146 fcs = hexa2int8(buffer + 2 + size * 2); 147 148 if (buffer[1] == '3') { 149 ng_bt3c_firmware_block_ep *block = NULL; |
150 u_int16_t *data = NULL; | 150 uint16_t *data = NULL; |
151 152 block = (ng_bt3c_firmware_block_ep *) 153 (firmware + firmware_size); 154 155 firmware_size += sizeof(*block); 156 if (firmware_size >= BT3CFW_MAX_FIRMWARE_SIZE) { 157 syslog(LOG_ERR, "Could not add new firmware " \ 158 "block. Firmware file %s is " \ --- 21 unchanged lines hidden (view full) --- 180 } 181 182 /* First part of the cheksum: size and address */ 183 cs = 0; 184 for (i = 0; i < 5; i++) 185 cs += hexa2int8(buffer + 2 + i * 2); 186 187 /* Data + second part of the cheksum: data */ | 151 152 block = (ng_bt3c_firmware_block_ep *) 153 (firmware + firmware_size); 154 155 firmware_size += sizeof(*block); 156 if (firmware_size >= BT3CFW_MAX_FIRMWARE_SIZE) { 157 syslog(LOG_ERR, "Could not add new firmware " \ 158 "block. Firmware file %s is " \ --- 21 unchanged lines hidden (view full) --- 180 } 181 182 /* First part of the cheksum: size and address */ 183 cs = 0; 184 for (i = 0; i < 5; i++) 185 cs += hexa2int8(buffer + 2 + i * 2); 186 187 /* Data + second part of the cheksum: data */ |
188 data = (u_int16_t *)(block + 1); | 188 data = (uint16_t *)(block + 1); |
189 for (i = 0; i < block->block_size; i++) { 190 data[i] = hexa2int16(buffer + (i * 4) + 12); 191 cs += (((data[i] & 0xff00) >> 8) & 0xff); 192 cs += (data[i] & 0x00ff); 193 } 194 } else 195 for (cs = 0, i = 0; i < size; i++) 196 cs += hexa2int8(buffer + 2 + i * 2); --- 31 unchanged lines hidden --- | 189 for (i = 0; i < block->block_size; i++) { 190 data[i] = hexa2int16(buffer + (i * 4) + 12); 191 cs += (((data[i] & 0xff00) >> 8) & 0xff); 192 cs += (data[i] & 0x00ff); 193 } 194 } else 195 for (cs = 0, i = 0; i < size; i++) 196 cs += hexa2int8(buffer + 2 + i * 2); --- 31 unchanged lines hidden --- |