Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* $Id: capiutil.c,v 1.13.6.4 2001/09/23 22:24:33 kai Exp $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * CAPI 2.0 convert capi message to capi message struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * From CAPI 2.0 Development Kit AVM 1995 (msg.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Rewritten for Linux 1996 by Carsten Paeth <calle@calle.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This software may be used and distributed according to the terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * of the GNU General Public License, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/isdn/capiutil.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "kcapi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* from CAPI2.0 DDK AVM Berlin GmbH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int typ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	size_t off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) } _cdef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define _CBYTE	       1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define _CWORD	       2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define _CDWORD        3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define _CSTRUCT       4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define _CMSTRUCT      5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define _CEND	       6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static _cdef cdef[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/*00 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	{_CEND},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/*01 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	{_CEND},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/*02 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	{_CEND},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	/*03 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	{_CDWORD, offsetof(_cmsg, adr.adrController)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/*04 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	{_CMSTRUCT, offsetof(_cmsg, AdditionalInfo)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/*05 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	{_CSTRUCT, offsetof(_cmsg, B1configuration)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/*06 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	{_CWORD, offsetof(_cmsg, B1protocol)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/*07 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	{_CSTRUCT, offsetof(_cmsg, B2configuration)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/*08 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	{_CWORD, offsetof(_cmsg, B2protocol)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/*09 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{_CSTRUCT, offsetof(_cmsg, B3configuration)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/*0a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	{_CWORD, offsetof(_cmsg, B3protocol)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/*0b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	{_CSTRUCT, offsetof(_cmsg, BC)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	/*0c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{_CSTRUCT, offsetof(_cmsg, BChannelinformation)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/*0d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	{_CMSTRUCT, offsetof(_cmsg, BProtocol)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	/*0e */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	{_CSTRUCT, offsetof(_cmsg, CalledPartyNumber)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/*0f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	{_CSTRUCT, offsetof(_cmsg, CalledPartySubaddress)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/*10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	{_CSTRUCT, offsetof(_cmsg, CallingPartyNumber)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/*11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	{_CSTRUCT, offsetof(_cmsg, CallingPartySubaddress)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/*12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	{_CDWORD, offsetof(_cmsg, CIPmask)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/*13 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	{_CDWORD, offsetof(_cmsg, CIPmask2)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/*14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	{_CWORD, offsetof(_cmsg, CIPValue)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/*15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	{_CDWORD, offsetof(_cmsg, Class)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/*16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	{_CSTRUCT, offsetof(_cmsg, ConnectedNumber)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/*17 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	{_CSTRUCT, offsetof(_cmsg, ConnectedSubaddress)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/*18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	{_CDWORD, offsetof(_cmsg, Data)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/*19 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	{_CWORD, offsetof(_cmsg, DataHandle)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/*1a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	{_CWORD, offsetof(_cmsg, DataLength)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/*1b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	{_CSTRUCT, offsetof(_cmsg, FacilityConfirmationParameter)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	/*1c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	{_CSTRUCT, offsetof(_cmsg, Facilitydataarray)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/*1d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	{_CSTRUCT, offsetof(_cmsg, FacilityIndicationParameter)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/*1e */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	{_CSTRUCT, offsetof(_cmsg, FacilityRequestParameter)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/*1f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	{_CWORD, offsetof(_cmsg, FacilitySelector)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/*20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	{_CWORD, offsetof(_cmsg, Flags)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/*21 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	{_CDWORD, offsetof(_cmsg, Function)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/*22 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	{_CSTRUCT, offsetof(_cmsg, HLC)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/*23 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	{_CWORD, offsetof(_cmsg, Info)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*24 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	{_CSTRUCT, offsetof(_cmsg, InfoElement)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/*25 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	{_CDWORD, offsetof(_cmsg, InfoMask)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/*26 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	{_CWORD, offsetof(_cmsg, InfoNumber)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/*27 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	{_CSTRUCT, offsetof(_cmsg, Keypadfacility)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	/*28 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	{_CSTRUCT, offsetof(_cmsg, LLC)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/*29 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	{_CSTRUCT, offsetof(_cmsg, ManuData)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/*2a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	{_CDWORD, offsetof(_cmsg, ManuID)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/*2b */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	{_CSTRUCT, offsetof(_cmsg, NCPI)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/*2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	{_CWORD, offsetof(_cmsg, Reason)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/*2d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	{_CWORD, offsetof(_cmsg, Reason_B3)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/*2e */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	{_CWORD, offsetof(_cmsg, Reject)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/*2f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	{_CSTRUCT, offsetof(_cmsg, Useruserdata)}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static unsigned char *cpars[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* ALERT_REQ */ [0x01] = "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* CONNECT_REQ */ [0x02] = "\x03\x14\x0e\x10\x0f\x11\x0d\x06\x08\x0a\x05\x07\x09\x01\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* DISCONNECT_REQ */ [0x04] = "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/* LISTEN_REQ */ [0x05] = "\x03\x25\x12\x13\x10\x11\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/* INFO_REQ */ [0x08] = "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* FACILITY_REQ */ [0x09] = "\x03\x1f\x1e\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/* SELECT_B_PROTOCOL_REQ */ [0x0a] = "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/* CONNECT_B3_REQ */ [0x0b] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* DISCONNECT_B3_REQ */ [0x0d] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* DATA_B3_REQ */ [0x0f] = "\x03\x18\x1a\x19\x20\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* RESET_B3_REQ */ [0x10] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* ALERT_CONF */ [0x13] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* CONNECT_CONF */ [0x14] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* DISCONNECT_CONF */ [0x16] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* LISTEN_CONF */ [0x17] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* MANUFACTURER_REQ */ [0x18] = "\x03\x2a\x15\x21\x29\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* INFO_CONF */ [0x1a] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/* FACILITY_CONF */ [0x1b] = "\x03\x23\x1f\x1b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	/* SELECT_B_PROTOCOL_CONF */ [0x1c] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* CONNECT_B3_CONF */ [0x1d] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* DISCONNECT_B3_CONF */ [0x1f] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* DATA_B3_CONF */ [0x21] = "\x03\x19\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	/* RESET_B3_CONF */ [0x22] = "\x03\x23\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* CONNECT_IND */ [0x26] = "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* CONNECT_ACTIVE_IND */ [0x27] = "\x03\x16\x17\x28\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* DISCONNECT_IND */ [0x28] = "\x03\x2c\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	/* MANUFACTURER_CONF */ [0x2a] = "\x03\x2a\x15\x21\x29\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/* INFO_IND */ [0x2c] = "\x03\x26\x24\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* FACILITY_IND */ [0x2d] = "\x03\x1f\x1d\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/* CONNECT_B3_IND */ [0x2f] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* CONNECT_B3_ACTIVE_IND */ [0x30] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* DISCONNECT_B3_IND */ [0x31] = "\x03\x2d\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* DATA_B3_IND */ [0x33] = "\x03\x18\x1a\x19\x20\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* RESET_B3_IND */ [0x34] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* CONNECT_B3_T90_ACTIVE_IND */ [0x35] = "\x03\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	/* CONNECT_RESP */ [0x38] = "\x03\x2e\x0d\x06\x08\x0a\x05\x07\x09\x01\x16\x17\x28\x04\x0c\x27\x2f\x1c\x01\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/* CONNECT_ACTIVE_RESP */ [0x39] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* DISCONNECT_RESP */ [0x3a] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* MANUFACTURER_IND */ [0x3c] = "\x03\x2a\x15\x21\x29\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/* INFO_RESP */ [0x3e] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* FACILITY_RESP */ [0x3f] = "\x03\x1f\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	/* CONNECT_B3_RESP */ [0x41] = "\x03\x2e\x2b\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* CONNECT_B3_ACTIVE_RESP */ [0x42] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/* DISCONNECT_B3_RESP */ [0x43] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* DATA_B3_RESP */ [0x45] = "\x03\x19\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	/* RESET_B3_RESP */ [0x46] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	/* CONNECT_B3_T90_ACTIVE_RESP */ [0x47] = "\x03\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	/* MANUFACTURER_RESP */ [0x4e] = "\x03\x2a\x15\x21\x29\x01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define byteTLcpy(x, y)         *(u8 *)(x) = *(u8 *)(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define wordTLcpy(x, y)         *(u16 *)(x) = *(u16 *)(y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define dwordTLcpy(x, y)        memcpy(x, y, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define structTLcpy(x, y, l)    memcpy(x, y, l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define structTLcpyovl(x, y, l) memmove(x, y, l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define byteTRcpy(x, y)         *(u8 *)(y) = *(u8 *)(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define wordTRcpy(x, y)         *(u16 *)(y) = *(u16 *)(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define dwordTRcpy(x, y)        memcpy(y, x, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define structTRcpy(x, y, l)    memcpy(y, x, l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define structTRcpyovl(x, y, l) memmove(y, x, l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static unsigned command_2_index(u8 c, u8 sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (c & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		c = 0x9 + (c & 0x0f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	else if (c == 0x41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		c = 0x9 + 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (c > 0x18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		c = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return (sc & 3) * (0x9 + 0x9) + c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * capi_cmd2par() - find parameter string for CAPI 2.0 command/subcommand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * @cmd:	command number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * @subcmd:	subcommand number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * Return value: static string, NULL if command/subcommand unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static unsigned char *capi_cmd2par(u8 cmd, u8 subcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return cpars[command_2_index(cmd, subcmd)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define TYP (cdef[cmsg->par[cmsg->p]].typ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #define OFF (((u8 *)cmsg) + cdef[cmsg->par[cmsg->p]].off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static void jumpcstruct(_cmsg *cmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	unsigned layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	for (cmsg->p++, layer = 1; layer;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		/* $$$$$ assert (cmsg->p); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		cmsg->p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		switch (TYP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		case _CMSTRUCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			layer++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		case _CEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			layer--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static char *mnames[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	[0x01] = "ALERT_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	[0x02] = "CONNECT_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	[0x04] = "DISCONNECT_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	[0x05] = "LISTEN_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	[0x08] = "INFO_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	[0x09] = "FACILITY_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	[0x0a] = "SELECT_B_PROTOCOL_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	[0x0b] = "CONNECT_B3_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	[0x0d] = "DISCONNECT_B3_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	[0x0f] = "DATA_B3_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	[0x10] = "RESET_B3_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	[0x13] = "ALERT_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	[0x14] = "CONNECT_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	[0x16] = "DISCONNECT_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	[0x17] = "LISTEN_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	[0x18] = "MANUFACTURER_REQ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	[0x1a] = "INFO_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	[0x1b] = "FACILITY_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	[0x1c] = "SELECT_B_PROTOCOL_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	[0x1d] = "CONNECT_B3_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	[0x1f] = "DISCONNECT_B3_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	[0x21] = "DATA_B3_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	[0x22] = "RESET_B3_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	[0x26] = "CONNECT_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	[0x27] = "CONNECT_ACTIVE_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	[0x28] = "DISCONNECT_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	[0x2a] = "MANUFACTURER_CONF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	[0x2c] = "INFO_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	[0x2d] = "FACILITY_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	[0x2f] = "CONNECT_B3_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	[0x30] = "CONNECT_B3_ACTIVE_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	[0x31] = "DISCONNECT_B3_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	[0x33] = "DATA_B3_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	[0x34] = "RESET_B3_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	[0x35] = "CONNECT_B3_T90_ACTIVE_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	[0x38] = "CONNECT_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	[0x39] = "CONNECT_ACTIVE_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	[0x3a] = "DISCONNECT_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	[0x3c] = "MANUFACTURER_IND",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	[0x3e] = "INFO_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	[0x3f] = "FACILITY_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	[0x41] = "CONNECT_B3_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	[0x42] = "CONNECT_B3_ACTIVE_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	[0x43] = "DISCONNECT_B3_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	[0x45] = "DATA_B3_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	[0x46] = "RESET_B3_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	[0x47] = "CONNECT_B3_T90_ACTIVE_RESP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	[0x4e] = "MANUFACTURER_RESP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * capi_cmd2str() - convert CAPI 2.0 command/subcommand number to name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * @cmd:	command number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * @subcmd:	subcommand number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * Return value: static string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) char *capi_cmd2str(u8 cmd, u8 subcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	char *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	result = mnames[command_2_index(cmd, subcmd)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (result == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		result = "INVALID_COMMAND";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #ifdef CONFIG_CAPI_TRACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static char *pnames[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	/*00 */ NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	/*01 */ NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/*02 */ NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/*03 */ "Controller/PLCI/NCCI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	/*04 */ "AdditionalInfo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	/*05 */ "B1configuration",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	/*06 */ "B1protocol",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	/*07 */ "B2configuration",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/*08 */ "B2protocol",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/*09 */ "B3configuration",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/*0a */ "B3protocol",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/*0b */ "BC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/*0c */ "BChannelinformation",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/*0d */ "BProtocol",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	/*0e */ "CalledPartyNumber",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	/*0f */ "CalledPartySubaddress",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/*10 */ "CallingPartyNumber",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	/*11 */ "CallingPartySubaddress",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/*12 */ "CIPmask",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	/*13 */ "CIPmask2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	/*14 */ "CIPValue",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	/*15 */ "Class",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	/*16 */ "ConnectedNumber",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	/*17 */ "ConnectedSubaddress",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	/*18 */ "Data32",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	/*19 */ "DataHandle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	/*1a */ "DataLength",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/*1b */ "FacilityConfirmationParameter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	/*1c */ "Facilitydataarray",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	/*1d */ "FacilityIndicationParameter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	/*1e */ "FacilityRequestParameter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	/*1f */ "FacilitySelector",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	/*20 */ "Flags",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	/*21 */ "Function",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	/*22 */ "HLC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	/*23 */ "Info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/*24 */ "InfoElement",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/*25 */ "InfoMask",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	/*26 */ "InfoNumber",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	/*27 */ "Keypadfacility",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	/*28 */ "LLC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/*29 */ "ManuData",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/*2a */ "ManuID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	/*2b */ "NCPI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	/*2c */ "Reason",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/*2d */ "Reason_B3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	/*2e */ "Reject",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	/*2f */ "Useruserdata"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static _cdebbuf *bufprint(_cdebbuf *cdb, char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	va_list f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	size_t n, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	if (!cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	va_start(f, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	r = cdb->size - cdb->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	n = vsnprintf(cdb->p, r, fmt, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	va_end(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (n >= r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		/* truncated, need bigger buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		size_t ns = 2 * cdb->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		u_char *nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		while ((ns - cdb->pos) <= n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			ns *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		nb = kmalloc(ns, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		if (!nb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			cdebbuf_free(cdb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		memcpy(nb, cdb->buf, cdb->pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		kfree(cdb->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		nb[cdb->pos] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		cdb->buf = nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		cdb->p = cdb->buf + cdb->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		cdb->size = ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		va_start(f, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		r = cdb->size - cdb->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		n = vsnprintf(cdb->p, r, fmt, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		va_end(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	cdb->p += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	cdb->pos += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static _cdebbuf *printstructlen(_cdebbuf *cdb, u8 *m, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	unsigned hex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (!cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	for (; len; len--, m++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		if (isalnum(*m) || *m == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			if (hex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 				cdb = bufprint(cdb, ">");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			cdb = bufprint(cdb, "%c", *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			hex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			if (!hex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 				cdb = bufprint(cdb, "<%02x", *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 				cdb = bufprint(cdb, " %02x", *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			hex = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (hex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		cdb = bufprint(cdb, ">");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static _cdebbuf *printstruct(_cdebbuf *cdb, u8 *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	unsigned len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (m[0] != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		len = m[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		m += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		len = ((u16 *) (m + 1))[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		m += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	cdb = printstructlen(cdb, m, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	return cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #define NAME (pnames[cmsg->par[cmsg->p]])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static _cdebbuf *protocol_message_2_pars(_cdebbuf *cdb, _cmsg *cmsg, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (!cmsg->par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return NULL;	/* invalid command/subcommand */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	for (; TYP != _CEND; cmsg->p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		int slen = 29 + 3 - level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		if (!cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		cdb = bufprint(cdb, "  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		for (i = 0; i < level - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			cdb = bufprint(cdb, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		switch (TYP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		case _CBYTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			cdb = bufprint(cdb, "%-*s = 0x%x\n", slen, NAME, *(u8 *) (cmsg->m + cmsg->l));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			cmsg->l++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		case _CWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			cdb = bufprint(cdb, "%-*s = 0x%x\n", slen, NAME, *(u16 *) (cmsg->m + cmsg->l));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			cmsg->l += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		case _CDWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			cdb = bufprint(cdb, "%-*s = 0x%lx\n", slen, NAME, *(u32 *) (cmsg->m + cmsg->l));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			cmsg->l += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		case _CSTRUCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			cdb = bufprint(cdb, "%-*s = ", slen, NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			if (cmsg->m[cmsg->l] == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 				cdb = bufprint(cdb, "default");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 				cdb = printstruct(cdb, cmsg->m + cmsg->l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			cdb = bufprint(cdb, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			if (cmsg->m[cmsg->l] != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 				cmsg->l += 1 + cmsg->m[cmsg->l];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 				cmsg->l += 3 + *(u16 *) (cmsg->m + cmsg->l + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		case _CMSTRUCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /*----- Metastruktur 0 -----*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			if (cmsg->m[cmsg->l] == '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 				cdb = bufprint(cdb, "%-*s = default\n", slen, NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 				cmsg->l++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 				jumpcstruct(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 				char *name = NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 				unsigned _l = cmsg->l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 				cdb = bufprint(cdb, "%-*s\n", slen, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 				cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 				cmsg->p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 				cdb = protocol_message_2_pars(cdb, cmsg, level + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	return cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /*-------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) static _cdebbuf *g_debbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static u_long g_debbuf_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static _cmsg *g_cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static _cdebbuf *cdebbuf_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	_cdebbuf *cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (likely(!test_and_set_bit(1, &g_debbuf_lock))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		cdb = g_debbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		goto init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		cdb = kmalloc(sizeof(_cdebbuf), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (!cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	cdb->buf = kmalloc(CDEBUG_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	if (!cdb->buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		kfree(cdb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	cdb->size = CDEBUG_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	cdb->buf[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	cdb->p = cdb->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	cdb->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	return cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)  * cdebbuf_free() - free CAPI debug buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)  * @cdb:	buffer to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) void cdebbuf_free(_cdebbuf *cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (likely(cdb == g_debbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		test_and_clear_bit(1, &g_debbuf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	if (likely(cdb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		kfree(cdb->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	kfree(cdb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)  * capi_message2str() - format CAPI 2.0 message for printing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)  * @msg:	CAPI 2.0 message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)  * Allocates a CAPI debug buffer and fills it with a printable representation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)  * of the CAPI 2.0 message in @msg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)  * Return value: allocated debug buffer, NULL on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)  * The returned buffer should be freed by a call to cdebbuf_free() after use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) _cdebbuf *capi_message2str(u8 *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	_cdebbuf *cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	_cmsg	*cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	cdb = cdebbuf_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	if (unlikely(!cdb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	if (likely(cdb == g_debbuf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		cmsg = g_cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		cmsg = kmalloc(sizeof(_cmsg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (unlikely(!cmsg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		cdebbuf_free(cdb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	cmsg->m = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	cmsg->l = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	cmsg->p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	byteTRcpy(cmsg->m + 4, &cmsg->Command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	byteTRcpy(cmsg->m + 5, &cmsg->Subcommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	cmsg->par = capi_cmd2par(cmsg->Command, cmsg->Subcommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	cdb = bufprint(cdb, "%-26s ID=%03d #0x%04x LEN=%04d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		       capi_cmd2str(cmsg->Command, cmsg->Subcommand),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		       ((unsigned short *) msg)[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		       ((unsigned short *) msg)[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		       ((unsigned short *) msg)[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	cdb = protocol_message_2_pars(cdb, cmsg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	if (unlikely(cmsg != g_cmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		kfree(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	return cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int __init cdebug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	g_cmsg = kmalloc(sizeof(_cmsg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	if (!g_cmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	g_debbuf = kmalloc(sizeof(_cdebbuf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	if (!g_debbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		kfree(g_cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	g_debbuf->buf = kmalloc(CDEBUG_GSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	if (!g_debbuf->buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		kfree(g_cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		kfree(g_debbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	g_debbuf->size = CDEBUG_GSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	g_debbuf->buf[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	g_debbuf->p = g_debbuf->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	g_debbuf->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) void cdebug_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (g_debbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		kfree(g_debbuf->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	kfree(g_debbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	kfree(g_cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) #else /* !CONFIG_CAPI_TRACE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static _cdebbuf g_debbuf = {"CONFIG_CAPI_TRACE not enabled", NULL, 0, 0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) _cdebbuf *capi_message2str(u8 *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	return &g_debbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) _cdebbuf *capi_cmsg2str(_cmsg *cmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	return &g_debbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) void cdebbuf_free(_cdebbuf *cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) int __init cdebug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) void cdebug_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) #endif