22 #include <linux/random.h>
34 #define TEI_ENTITY_ID 0xf
36 static struct Fsm teifsm;
46 #define TEI_STATE_COUNT (ST_TEI_IDVERIFY + 1)
48 static char *strTeiState[] =
65 #define TEI_EVENT_COUNT (EV_T202 + 1)
67 static char *strTeiEvent[] =
87 static struct PStack *
88 findtei(
struct PStack *
st,
int tei)
90 struct PStack *
ptr = *(st->l1.stlistp);
96 if (ptr->l2.tei == tei)
104 put_tei_msg(
struct PStack *st,
u_char m_id,
unsigned int ri,
u_char tei)
122 bp[4] = (tei << 1) | 1;
131 if (st->l2.tei != -1) {
132 st->ma.tei_m.printdebug(&st->ma.tei_m,
133 "assign request for already assigned tei %d",
137 st->ma.ri = random_ri();
139 st->ma.tei_m.printdebug(&st->ma.tei_m,
140 "assign request ri %d", st->ma.ri);
148 tei_id_assign(
struct FsmInst *fi,
int event,
void *arg)
150 struct PStack *ost, *st = fi->
userdata;
152 struct IsdnCardState *
cs;
155 ri = ((
unsigned int) skb->
data[1] << 8) + skb->
data[2];
156 tei = skb->
data[4] >> 1;
158 st->ma.tei_m.printdebug(&st->ma.tei_m,
159 "identity assign ri %d tei %d", ri, tei);
160 if ((ost = findtei(st, tei))) {
161 if (ri != ost->ma.ri) {
162 st->ma.tei_m.printdebug(&st->ma.tei_m,
163 "possible duplicate assignment tei %d", tei);
166 }
else if (ri == st->ma.ri) {
170 cs = (
struct IsdnCardState *) st->l1.hardware;
176 tei_id_test_dup(
struct FsmInst *fi,
int event,
void *arg)
178 struct PStack *ost, *st = fi->
userdata;
182 ri = ((
unsigned int) skb->
data[1] << 8) + skb->
data[2];
183 tei = skb->
data[4] >> 1;
185 st->ma.tei_m.printdebug(&st->ma.tei_m,
186 "foreign identity assign ri %d tei %d", ri, tei);
187 if ((ost = findtei(st, tei))) {
188 if (ri != ost->ma.ri) {
189 st->ma.tei_m.printdebug(&st->ma.tei_m,
190 "possible duplicate assignment tei %d", tei);
197 tei_id_denied(
struct FsmInst *fi,
int event,
void *arg)
203 ri = ((
unsigned int) skb->
data[1] << 8) + skb->
data[2];
204 tei = skb->
data[4] >> 1;
206 st->ma.tei_m.printdebug(&st->ma.tei_m,
207 "identity denied ri %d tei %d", ri, tei);
211 tei_id_chk_req(
struct FsmInst *fi,
int event,
void *arg)
217 tei = skb->
data[4] >> 1;
219 st->ma.tei_m.printdebug(&st->ma.tei_m,
220 "identity check req tei %d", tei);
221 if ((st->l2.tei != -1) && ((tei ==
GROUP_TEI) || (tei == st->l2.tei))) {
224 put_tei_msg(st,
ID_CHK_RES, random_ri(), st->l2.tei);
229 tei_id_remove(
struct FsmInst *fi,
int event,
void *arg)
233 struct IsdnCardState *
cs;
236 tei = skb->
data[4] >> 1;
238 st->ma.tei_m.printdebug(&st->ma.tei_m,
239 "identity remove tei %d", tei);
240 if ((st->l2.tei != -1) && ((tei ==
GROUP_TEI) || (tei == st->l2.tei))) {
244 cs = (
struct IsdnCardState *) st->l1.hardware;
250 tei_id_verify(
struct FsmInst *fi,
int event,
void *arg)
255 st->ma.tei_m.printdebug(&st->ma.tei_m,
256 "id verify request for tei %d", st->l2.tei);
257 put_tei_msg(st,
ID_VERIFY, 0, st->l2.tei);
264 tei_id_req_tout(
struct FsmInst *fi,
int event,
void *arg)
267 struct IsdnCardState *
cs;
270 st->ma.ri = random_ri();
272 st->ma.tei_m.printdebug(&st->ma.tei_m,
273 "assign req(%d) ri %d", 4 - st->ma.N202,
278 st->ma.tei_m.printdebug(&st->ma.tei_m,
"assign req failed");
280 cs = (
struct IsdnCardState *) st->l1.hardware;
287 tei_id_ver_tout(
struct FsmInst *fi,
int event,
void *arg)
290 struct IsdnCardState *
cs;
294 st->ma.tei_m.printdebug(&st->ma.tei_m,
295 "id verify req(%d) for tei %d",
296 3 - st->ma.N202, st->l2.tei);
297 put_tei_msg(st,
ID_VERIFY, 0, st->l2.tei);
300 st->ma.tei_m.printdebug(&st->ma.tei_m,
301 "verify req for tei %d failed", st->l2.tei);
303 cs = (
struct IsdnCardState *) st->l1.hardware;
310 tei_l1l2(
struct PStack *st,
int pr,
void *arg)
322 st->ma.tei_m.printdebug(&st->ma.tei_m,
323 "short mgr frame %ld/3", skb->
len);
326 st->ma.tei_m.printdebug(&st->ma.tei_m,
327 "wrong mgr sapi/tei %x/%x",
329 }
else if ((skb->
data[2] & 0xef) != UI) {
330 st->ma.tei_m.printdebug(&st->ma.tei_m,
331 "mgr frame is not ui %x", skb->
data[2]);
335 st->ma.tei_m.printdebug(&st->ma.tei_m,
336 "short mgr frame %ld/5", skb->
len);
339 st->ma.tei_m.printdebug(&st->ma.tei_m,
340 "tei handler wrong entity id %x",
353 st->ma.tei_m.printdebug(&st->ma.tei_m,
354 "tei handler wrong mt %x\n", mt);
359 st->ma.tei_m.printdebug(&st->ma.tei_m,
360 "tei handler wrong pr %x\n", pr);
366 tei_l2tei(
struct PStack *st,
int pr,
void *arg)
368 struct IsdnCardState *
cs;
373 st->ma.tei_m.printdebug(&st->ma.tei_m,
374 "fixed assign tei %d", st->l2.tei);
376 cs = (
struct IsdnCardState *) st->l1.hardware;
407 st->l2.l2tei = tei_l2tei;
409 st->l1.l1tei = tei_l1l2;
411 st->ma.tei_m.fsm = &teifsm;
413 st->ma.tei_m.debug = 1;
414 st->ma.tei_m.userdata =
st;
415 st->ma.tei_m.userint = 0;
416 st->ma.tei_m.printdebug = tei_debug;
428 struct PStack *st = cs->stlist;
456 teifsm.strEvent = strTeiEvent;
457 teifsm.strState = strTeiState;