1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * s_common.c - common utilities for Solaris PPP
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc.
5*7c478bd9Sstevel@tonic-gate * All rights reserved.
6*7c478bd9Sstevel@tonic-gate *
7*7c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software and its
8*7c478bd9Sstevel@tonic-gate * documentation is hereby granted, provided that the above copyright
9*7c478bd9Sstevel@tonic-gate * notice appears in all copies.
10*7c478bd9Sstevel@tonic-gate *
11*7c478bd9Sstevel@tonic-gate * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
12*7c478bd9Sstevel@tonic-gate * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13*7c478bd9Sstevel@tonic-gate * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14*7c478bd9Sstevel@tonic-gate * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
15*7c478bd9Sstevel@tonic-gate * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16*7c478bd9Sstevel@tonic-gate * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
17*7c478bd9Sstevel@tonic-gate */
18*7c478bd9Sstevel@tonic-gate
19*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
20*7c478bd9Sstevel@tonic-gate #define RCSID "$Id: s_common.c,v 1.0 2000/05/08 01:10:12 masputra Exp $"
21*7c478bd9Sstevel@tonic-gate
22*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
23*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
24*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
25*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
26*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
27*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
28*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
29*7c478bd9Sstevel@tonic-gate #include <sys/ioccom.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
34*7c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
35*7c478bd9Sstevel@tonic-gate #include <net/pppio.h>
36*7c478bd9Sstevel@tonic-gate #include "s_common.h"
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate * putctl4()
40*7c478bd9Sstevel@tonic-gate *
41*7c478bd9Sstevel@tonic-gate * Description:
42*7c478bd9Sstevel@tonic-gate * Create and send a 4-byte message.
43*7c478bd9Sstevel@tonic-gate */
44*7c478bd9Sstevel@tonic-gate int
putctl4(queue_t * q,uchar_t type,uchar_t code,uint16_t val)45*7c478bd9Sstevel@tonic-gate putctl4(queue_t *q, uchar_t type, uchar_t code, uint16_t val)
46*7c478bd9Sstevel@tonic-gate {
47*7c478bd9Sstevel@tonic-gate mblk_t *mp;
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate if ((mp = allocb(4, BPRI_HI)) == NULL) {
50*7c478bd9Sstevel@tonic-gate return (0);
51*7c478bd9Sstevel@tonic-gate }
52*7c478bd9Sstevel@tonic-gate MTYPE(mp) = type;
53*7c478bd9Sstevel@tonic-gate mp->b_wptr[0] = code;
54*7c478bd9Sstevel@tonic-gate ((uint16_t *)mp->b_wptr)[1] = val;
55*7c478bd9Sstevel@tonic-gate mp->b_wptr += 4;
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate putnext(q, mp);
58*7c478bd9Sstevel@tonic-gate return (1);
59*7c478bd9Sstevel@tonic-gate }
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate * putctl8()
63*7c478bd9Sstevel@tonic-gate *
64*7c478bd9Sstevel@tonic-gate * Description:
65*7c478bd9Sstevel@tonic-gate * Create and send a 8-byte message.
66*7c478bd9Sstevel@tonic-gate */
67*7c478bd9Sstevel@tonic-gate int
putctl8(queue_t * q,uchar_t type,uchar_t code,uint32_t val)68*7c478bd9Sstevel@tonic-gate putctl8(queue_t *q, uchar_t type, uchar_t code, uint32_t val)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate mblk_t *mp;
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate if ((mp = allocb(8, BPRI_HI)) == NULL) {
73*7c478bd9Sstevel@tonic-gate return (0);
74*7c478bd9Sstevel@tonic-gate }
75*7c478bd9Sstevel@tonic-gate MTYPE(mp) = type;
76*7c478bd9Sstevel@tonic-gate mp->b_wptr[0] = code;
77*7c478bd9Sstevel@tonic-gate ((uint32_t *)mp->b_wptr)[1] = val;
78*7c478bd9Sstevel@tonic-gate mp->b_wptr += 8;
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate putnext(q, mp);
81*7c478bd9Sstevel@tonic-gate return (1);
82*7c478bd9Sstevel@tonic-gate }
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate /*
85*7c478bd9Sstevel@tonic-gate * msg_byte()
86*7c478bd9Sstevel@tonic-gate *
87*7c478bd9Sstevel@tonic-gate * Description:
88*7c478bd9Sstevel@tonic-gate * Helper routine to return a specific byte off a data buffer.
89*7c478bd9Sstevel@tonic-gate */
90*7c478bd9Sstevel@tonic-gate int
msg_byte(mblk_t * mp,unsigned int i)91*7c478bd9Sstevel@tonic-gate msg_byte(mblk_t *mp, unsigned int i)
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate while (mp != NULL) {
94*7c478bd9Sstevel@tonic-gate if (i < MBLKL(mp)) {
95*7c478bd9Sstevel@tonic-gate break;
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate i -= MBLKL(mp);
98*7c478bd9Sstevel@tonic-gate mp = mp->b_cont;
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate if (mp == NULL) {
101*7c478bd9Sstevel@tonic-gate return (-1);
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate return (mp->b_rptr[i]);
104*7c478bd9Sstevel@tonic-gate }
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate /*
107*7c478bd9Sstevel@tonic-gate * sppp_create_lsmsg()
108*7c478bd9Sstevel@tonic-gate *
109*7c478bd9Sstevel@tonic-gate * Description:
110*7c478bd9Sstevel@tonic-gate * Create a PPP link status message.
111*7c478bd9Sstevel@tonic-gate */
112*7c478bd9Sstevel@tonic-gate mblk_t *
create_lsmsg(enum LSstat ls_type)113*7c478bd9Sstevel@tonic-gate create_lsmsg(enum LSstat ls_type)
114*7c478bd9Sstevel@tonic-gate {
115*7c478bd9Sstevel@tonic-gate mblk_t *mp;
116*7c478bd9Sstevel@tonic-gate struct ppp_ls *plt;
117*7c478bd9Sstevel@tonic-gate
118*7c478bd9Sstevel@tonic-gate if ((mp = allocb(sizeof (*plt), BPRI_HI)) == NULL) {
119*7c478bd9Sstevel@tonic-gate return (NULL);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate /*
122*7c478bd9Sstevel@tonic-gate * Make sure that this message is a control message, and contains
123*7c478bd9Sstevel@tonic-gate * a notification that the link has been terminated.
124*7c478bd9Sstevel@tonic-gate */
125*7c478bd9Sstevel@tonic-gate MTYPE(mp) = M_PROTO;
126*7c478bd9Sstevel@tonic-gate mp->b_wptr += sizeof (*plt);
127*7c478bd9Sstevel@tonic-gate plt = (struct ppp_ls *)mp->b_rptr;
128*7c478bd9Sstevel@tonic-gate plt->magic = PPPLSMAGIC;
129*7c478bd9Sstevel@tonic-gate plt->ppp_message = ls_type;
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate return (mp);
132*7c478bd9Sstevel@tonic-gate }
133