| /* |
| HCIDump - HCI packet analyzer |
| Copyright (C) 2000-2001 Maxim Krasnyansky <maxk@qualcomm.com> |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License version 2 as |
| published by the Free Software Foundation; |
| |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, |
| OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER |
| RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
| NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE |
| USE OR PERFORMANCE OF THIS SOFTWARE. |
| |
| ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, |
| TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. |
| */ |
| |
| /* |
| * $Id$ |
| */ |
| |
| /* Modes */ |
| enum { |
| PARSE, |
| READ, |
| WRITE |
| }; |
| |
| struct dump_hdr { |
| __u16 len; |
| __u8 in; |
| __u8 pad; |
| __u32 ts_sec; |
| __u32 ts_usec; |
| } __attribute__ ((packed)); |
| #define DUMP_HDR_SIZE (sizeof(struct dump_hdr)) |
| |
| #define SNAP_LEN HCI_MAX_FRAME_SIZE |
| |
| static inline int read_n(int fd, char *buf, int len) |
| { |
| register int t=0, w; |
| |
| while (len > 0) { |
| if ((w = read(fd, buf, len)) < 0) { |
| if( errno == EINTR || errno == EAGAIN ) |
| continue; |
| return -1; |
| } |
| if (!w) |
| return 0; |
| len -= w; buf += w; t += w; |
| } |
| return t; |
| } |
| |
| static inline int write_n(int fd, char *buf, int len) |
| { |
| register int t=0, w; |
| |
| while (len > 0) { |
| if ((w = write(fd, buf, len)) < 0) { |
| if( errno == EINTR || errno == EAGAIN ) |
| continue; |
| return -1; |
| } |
| if (!w) |
| return 0; |
| len -= w; buf += w; t += w; |
| } |
| return t; |
| } |