summaryrefslogtreecommitdiffstats
path: root/net/irda/ircomm/ircomm_event.c
blob: b172c65223282888e90c1a45cf24383e63c33d8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*********************************************************************
 *
 * Filename:      ircomm_event.c
 * Version:       1.0
 * Description:   IrCOMM layer state machine
 * Status:        Stable
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Sun Jun  6 20:33:11 1999
 * Modified at:   Sun Dec 12 13:44:32 1999
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 *
 *     Copyright (c) 1999 Dag Brattli, All Rights Reserved.
 *
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
 *     the License, or (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 ********************************************************************/

#include <linux/proc_fs.h>
#include <linux/init.h>

#include <net/irda/irda.h>
#include <net/irda/irlmp.h>
#include <net/irda/iriap.h>
#include <net/irda/irttp.h>
#include <net/irda/irias_object.h>

#include <net/irda/ircomm_core.h>
#include <net/irda/ircomm_event.h>

static int ircomm_state_idle(struct ircomm_cb *self, IRCOMM_EVENT event,
			     struct sk_buff *skb, struct ircomm_info *info);
static int ircomm_state_waiti(struct ircomm_cb *self, IRCOMM_EVENT event,
			      struct sk_buff *skb, struct ircomm_info *info);
static int ircomm_state_waitr(struct ircomm_cb *self, IRCOMM_EVENT event,
			      struct sk_buff *skb, struct ircomm_info *info);
static int ircomm_state_conn(struct ircomm_cb *self, IRCOMM_EVENT event,
			     struct sk_buff *skb, struct ircomm_info *info);

const char *const ircomm_state[] = {
	"IRCOMM_IDLE",
	"IRCOMM_WAITI",
	"IRCOMM_WAITR",
	"IRCOMM_CONN",
};

#ifdef CONFIG_IRDA_DEBUG
static const char *const ircomm_event[] = {
	"IRCOMM_CONNECT_REQUEST",
	"IRCOMM_CONNECT_RESPONSE",
	"IRCOMM_TTP_CONNECT_INDICATION",
	"IRCOMM_LMP_CONNECT_INDICATION",
	"IRCOMM_TTP_CONNECT_CONFIRM",
	"IRCOMM_LMP_CONNECT_CONFIRM",

	"IRCOMM_LMP_DISCONNECT_INDICATION",
	"IRCOMM_TTP_DISCONNECT_INDICATION",
	"IRCOMM_DISCONNECT_REQUEST",

	"IRCOMM_TTP_DATA_INDICATION",
	"IRCOMM_LMP_DATA_INDICATION",
	"IRCOMM_DATA_REQUEST",
	"IRCOMM_CONTROL_REQUEST",
	"IRCOMM_CONTROL_INDICATION",
};
#endif /* CONFIG_IRDA_DEBUG */

static int (*state[])(struct ircomm_cb *self, IRCOMM_EVENT event,
		      struct sk_buff *skb, struct ircomm_info *info) =
{
	ircomm_state_idle,
	ircomm_state_waiti,
	ircomm_state_waitr,
	ircomm_state_conn,
};

/*
 * Function ircomm_state_idle (self, event, skb)
 *
 *    IrCOMM is currently idle
 *
 */
static int ircomm_state_idle(struct ircomm_cb *self, IRCOMM_EVENT event,
			     struct sk_buff *skb, struct ircomm_info *info)
{
	int ret = 0;

	switch (event) {
	case IRCOMM_CONNECT_REQUEST:
		ircomm_next_state(self, IRCOMM_WAITI);
		ret = self->issue.connect_request(self, skb, info);
		break;
	case IRCOMM_TTP_CONNECT_INDICATION:
	case IRCOMM_LMP_CONNECT_INDICATION:
		ircomm_next_state(self, IRCOMM_WAITR);
		ircomm_connect_indication(self, skb, info);
		break;
	default:
		IRDA_DEBUG(4, "%s(), unknown event: %s\n", __func__ ,
			   ircomm_event[event]);
		ret = -EINVAL;
	}
	return ret;
}

/*
 * Function ircomm_state_waiti (self, event, skb)
 *
 *    The IrCOMM user has requested an IrCOMM connection to the remote
 *    device and is awaiting confirmation
 */
static int ircomm_state_waiti(struct ircomm_cb *self, IRCOMM_EVENT event,
			      struct sk_buff *skb, struct ircomm_info *info)
{
	int ret = 0;

	switch (event) {
	case IRCOMM_TTP_CONNECT_CONFIRM:
	case IRCOMM_LMP_CONNECT_CONFIRM:
		ircomm_next_state(self, IRCOMM_CONN);
		ircomm_connect_confirm(self, skb, info);
		break;
	case IRCOMM_TTP_DISCONNECT_INDICATION:
	case IRCOMM_LMP_DISCONNECT_INDICATION:
		ircomm_next_state(self, IRCOMM_IDLE);
		ircomm_disconnect_indication(self, skb, info);
		break;
	default:
		IRDA_DEBUG(0, "%s(), unknown event: %s\n", __func__ ,
			   ircomm_event[event]);
		ret = -EINVAL;
	}
	return ret;
}

/*
 * Function ircomm_state_waitr (self, event, skb)
 *
 *    IrCOMM has received an incoming connection request and is awaiting
 *    response from the user
 */
static int ircomm_state_waitr(struct ircomm_cb *self, IRCOMM_EVENT event,
			      struct sk_buff *skb, struct ircomm_info *info)
{
	int ret = 0;

	switch (event) {
	case IRCOMM_CONNECT_RESPONSE:
		ircomm_next_state(self, IRCOMM_CONN);
		ret = self->issue.connect_response(self, skb);
		break;
	case IRCOMM_DISCONNECT_REQUEST:
		ircomm_next_state(self, IRCOMM_IDLE);
		ret = self->issue.disconnect_request(self, skb, info);
		break;
	case IRCOMM_TTP_DISCONNECT_INDICATION:
	case IRCOMM_LMP_DISCONNECT_INDICATION:
		ircomm_next_state(self, IRCOMM_IDLE);
		ircomm_disconnect_indication(self, skb, info);
		break;
	default:
		IRDA_DEBUG(0, "%s(), unknown event = %s\n", __func__ ,
			   ircomm_event[event]);
		ret = -EINVAL;
	}
	return ret;
}

/*
 * Function ircomm_state_conn (self, event, skb)
 *
 *    IrCOMM is connected to the peer IrCOMM device
 *
 */
static int ircomm_state_conn(struct ircomm_cb *self, IRCOMM_EVENT event,
			     struct sk_buff *skb, struct ircomm_info *info)
{
	int ret = 0;

	switch (event) {
	case IRCOMM_DATA_REQUEST:
		ret = self->issue.data_request(self, skb, 0);
		break;
	case IRCOMM_TTP_DATA_INDICATION:
		ircomm_process_data(self, skb);
		break;
	case IRCOMM_LMP_DATA_INDICATION:
		ircomm_data_indication(self, skb);
		break;
	case IRCOMM_CONTROL_REQUEST:
		/* Just send a separate frame for now */
		ret = self->issue.data_request(self, skb, skb->len);
		break;
	case IRCOMM_TTP_DISCONNECT_INDICATION:
	case IRCOMM_LMP_DISCONNECT_INDICATION:
		ircomm_next_state(self, IRCOMM_IDLE);
		ircomm_disconnect_indication(self, skb, info);
		break;
	case IRCOMM_DISCONNECT_REQUEST:
		ircomm_next_state(self, IRCOMM_IDLE);
		ret = self->issue.disconnect_request(self, skb, info);
		break;
	default:
		IRDA_DEBUG(0, "%s(), unknown event = %s\n", __func__ ,
			   ircomm_event[event]);
		ret = -EINVAL;
	}
	return ret;
}

/*
 * Function ircomm_do_event (self, event, skb)
 *
 *    Process event
 *
 */
int ircomm_do_event(struct ircomm_cb *self, IRCOMM_EVENT event,
		    struct sk_buff *skb, struct ircomm_info *info)
{
	IRDA_DEBUG(4, "%s: state=%s, event=%s\n", __func__ ,
		   ircomm_state[self->state], ircomm_event[event]);

	return (*state[self->state])(self, event, skb, info);
}

/*
 * Function ircomm_next_state (self, state)
 *
 *    Switch state
 *
 */
void ircomm_next_state(struct ircomm_cb *self, IRCOMM_STATE state)
{
	self->state = state;

	IRDA_DEBUG(4, "%s: next state=%s, service type=%d\n", __func__ ,
		   ircomm_state[self->state], self->service_type);
}
OpenPOWER on IntegriCloud