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
|
/*
* s_common.c - common utilities for Solaris PPP
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies.
*
* SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define RCSID "$Id: s_common.c,v 1.0 2000/05/08 01:10:12 masputra Exp $"
#include <sys/types.h>
#include <sys/debug.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/errno.h>
#include <sys/ioccom.h>
#include <sys/cmn_err.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/strsun.h>
#include <net/ppp_defs.h>
#include <net/pppio.h>
#include "s_common.h"
/*
* putctl4()
*
* Description:
* Create and send a 4-byte message.
*/
int
putctl4(queue_t *q, uchar_t type, uchar_t code, uint16_t val)
{
mblk_t *mp;
if ((mp = allocb(4, BPRI_HI)) == NULL) {
return (0);
}
MTYPE(mp) = type;
mp->b_wptr[0] = code;
((uint16_t *)mp->b_wptr)[1] = val;
mp->b_wptr += 4;
putnext(q, mp);
return (1);
}
/*
* putctl8()
*
* Description:
* Create and send a 8-byte message.
*/
int
putctl8(queue_t *q, uchar_t type, uchar_t code, uint32_t val)
{
mblk_t *mp;
if ((mp = allocb(8, BPRI_HI)) == NULL) {
return (0);
}
MTYPE(mp) = type;
mp->b_wptr[0] = code;
((uint32_t *)mp->b_wptr)[1] = val;
mp->b_wptr += 8;
putnext(q, mp);
return (1);
}
/*
* msg_byte()
*
* Description:
* Helper routine to return a specific byte off a data buffer.
*/
int
msg_byte(mblk_t *mp, unsigned int i)
{
while (mp != NULL) {
if (i < MBLKL(mp)) {
break;
}
i -= MBLKL(mp);
mp = mp->b_cont;
}
if (mp == NULL) {
return (-1);
}
return (mp->b_rptr[i]);
}
/*
* sppp_create_lsmsg()
*
* Description:
* Create a PPP link status message.
*/
mblk_t *
create_lsmsg(enum LSstat ls_type)
{
mblk_t *mp;
struct ppp_ls *plt;
if ((mp = allocb(sizeof (*plt), BPRI_HI)) == NULL) {
return (NULL);
}
/*
* Make sure that this message is a control message, and contains
* a notification that the link has been terminated.
*/
MTYPE(mp) = M_PROTO;
mp->b_wptr += sizeof (*plt);
plt = (struct ppp_ls *)mp->b_rptr;
plt->magic = PPPLSMAGIC;
plt->ppp_message = ls_type;
return (mp);
}
|