~ubuntu-branches/ubuntu/jaunty/irda-utils/jaunty-proposed

« back to all changes in this revision

Viewing changes to irdadump/ircomm.c

  • Committer: Bazaar Package Importer
  • Author(s): Sivan Greenberg
  • Date: 2006-12-07 18:32:56 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061207183256-tmlir0kv8t5vavnd
Tags: 0.9.18-5ubuntu1
* Merged with Debian unstable.
Remaining changes:
* findchip/smc.c,
  findchip/nsc.c,
  findchip/winbond.c:
  + Include sys/io.h instead of asm/io.h to fix FTBFS on i386
* debian/control,
  debian/irda-utils.init:
  + read -d doesn't work with dash. Run with bash and depend on it.
    Thanks to Alexander Schremmer for noticing.
* Remove stop script symlinks from rc0 and rc6.
* Autoconfiguration support (Debian #324404)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************
 
2
 *                
 
3
 * Filename:      ircomm.c
 
4
 * Version:       
 
5
 * Description:   
 
6
 * Status:        Experimental.
 
7
 * Author:        Dag Brattli <dagb@cs.uit.no>
 
8
 * Created at:    Sun Jun  6 13:40:30 1999
 
9
 * Modified at:   Fri Jun 11 10:47:08 1999
 
10
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 
11
 * 
 
12
 *     Copyright (c) 1999 Dag Brattli, All Rights Reserved.
 
13
 *     
 
14
 *     This program is free software; you can redistribute it and/or 
 
15
 *     modify it under the terms of the GNU General Public License as 
 
16
 *     published by the Free Software Foundation; either version 2 of 
 
17
 *     the License, or (at your option) any later version.
 
18
 * 
 
19
 *     This program is distributed in the hope that it will be useful,
 
20
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
22
 *     GNU General Public License for more details.
 
23
 *
 
24
 *     You should have received a copy of the GNU General Public License
 
25
 *     along with this program; if not, write to the Free Software
 
26
 *     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
27
 *     MA 02111-1307 USA
 
28
 *
 
29
 ********************************************************************/
 
30
 
 
31
#include "irdadump.h"
 
32
#include "ircomm.h"
 
33
 
 
34
#if 0
 
35
static char *ircomm_service_type[] =
 
36
{
 
37
        "N/A",
 
38
        "THREE_WIRE_RAW",
 
39
        "THREE_WIRE",
 
40
        "N/A",
 
41
        "NINE_WIRE",
 
42
        "N/A",
 
43
        "N/A",
 
44
        "N/A",
 
45
        "CENTRONICS"
 
46
};
 
47
 
 
48
static char *ircomm_port_type[] =
 
49
{
 
50
        "SERIAL",
 
51
        "PARALLEL"
 
52
};
 
53
#endif
 
54
 
 
55
static inline guint bytes_to_uint(unsigned char *buf)
 
56
{
 
57
        guint   ret;
 
58
        ret = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
 
59
        return(ret);
 
60
}
 
61
 
 
62
void parse_ircomm_params(guint8 clen, GNetBuf *buf, GString *str)
 
63
{
 
64
        guint pi, pl;
 
65
        guint pv_byte;
 
66
        guint n = 0;
 
67
 
 
68
        while (n < clen) {
 
69
                pi = buf->data[n] & 0x7f; /* Remove critical bit */
 
70
                pl = buf->data[n+1];
 
71
 
 
72
                switch (pi) {
 
73
                case SERVICE_TYPE:
 
74
                        pv_byte = buf->data[n+2];
 
75
                        g_string_sprintfa(str, "Service Type=");
 
76
                        if (pv_byte & IRCOMM_CENTRONICS)
 
77
                                g_string_sprintfa(str, "CENTRONICS ");
 
78
                        if (pv_byte & IRCOMM_9_WIRE)
 
79
                                g_string_sprintfa(str, "NINE_WIRE ");
 
80
                        if (pv_byte & IRCOMM_3_WIRE)
 
81
                                g_string_sprintfa(str, "THREE_WIRE ");
 
82
                        if (pv_byte & IRCOMM_3_WIRE_RAW)
 
83
                                g_string_sprintfa(str, "THREE_WIRE_RAW ");
 
84
                        if (!(pv_byte & IRCOMM_VALID_SERVICES))
 
85
                                g_string_sprintfa(str, "N/A ");
 
86
                        break;
 
87
                case PORT_TYPE:
 
88
                        pv_byte = buf->data[n+2];
 
89
                        g_string_sprintfa(str, "Port Type=");
 
90
                        if (pv_byte & IRCOMM_SERIAL)
 
91
                                g_string_sprintfa(str, "SERIAL ");
 
92
                        if (pv_byte & IRCOMM_PARALLEL)
 
93
                                g_string_sprintfa(str, "PARALLEL ");
 
94
                        if (!(pv_byte & IRCOMM_VALID_PORT_TYPES))
 
95
                                g_string_sprintfa(str, "N/A ");
 
96
                        break;
 
97
                case DATA_RATE:
 
98
                        pv_byte = bytes_to_uint(&(buf->data[n+2]));
 
99
                        g_string_sprintfa(str, "Data Rate=%d ", pv_byte);
 
100
                        break;
 
101
                case DATA_FORMAT:
 
102
                        g_string_sprintfa(str, "Data Format=%02x ",
 
103
                                          buf->data[n+2]);
 
104
                        break;
 
105
                case FLOW_CONTROL:
 
106
                        g_string_sprintfa(str, "Flow Control=%02x ",
 
107
                                          buf->data[n+2]);
 
108
                        break;
 
109
                case XON_XOFF_CHAR:
 
110
                        g_string_sprintfa(str, "XON/XOFF=%02x,%02x ",
 
111
                                          buf->data[n+2], buf->data[n+3]);
 
112
                        break;
 
113
                case DTELINE_STATE:
 
114
                        g_string_sprintfa(str, "DTEline State=%02x ",
 
115
                                          buf->data[n+2]);
 
116
                        break;
 
117
                default:
 
118
                        break;
 
119
                }
 
120
                n += pl+2;
 
121
        }
 
122
        g_netbuf_pull(buf, clen);
 
123
}
 
124
 
 
125
void parse_ircomm_connect(GNetBuf *buf, GString *str)
 
126
{
 
127
        parse_ircomm_ttp(buf, str);
 
128
}
 
129
 
 
130
void parse_ircomm_lmp(GNetBuf *buf, GString *str)
 
131
{
 
132
        /* Kill "unused" warning */
 
133
        buf = buf;
 
134
 
 
135
        g_string_append(str, "IrCOMM (IrLPT) ");
 
136
 
 
137
        return;
 
138
}
 
139
 
 
140
void parse_ircomm_ttp(GNetBuf *buf, GString *str)
 
141
{
 
142
        int     len;
 
143
        guint8 clen;
 
144
 
 
145
        /* Check for empty frames - Jean II */
 
146
        len = g_netbuf_get_len(buf);
 
147
        if(len == 0)
 
148
                return;
 
149
 
 
150
        clen = buf->data[0];
 
151
 
 
152
        g_netbuf_pull(buf, 1);
 
153
 
 
154
        if (clen) {
 
155
                g_string_append(str, "\n\tIrCOMM ");
 
156
                parse_ircomm_params(clen, buf, str);
 
157
        } else
 
158
                g_string_append(str, "IrCOMM ");
 
159
}