[asterisk-commits] branch north/chan_skinny-fixup r23377 - /team/north/chan_skinny-fixup/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Apr 29 08:12:29 MST 2006


Author: north
Date: Sat Apr 29 10:12:28 2006
New Revision: 23377

URL: http://svn.digium.com/view/asterisk?rev=23377&view=rev
Log:
Finally have time to add my skinny changes...

Modified:
    team/north/chan_skinny-fixup/channels/chan_skinny.c

Modified: team/north/chan_skinny-fixup/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/north/chan_skinny-fixup/channels/chan_skinny.c?rev=23377&r1=23376&r2=23377&view=diff
==============================================================================
--- team/north/chan_skinny-fixup/channels/chan_skinny.c (original)
+++ team/north/chan_skinny-fixup/channels/chan_skinny.c Sat Apr 29 10:12:28 2006
@@ -87,11 +87,6 @@
 static char date_format[6] = "D-M-Y";
 static char version_id[16] = "P002F202";
 
-/* these should be in an include file, but dunno what to include */
-typedef unsigned char	UINT8;
-typedef unsigned short	UINT16;
-typedef unsigned int	UINT32;
-
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define letohl(x) (x)
 #define letohs(x) (x)
@@ -179,7 +174,16 @@
 #define BUTTON_TEMPLATE_REQ_MESSAGE 0x000E
 #define VERSION_REQ_MESSAGE 0x000F
 #define SERVER_REQUEST_MESSAGE 0x0012
+
 #define ALARM_MESSAGE 0x0020
+/* XXX We never actually use this.  Maybe in the future we can.
+   I only added it for testing. */
+typedef struct alarm_message {
+	uint32_t alarmSeverity;
+	char displayMessage[80];
+	uint32_t alarmParam1;
+	uint32_t alarmParam2;
+} alarm_message;
 
 #define OPEN_RECEIVE_CHANNEL_ACK_MESSAGE 0x0022
 typedef struct open_receive_channel_ack_message {
@@ -190,8 +194,18 @@
 } open_receive_channel_ack_message;
 
 #define SOFT_KEY_SET_REQ_MESSAGE 0x0025
+
+#define SOFT_KEY_EVENT_MESSAGE 0x0026
+typedef struct soft_key_event_message {
+	int softKeyEvent;
+	int instance;
+	int reference;
+} soft_key_event_message;
+
 #define UNREGISTER_MESSAGE 0x0027
 #define SOFT_KEY_TEMPLATE_REQ_MESSAGE 0x0028
+#define HEADSET_STATUS_MESSAGE 0x002B
+#define REGISTER_AVAILABLE_LINES_MESSAGE 0x002D
 
 #define REGISTER_ACK_MESSAGE 0x0081
 typedef struct register_ack_message {
@@ -225,6 +239,12 @@
 typedef struct set_speaker_message {
 	int mode;
 } set_speaker_message;
+
+/* XXX When do we need to use this? */
+#define SET_MICROPHONE_MESSAGE 0x0089
+typedef struct set_microphone_message {
+	int mode;
+} set_microphone_message;
 
 #define START_MEDIA_TRANSMISSION_MESSAGE 0x008A
 typedef struct media_qualifier {
@@ -272,7 +292,7 @@
 
 #define LINE_STAT_RES_MESSAGE 0x0092
 typedef struct line_stat_res_message {
-	int linenumber;
+	int lineNumber;
 	char lineDirNumber[24];
 	char lineDisplayName[42];
 	int space;
@@ -292,163 +312,60 @@
 } definetimedate_message;
 
 #define BUTTON_TEMPLATE_RES_MESSAGE 0x0097
-
 typedef struct buttondefinition {
-	UINT8 instanceNumber;
-	UINT8 buttonDefinition;
+	uint8_t instanceNumber;
+	uint8_t buttonDefinition;
 } button_definition;
 
-#define STIMULUS_REDIAL 	0x01
-#define STIMULUS_SPEEDDIAL 	0x02
-#define STIMULUS_HOLD 		0x03
-#define STIMULUS_TRANSFER 	0x04
-#define STIMULUS_FORWARDALL 	0x05
-#define STIMULUS_FORWARDBUSY 	0x06
-#define STIMULUS_FORWARDNOANSWER 0x07
-#define STIMULUS_DISPLAY 	0x08
-#define STIMULUS_LINE 		0x09
-#define STIMULUS_VOICEMAIL 	0x0F
-#define STIMULUS_AUTOANSWER 	0x11
-#define STIMULUS_CONFERENCE 	0x7D
-#define STIMULUS_CALLPARK 	0x7E
-#define STIMULUS_CALLPICKUP 	0x7F
-#define STIMULUS_NONE	 	0xFF
-
-button_definition button_def_30vip[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 2, STIMULUS_LINE },		/* Line 2 */
-	{ 3, STIMULUS_LINE },		/* Line 3 */
-	{ 4, STIMULUS_LINE },		/* Line 4 */
-	{ 1, STIMULUS_CALLPARK },	/* Call Park */
-	{ 0, STIMULUS_NONE },
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 3, STIMULUS_SPEEDDIAL },	/* Speeddial 3 */
-	{ 4, STIMULUS_SPEEDDIAL },	/* Speeddial 4 */
-	{ 5, STIMULUS_SPEEDDIAL },	/* Speeddial 5 */
-	{ 6, STIMULUS_SPEEDDIAL },	/* Speeddial 6 */
-	{ 1, STIMULUS_VOICEMAIL },	/* Voicemail */
-	{ 1, STIMULUS_FORWARDALL },	/* Forward All */
-	{ 1, STIMULUS_CONFERENCE },	/* Conference */
-	{ 0, STIMULUS_NONE },
-	{ 0, STIMULUS_NONE },
-	{ 0, STIMULUS_NONE },
-	{ 0, STIMULUS_NONE },
-	{ 0, STIMULUS_NONE },
-	{ 7, STIMULUS_SPEEDDIAL },	/* Speeddial 7 */
-	{ 8, STIMULUS_SPEEDDIAL },	/* Speeddial 8 */
-	{ 9, STIMULUS_SPEEDDIAL },	/* Speeddial 9 */
-	{ 10, STIMULUS_SPEEDDIAL }	/* Speeddial 10 */
-};
-
-button_definition button_def_12sp[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 3, STIMULUS_SPEEDDIAL },	/* Speeddial 3 */
-	{ 4, STIMULUS_SPEEDDIAL },	/* Speeddial 4 */
-	{ 1, STIMULUS_VOICEMAIL },	/* Voicemail */
-	{ 5, STIMULUS_SPEEDDIAL },	/* Speeddial 5 */
-	{ 6, STIMULUS_SPEEDDIAL },	/* Speeddial 6 */
-	{ 7, STIMULUS_SPEEDDIAL },	/* Speeddial 7 */
-	{ 8, STIMULUS_SPEEDDIAL },	/* Speeddial 8 */
-	{ 9, STIMULUS_SPEEDDIAL }	/* Speeddial 9 */
-};
-
-button_definition button_def_7902[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 1, STIMULUS_HOLD },		/* Hold */
-	{ 1, STIMULUS_TRANSFER },
-	{ 1, STIMULUS_DISPLAY },
-	{ 1, STIMULUS_VOICEMAIL },
-	{ 1, STIMULUS_CONFERENCE },
-	{ 1, STIMULUS_FORWARDALL },
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 3, STIMULUS_SPEEDDIAL },	/* Speeddial 3 */
-	{ 4, STIMULUS_SPEEDDIAL },	/* Speeddial 4 */
-	{ 1, STIMULUS_REDIAL }
-};
-
-button_definition button_def_7910[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 1, STIMULUS_HOLD },		/* Hold */
-	{ 1, STIMULUS_TRANSFER },
-	{ 1, STIMULUS_DISPLAY },
-	{ 1, STIMULUS_VOICEMAIL },
-	{ 1, STIMULUS_CONFERENCE },
-	{ 1, STIMULUS_FORWARDALL },
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 1, STIMULUS_REDIAL }
-};
-
-button_definition button_def_7920[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 2, STIMULUS_LINE },		/* Line 2 */
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 3, STIMULUS_SPEEDDIAL },	/* Speeddial 3 */
-	{ 4, STIMULUS_SPEEDDIAL }	/* Speeddial 4 */
-};
-
-button_definition button_def_7935[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 2, STIMULUS_LINE }		/* Line 2 */
-};
-
-button_definition button_def_7940[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 2, STIMULUS_LINE }		/* Line 2 */
-};
-
-button_definition button_def_7960[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 2, STIMULUS_LINE },		/* Line 2 */
-	{ 3, STIMULUS_LINE },		/* Line 3 */
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 3, STIMULUS_SPEEDDIAL }	/* Speeddial 3 */
-};
-
-button_definition button_def_7970[] = {
-	{ 1, STIMULUS_LINE },		/* Line 1 */
-	{ 2, STIMULUS_LINE },		/* Line 2 */
-	{ 3, STIMULUS_LINE },		/* Line 3 */
-	{ 1, STIMULUS_SPEEDDIAL },	/* Speeddial 1 */
-	{ 2, STIMULUS_SPEEDDIAL },	/* Speeddial 2 */
-	{ 3, STIMULUS_SPEEDDIAL },	/* Speeddial 3 */
-	{ 4, STIMULUS_SPEEDDIAL },	/* Speeddial 4 */
-	{ 5, STIMULUS_SPEEDDIAL }	/* Speeddial 5 */
-};
-
-button_definition button_def_none = { 0, STIMULUS_NONE };
-
-typedef struct button_defs {
-	char *type;
-	int num_buttons;
-	button_definition *button_def;
-} button_defs_t;
-
-button_defs_t button_defs[] = {
-	{ "12SP", 	12,	button_def_12sp }, /* First one is used if
-						      there's no match */
-	{ "30VIP", 	26,	button_def_30vip },
-	{ "7902",	12,	button_def_7902 },
-	{ "7910",	10,	button_def_7910 },
-	{ "7920",	6,	button_def_7920 },
-	{ "7935",	2,	button_def_7935 },
-	{ "7940",	2,	button_def_7940 },
-	{ "7960",	6,	button_def_7960 },
-	{ "7970",	8,	button_def_7970 },
-	{ NULL,		0,	NULL }
-};
+typedef struct buttondefinitiontemplate {
+	uint8_t buttonDefinition;
+	/* for now, anything between 0xB0 and 0xCF is custom */
+	/*int custom;*/
+} button_definition_template;
+
+#define STIMULUS_REDIAL			0x01
+#define STIMULUS_SPEEDDIAL		0x02
+#define STIMULUS_HOLD			0x03
+#define STIMULUS_TRANSFER		0x04
+#define STIMULUS_FORWARDALL		0x05
+#define STIMULUS_FORWARDBUSY		0x06
+#define STIMULUS_FORWARDNOANSWER	0x07
+#define STIMULUS_DISPLAY		0x08
+#define STIMULUS_LINE			0x09
+#define STIMULUS_VOICEMAIL		0x0F
+#define STIMULUS_AUTOANSWER		0x11
+#define STIMULUS_CONFERENCE		0x7D
+#define STIMULUS_CALLPARK		0x7E
+#define STIMULUS_CALLPICKUP		0x7F
+#define STIMULUS_NONE			0xFF
+
+/* Button types */
+#define BT_REDIAL			STIMULUS_REDIAL
+#define BT_SPEEDDIAL			STIMULUS_SPEEDDIAL
+#define BT_HOLD				STIMULUS_HOLD
+#define BT_TRANSFER			STIMULUS_TRANSFER
+#define BT_FORWARDALL			STIMULUS_FORWARDALL
+#define BT_FORWARDBUSY			STIMULUS_FORWARDBUSY
+#define BT_FORWARDNOANSWER		STIMULUS_FORWARDNOANSWER
+#define BT_DISPLAY 			STIMULUS_DISPLAY
+#define BT_LINE				STIMULUS_LINE
+#define BT_VOICEMAIL			STIMULUS_VOICEMAIL
+#define BT_AUTOANSWER			STIMULUS_AUTOANSWER
+#define BT_CONFERENCE			STIMULUS_CONFERENCE
+#define BT_CALLPARK			STIMULUS_CALLPARK
+#define BT_CALLPICKUP			STIMULUS_CALLPICKUP
+#define BT_NONE				0x00
+
+/* Custom button types - add our own between 0xB0 and 0xCF.
+   This may need to be revised in the future,
+   if stimuluses are ever added in this range. */
+#define BT_CUST_LINESPEEDDIAL		0xB0	/* line or speeddial */
+#define BT_CUST_HINT			0xB1	/* pipe dream */
 
 typedef struct button_template_res_message {
-	UINT32 buttonOffset;
-	UINT32 buttonCount;
-	UINT32 totalButtonCount;
+	uint32_t buttonOffset;
+	uint32_t buttonCount;
+	uint32_t totalButtonCount;
 	button_definition definition[42];
 } button_template_res_message;
 
@@ -506,83 +423,172 @@
 	int softKeyEvent;
 } soft_key_template_definition;
 
+#define KEYDEF_ONHOOK			0
+#define KEYDEF_CONNECTED		1
+#define KEYDEF_ONHOLD			2
+#define KEYDEF_RINGIN			3
+#define KEYDEF_OFFHOOK			4
+#define KEYDEF_CONNWITHTRANS		5
+#define KEYDEF_DADFD			6 /* Digits After Dialing First Digit */
+#define KEYDEF_CONNWITHCONF		7
+#define KEYDEF_RINGOUT			8
+#define KEYDEF_OFFHOOKWITHFEAT		9
+#define KEYDEF_UNKNOWN			10
+
+#define SOFTKEY_NONE			0x00
+#define SOFTKEY_REDIAL			0x01
+#define SOFTKEY_NEWCALL			0x02
+#define SOFTKEY_HOLD			0x03
+#define SOFTKEY_TRNSFER			0x04
+#define SOFTKEY_CFWDALL			0x05
+#define SOFTKEY_CFWDBUSY		0x06
+#define SOFTKEY_CFWDNOANSWER		0x07
+#define SOFTKEY_BKSPC			0x08
+#define SOFTKEY_ENDCALL			0x09
+#define SOFTKEY_RESUME			0x0A
+#define SOFTKEY_ANSWER			0x0B
+#define SOFTKEY_INFO			0x0C
+#define SOFTKEY_CONFRN			0x0D
+#define SOFTKEY_PARK			0x0E
+#define SOFTKEY_JOIN			0x0F
+#define SOFTKEY_MEETME			0x10
+#define SOFTKEY_PICKUP			0x11
+#define SOFTKEY_GPICKUP			0x12
+
 soft_key_template_definition soft_key_template_default[] = {
-	{ "Redial",	 	1 },
-	{ "NewCall",	 	2 },
-	{ "Hold",	 	3 },
-	{ "Trnsfer",	 	4 },
-	{ "CFwdAll",	 	5 },
-	{ "CFwdBusy",	 	6 },
-	{ "CFwdNoAnswer",	7 },
-	{ "<<",		 	8 },
-	{ "EndCall",	 	9 },
-	{ "Resume",		10 },
-	{ "Answer",		11 },
-	{ "Info",		12 },
-	{ "Confrn",		13 },
-	{ "Park",		14 },
-	{ "Join",		15 },
-	{ "MeetMe",		16 },
-	{ "PickUp",		17 },
-	{ "GPickUp",		18 },
+	{ "Redial",	 	0x01 },
+	{ "NewCall",	 	0x02 },
+	{ "Hold",	 	0x03 },
+	{ "Trnsfer",	 	0x04 },
+	{ "CFwdAll",	 	0x05 },
+	{ "CFwdBusy",	 	0x06 },
+	{ "CFwdNoAnswer",	0x07 },
+	{ "<<",		 	0x08 },
+	{ "EndCall",	 	0x09 },
+	{ "Resume",		0x0A },
+	{ "Answer",		0x0B },
+	{ "Info",		0x0C },
+	{ "Confrn",		0x0D },
+	{ "Park",		0x0E },
+	{ "Join",		0x0F },
+	{ "MeetMe",		0x10 },
+	{ "PickUp",		0x11 },
+	{ "GPickUp",		0x12 },
 };
 
-typedef struct soft_key_template {
+typedef struct soft_key_definitions {
+	const uint8_t mode;
+	const uint8_t *defaults;
+	const int count;
+} soft_key_definitions;
+
+static const uint8_t soft_key_default_onhook[] = {
+	SOFTKEY_REDIAL,
+	SOFTKEY_CFWDALL,
+	SOFTKEY_CFWDBUSY,
+	SOFTKEY_GPICKUP,
+	SOFTKEY_CONFRN,
+};
+
+static const uint8_t soft_key_default_connected[] = {
+	SOFTKEY_HOLD,
+	SOFTKEY_ENDCALL,
+	SOFTKEY_TRNSFER,
+	SOFTKEY_PARK,
+	SOFTKEY_CFWDALL,
+	SOFTKEY_CFWDBUSY,
+};
+
+static const uint8_t soft_key_default_onhold[] = {
+	SOFTKEY_RESUME,
+	SOFTKEY_NEWCALL,
+	SOFTKEY_ENDCALL,
+	SOFTKEY_TRNSFER,
+};
+
+static const uint8_t soft_key_default_ringin[] = {
+	SOFTKEY_ANSWER,
+	SOFTKEY_ENDCALL,
+	SOFTKEY_TRNSFER,
+};
+
+static const uint8_t soft_key_default_offhook[] = {
+	SOFTKEY_REDIAL,
+	SOFTKEY_ENDCALL,
+	SOFTKEY_CFWDALL,
+	SOFTKEY_CFWDBUSY,
+	SOFTKEY_GPICKUP,
+};
+
+static const uint8_t soft_key_default_connwithtrans[] = {
+	SOFTKEY_HOLD,
+	SOFTKEY_ENDCALL,
+	SOFTKEY_TRNSFER,
+	SOFTKEY_PARK,
+	SOFTKEY_CFWDALL,
+	SOFTKEY_CFWDBUSY,
+};
+
+static const uint8_t soft_key_default_dadfd[] = {
+	SOFTKEY_BKSPC,
+	SOFTKEY_ENDCALL,
+};
+
+static const uint8_t soft_key_default_connwithconf[] = {
+	SOFTKEY_NONE,
+};
+
+static const uint8_t soft_key_default_ringout[] = {
+	SOFTKEY_ENDCALL,
+	SOFTKEY_TRNSFER,
+	SOFTKEY_CFWDALL,
+	SOFTKEY_CFWDBUSY,
+};
+
+static const uint8_t soft_key_default_offhookwithfeat[] = {
+	SOFTKEY_REDIAL,
+	SOFTKEY_ENDCALL,
+};
+
+static const uint8_t soft_key_default_unknown[] = {
+	SOFTKEY_NONE,
+};
+
+static const soft_key_definitions soft_key_default_definitions[] = {
+	{KEYDEF_ONHOOK, soft_key_default_onhook, sizeof(soft_key_default_onhook) / sizeof(uint8_t)},
+	{KEYDEF_CONNECTED, soft_key_default_connected, sizeof(soft_key_default_connected) / sizeof(uint8_t)},
+	{KEYDEF_ONHOLD, soft_key_default_onhold, sizeof(soft_key_default_onhold) / sizeof(uint8_t)},
+	{KEYDEF_RINGIN, soft_key_default_ringin, sizeof(soft_key_default_ringin) / sizeof(uint8_t)},
+	{KEYDEF_OFFHOOK, soft_key_default_offhook, sizeof(soft_key_default_offhook) / sizeof(uint8_t)},
+	{KEYDEF_CONNWITHTRANS, soft_key_default_connwithtrans, sizeof(soft_key_default_connwithtrans) / sizeof(uint8_t)},
+	{KEYDEF_DADFD, soft_key_default_dadfd, sizeof(soft_key_default_dadfd) / sizeof(uint8_t)},
+	{KEYDEF_CONNWITHCONF, soft_key_default_connwithconf, sizeof(soft_key_default_connwithconf) / sizeof(uint8_t)},
+	{KEYDEF_RINGOUT, soft_key_default_ringout, sizeof(soft_key_default_ringout) / sizeof(uint8_t)},
+	{KEYDEF_OFFHOOKWITHFEAT, soft_key_default_offhookwithfeat, sizeof(soft_key_default_offhookwithfeat) / sizeof(uint8_t)},
+	{KEYDEF_UNKNOWN, soft_key_default_unknown, sizeof(soft_key_default_unknown) / sizeof(uint8_t)}
+};
+
+typedef struct soft_key_template_res_message {
 	int softKeyOffset;
 	int softKeyCount;
 	int totalSoftKeyCount;
 	soft_key_template_definition softKeyTemplateDefinition[32];
-} soft_key_template;
+} soft_key_template_res_message;
 
 #define SOFT_KEY_SET_RES_MESSAGE 0x0109
-static const char *soft_key_set_hack = {
-	"\x01\x02\x05\x03\x09\x0a\x0b\x10\x11\x12\x04\x0e\x0d\x00\x00\x00"
-	"\x2d\x01\x2e\x01\x31\x01\x2f\x01\x35\x01\x36\x01\x37\x01\x3c\x01"
-	"\x3d\x01\x3e\x01\x30\x01\x3a\x01\x39\x01\x00\x00\x00\x00\x00\x00"
-	"\x03\x09\x04\x0e\x0d\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x2f\x01\x35\x01\x30\x01\x3a\x01\x39\x01\x3f\x01\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x0a\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x36\x01\x2e\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x37\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x01\x09\x05\x10\x11\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x2d\x01\x35\x01\x31\x01\x3c\x01\x3d\x01\x3e\x01\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x09\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x35\x01\x30\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x08\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x34\x01\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x09\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x35\x01\x39\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x01\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x2d\x01\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x41\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-};
 
 typedef struct soft_key_set_definition {
-	UINT8 softKeyTemplateIndex[16];
-	UINT16 softKeyInfoIndex[16];
+	uint8_t softKeyTemplateIndex[16];
+	uint16_t softKeyInfoIndex[16];
 } soft_key_set_definition;
 
-typedef struct soft_key_sets {
-	UINT32 softKeySetOffset;
-	UINT32 softKeySetCount;
-	UINT32 totalSoftKeySetCount;
+typedef struct soft_key_set_res_message {
+	uint32_t softKeySetOffset;
+	uint32_t softKeySetCount;
+	uint32_t totalSoftKeySetCount;
 	soft_key_set_definition softKeySetDefinition[16];
-	UINT32 res;
-} soft_key_sets;
+	uint32_t res;
+} soft_key_set_res_message;
 
 #define SELECT_SOFT_KEYS_MESSAGE 0x0110
 typedef struct select_soft_keys_message {
@@ -625,47 +631,56 @@
 	int callReference;
 } dialed_number_message;
 
+typedef union {
+	alarm_message alarm;
+	speed_dial_stat_req_message speeddialreq;
+	register_message reg;
+	register_ack_message regack;
+	register_rej_message regrej;
+	capabilities_res_message caps;
+	version_res_message version;
+	button_template_res_message buttontemplate;
+	displaytext_message displaytext;
+	display_prompt_status_message displaypromptstatus;
+	definetimedate_message definetimedate;
+	start_tone_message starttone;
+	speed_dial_stat_res_message speeddial;
+	line_state_req_message line;
+	line_stat_res_message linestat;
+	soft_key_set_res_message softkeysets;
+	soft_key_template_res_message softkeytemplate;
+	server_res_message serverres;
+	set_lamp_message setlamp;
+	set_ringer_message setringer;
+	call_state_message callstate;
+	keypad_button_message keypad;
+	select_soft_keys_message selectsoftkey;
+	activate_call_plane_message activatecallplane;
+	stimulus_message stimulus;
+	set_speaker_message setspeaker;
+	call_info_message callinfo;
+	start_media_transmission_message startmedia;
+	stop_media_transmission_message stopmedia;
+	open_receive_channel_message openreceivechannel;
+	open_receive_channel_ack_message openreceivechannelack;
+	close_receive_channel_message closereceivechannel;
+	display_notify_message displaynotify;
+	dialed_number_message dialednumber;
+	soft_key_event_message softkeyeventmessage;
+} skinny_data;
+
 /* packet composition */
 typedef struct {
 	int len;
 	int res;
 	int e;
-	union {
-		speed_dial_stat_req_message speeddialreq;
-		register_message reg;
-		register_ack_message regack;
-		register_rej_message regrej;
-		capabilities_res_message caps;
-		version_res_message version;
-		button_template_res_message buttontemplate;
-		displaytext_message displaytext;
-		display_prompt_status_message displaypromptstatus;
-		definetimedate_message definetimedate;
-		start_tone_message starttone;
-		speed_dial_stat_res_message speeddial;
-		line_state_req_message line;
-		line_stat_res_message linestat;
-		soft_key_sets softkeysets;
-		soft_key_template softkeytemplate;
-		server_res_message serverres;
-		set_lamp_message setlamp;
-		set_ringer_message setringer;
-		call_state_message callstate;
-		keypad_button_message keypad;
-		select_soft_keys_message selectsoftkey;
-		activate_call_plane_message activatecallplane;
-		stimulus_message stimulus;
-		set_speaker_message setspeaker;
-		call_info_message callinfo;
-		start_media_transmission_message startmedia;
-		stop_media_transmission_message stopmedia;
-		open_receive_channel_message openreceivechannel;
-		open_receive_channel_ack_message openreceivechannelack;
-		close_receive_channel_message closereceivechannel;
-		display_notify_message displaynotify;
-		dialed_number_message dialednumber;
-	} data;
+	skinny_data data;
 } skinny_req;
+
+/* XXX This is the combined size of the variables above.  (len, res, e)
+   If more are added, this MUST change.
+   (sizeof(skinny_req) - sizeof(skinny_data)) DOES NOT WORK on all systems (amd64?). */
+int skinny_header_size = 12;
 
 /*****************************
  * Asterisk specific globals *
@@ -705,9 +720,34 @@
 static int amaflags = 0;
 static int callnums = 1;
 
-#define SUB_REAL 0
-#define SUB_ALT 1
-#define MAX_SUBS 2
+#define SKINNY_DEVICE_UNKNOWN		-1
+#define SKINNY_DEVICE_NONE		0
+#define SKINNY_DEVICE_30SPPLUS		1
+#define SKINNY_DEVICE_12SPPLUS		2
+#define SKINNY_DEVICE_12SP		3
+#define SKINNY_DEVICE_12		4
+#define SKINNY_DEVICE_30VIP		5
+#define SKINNY_DEVICE_7910		6
+#define SKINNY_DEVICE_7960		7
+#define SKINNY_DEVICE_7940		8
+#define SKINNY_DEVICE_7935		9
+#define SKINNY_DEVICE_ATA186		12	/* Cisco ATA-186 */
+#define SKINNY_DEVICE_7941		115
+#define SKINNY_DEVICE_7971		119
+#define SKINNY_DEVICE_7985		302
+#define SKINNY_DEVICE_7911		307
+#define SKINNY_DEVICE_7961GE		308
+#define SKINNY_DEVICE_7941GE		309
+#define SKINNY_DEVICE_7905		20000
+#define SKINNY_DEVICE_7920		30002
+#define SKINNY_DEVICE_7970		30006
+#define SKINNY_DEVICE_7912		30007
+#define SKINNY_DEVICE_7902		30008
+#define SKINNY_DEVICE_CIPC		30016	/* Cisco IP Communicator */
+#define SKINNY_DEVICE_7961		30018
+#define SKINNY_DEVICE_7936		30019
+#define SKINNY_DEVICE_SCCPGATEWAY_AN	30027	/* ??? */
+#define SKINNY_DEVICE_SCCPGATEWAY_BRI	30028	/* ??? */
 
 #define SKINNY_SPEAKERON 1
 #define SKINNY_SPEAKEROFF 2
@@ -802,28 +842,10 @@
 /* How long to wait for an extra digit, if there is an ambiguous match */
 static int matchdigittimeout = 3000;
 
-struct skinny_subchannel {
-	ast_mutex_t lock;
-	unsigned int callid;
-	struct ast_channel *owner;
-	struct skinny_line *parent;
-	struct ast_rtp *rtp;
-	time_t lastouttime;
-	int progress;
-	int ringing;
-	int lastout;
-	int cxmode;
-	int nat;
-	int outgoing;
-	int alreadygone;
-	struct skinny_subchannel *next;
-};
-
 struct skinny_line {
 	ast_mutex_t lock;
 	char name[80];
 	char label[42];					/* Label that shows next to the line buttons */
-	struct skinny_subchannel *sub;			/* pointer to our current connection, channel and stuff */
 	char accountcode[AST_MAX_ACCOUNT_CODE];
 	char exten[AST_MAX_EXTENSION];			/* Extension where to start */
 	char context[AST_MAX_CONTEXT];
@@ -858,7 +880,36 @@
 	int immediate;
 	int hookstate;
 	int progress;
+	unsigned int callid;
+	struct ast_channel *owner;
+	struct ast_rtp *rtp;
+	time_t lastouttime;
+	int ringing;
+	int lastout;
+	int cxmode;
+	int nat;
+	int outgoing;
+	int alreadygone;
+
 	struct skinny_line *next;
+	struct skinny_device *parent;
+};
+
+struct skinny_speeddial {
+	ast_mutex_t lock;
+	char label[42];
+	char exten[AST_MAX_EXTENSION];
+	int instance;
+
+	struct skinny_speeddial *next;
+	struct skinny_device *parent;
+};
+
+struct skinny_addon {
+	ast_mutex_t lock;
+	char type[10];
+
+	struct skinny_addon *next;
 	struct skinny_device *parent;
 };
 
@@ -869,10 +920,12 @@
 	char version_id[16];
 	int type;
 	int registered;
-	char model[6];
+	char model[10];
 	struct sockaddr_in addr;
 	struct in_addr ourip;
 	struct skinny_line *lines;
+	struct skinny_speeddial *speeddials;
+	struct skinny_addon *addons;
 	struct ast_ha *ha;
 	struct skinnysession *session;
 	struct skinny_device *next;
@@ -891,6 +944,7 @@
 	struct sockaddr_in sin;
 	int fd;
 	char inbuf[SKINNY_MAX_PACKET];
+	char outbuf[SKINNY_MAX_PACKET];
 	struct skinny_device *device;
 	struct skinnysession *next;
 } *sessions = NULL;
@@ -922,25 +976,161 @@
 /*	.bridge = ast_rtp_bridge, */
 };
 
-static skinny_req *req_alloc(size_t size)
+static void *get_button_template(struct skinnysession *s, button_definition_template *btn)
+{
+	struct skinny_device *d = s->device;
+	struct skinny_addon *a = d->addons;
+	int i;
+
+	switch (d->type) {
+		case SKINNY_DEVICE_30SPPLUS:
+		case SKINNY_DEVICE_30VIP:
+			/* 13 rows, 2 columns */
+			for (i = 0; i < 4; i++)
+				(btn++)->buttonDefinition = BT_LINE;
+			(btn++)->buttonDefinition = BT_REDIAL;
+			(btn++)->buttonDefinition = BT_VOICEMAIL;
+			(btn++)->buttonDefinition = BT_CALLPARK;
+			(btn++)->buttonDefinition = BT_FORWARDALL;
+			(btn++)->buttonDefinition = BT_CONFERENCE;
+			for (i = 0; i < 4; i++)
+				(btn++)->buttonDefinition = BT_NONE;
+			for (i = 0; i < 13; i++)
+				(btn++)->buttonDefinition = BT_SPEEDDIAL;
+			
+			break;
+		case SKINNY_DEVICE_12SPPLUS:
+		case SKINNY_DEVICE_12SP:
+		case SKINNY_DEVICE_12:
+			/* 6 rows, 2 columns */
+			for (i = 0; i < 2; i++)
+				(btn++)->buttonDefinition = BT_LINE;
+			(btn++)->buttonDefinition = BT_REDIAL;
+			for (i = 0; i < 3; i++)
+				(btn++)->buttonDefinition = BT_SPEEDDIAL;
+			(btn++)->buttonDefinition = BT_HOLD;
+			(btn++)->buttonDefinition = BT_TRANSFER;
+			(btn++)->buttonDefinition = BT_FORWARDALL;
+			(btn++)->buttonDefinition = BT_CALLPARK;
+			(btn++)->buttonDefinition = BT_VOICEMAIL;
+			(btn++)->buttonDefinition = BT_CONFERENCE;
+			break;
+		case SKINNY_DEVICE_7910:
+			(btn++)->buttonDefinition = BT_LINE;
+			(btn++)->buttonDefinition = BT_HOLD;
+			(btn++)->buttonDefinition = BT_TRANSFER;
+			(btn++)->buttonDefinition = BT_DISPLAY;
+			(btn++)->buttonDefinition = BT_VOICEMAIL;
+			(btn++)->buttonDefinition = BT_CONFERENCE;
+			(btn++)->buttonDefinition = BT_FORWARDALL;
+			for (i = 0; i < 2; i++)
+				(btn++)->buttonDefinition = BT_SPEEDDIAL;
+			(btn++)->buttonDefinition = BT_REDIAL;
+			break;
+		case SKINNY_DEVICE_7960:
+		case SKINNY_DEVICE_7961:
+		case SKINNY_DEVICE_7961GE:
+			for (i = 0; i < 6; i++)
+				(btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
+			break;
+		case SKINNY_DEVICE_7940:
+		case SKINNY_DEVICE_7941:
+		case SKINNY_DEVICE_7941GE:
+			for (i = 0; i < 2; i++)
+				(btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
+			break;
+		case SKINNY_DEVICE_7935:
+		case SKINNY_DEVICE_7936:
+			for (i = 0; i < 2; i++)
+				(btn++)->buttonDefinition = BT_LINE;
+			break;
+		case SKINNY_DEVICE_ATA186:
+			(btn++)->buttonDefinition = BT_LINE;
+			break;
+		case SKINNY_DEVICE_7970:
+		case SKINNY_DEVICE_7971:
+		case SKINNY_DEVICE_CIPC:
+			for (i = 0; i < 8; i++)
+				(btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
+			break;
+		case SKINNY_DEVICE_7985:
+			/* XXX I have no idea what the buttons look like on these. */
+			ast_log(LOG_WARNING, "Unsupported device type '%d (7985)' found.\n", d->type);
+			break;
+		case SKINNY_DEVICE_7912:
+		case SKINNY_DEVICE_7911:
+		case SKINNY_DEVICE_7905:
+			(btn++)->buttonDefinition = BT_LINE;
+			(btn++)->buttonDefinition = BT_HOLD;
+			break;
+		case SKINNY_DEVICE_7920:
+			/* XXX I don't know if this is right. */
+			for (i = 0; i < 4; i++)
+				(btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
+			break;
+		case SKINNY_DEVICE_7902:
+			ast_log(LOG_WARNING, "Unsupported device type '%d (7902)' found.\n", d->type);
+			break;
+		case SKINNY_DEVICE_SCCPGATEWAY_AN:
+		case SKINNY_DEVICE_SCCPGATEWAY_BRI:
+			ast_log(LOG_WARNING, "Unsupported device type '%d (SCCP gateway)' found.\n", d->type);
+			break;
+		default:
+			ast_log(LOG_WARNING, "Unknown device type '%d' found.\n", d->type);
+			break;
+	}
+
+	a = d->addons;
+	while (a) {
+		if (!strcasecmp(a->type, "7914")) {
+			for (i = 0; i < 14; i++)
+				(btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
+		} else {
+			ast_log(LOG_WARNING, "Unknown addon type '%s' found.  Skipping.\n", a->type);
+		}
+		a = a->next;
+	}
+
+	return btn;
+}
+
+static skinny_req *req_alloc(size_t size, int response_message)
 {
 	skinny_req *req;
-	req = malloc(size+12);
-	if (!req) {
+	skinny_data *data;
+
+	if (!(req = ast_calloc(1, sizeof(skinny_req))))
 		return NULL;
-	}
-	memset(req, 0, size+12);
+
+	if (!(data = ast_calloc(1, size)))
+		return NULL;
+
+	req->len = htolel(size+4);
+	req->e = htolel(response_message);
+
+	req->data = *data;
+
 	return req;
 }
 
-static struct skinny_subchannel *find_subchannel_by_line(struct skinny_line *l)
-{
-	/* XXX Need to figure out how to determine which sub we want */
-	struct skinny_subchannel *sub = l->sub;
-	return sub;
-}
-
-static struct skinny_subchannel *find_subchannel_by_name(const char *dest)
+static struct skinny_line *find_line_by_instance(struct skinny_device *d, int instance)
+{
+	struct skinny_line *l;
+
+	l = d->lines;
+	while (l) {
+		if (l->instance == instance)
+			break;
+		l = l->next;
+	}
+
+	if (!l) {
+		ast_log(LOG_WARNING, "Could not find line with instance '%d' on device '%s'\n", instance, d->name);
+	}
+	return l;
+}
+
+static struct skinny_line *find_line_by_name(const char *dest)
 {
 	struct skinny_line *l;
 	struct skinny_device *d;
@@ -959,15 +1149,14 @@
 	ast_mutex_lock(&devicelock);
 	for (d = devices; d; d = d->next) {
 		if (!strcasecmp(d->name, device)) {
-			if (skinnydebug) {
+			if (skinnydebug)
 				ast_verbose("Found device: %s\n", d->name);
-			}
 			/* Found the device */
 			for (l = d->lines; l; l = l->next) {
 				/* Search for the right line */
 				if (!strcasecmp(l->name, line)) {
 					ast_mutex_unlock(&devicelock);
-					return l->sub;
+					return l;
 				}
 			}
 		}
@@ -983,12 +1172,15 @@
 	ast_mutex_lock(&s->lock);
 
 #if 0
-	if (skinnydebug) {
+	if (skinnydebug)
 		ast_verbose("writing packet type %04X (%d bytes) to socket %d\n", letohl(req->e), letohl(req->len)+8, s->fd);
-	}
 #endif
 
-	res = write(s->fd, req, letohl(req->len)+8);
+	memset(s->outbuf,0,sizeof(s->outbuf));
+	memcpy(s->outbuf, req, skinny_header_size);
+	memcpy(s->outbuf+skinny_header_size, &req->data, sizeof(skinny_data));
+
+	res = write(s->fd, s->outbuf, letohl(req->len)+8);
 	if (res != letohl(req->len)+8) {
 		ast_log(LOG_WARNING, "Transmit: write only sent %d out of %d bytes: %s\n", res, letohl(req->len)+8, strerror(errno));
 	}
@@ -1007,13 +1199,9 @@
 {
 	skinny_req *req;
 
-	req = req_alloc(sizeof(struct set_speaker_message));
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (!(req = req_alloc(sizeof(struct set_speaker_message), SET_SPEAKER_MESSAGE)))
 		return;
-	}
-	req->len = htolel(sizeof(set_speaker_message)+4);
-	req->e = htolel(SET_SPEAKER_MESSAGE);
+
 	req->data.setspeaker.mode = htolel(mode);
 	transmit_response(s, req);
 }
@@ -1021,43 +1209,40 @@
 static void transmit_callstate(struct skinnysession *s, int instance, int state, unsigned callid)
 {
 	skinny_req *req;
-	int memsize = sizeof(struct call_state_message);
-
-	req = req_alloc(memsize);
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+
+	if (!(req = req_alloc(sizeof(struct call_state_message), CALL_STATE_MESSAGE)))
 		return;
-	}
+
 	if (state == SKINNY_ONHOOK) {
 		transmit_speaker_mode(s, SKINNY_SPEAKEROFF);
 	}
-	req->len = htolel(sizeof(call_state_message)+4);
-	req->e = htolel(CALL_STATE_MESSAGE);
 	req->data.callstate.callState = htolel(state);
 	req->data.callstate.lineInstance = htolel(instance);
 	req->data.callstate.callReference = htolel(callid);
 	transmit_response(s, req);
 	if (state == SKINNY_OFFHOOK) {
-		memset(req, 0, memsize);
-		req->len = htolel(sizeof(activate_call_plane_message)+4);
-		req->e = htolel(ACTIVATE_CALL_PLANE_MESSAGE);
+		if (!(req = req_alloc(sizeof(struct activate_call_plane_message), ACTIVATE_CALL_PLANE_MESSAGE)))
+			return;
+
 		req->data.activatecallplane.lineInstance = htolel(instance);
 		transmit_response(s, req);
 	} else if (state == SKINNY_ONHOOK) {
-		memset(req, 0, memsize);
-		req->len = htolel(sizeof(activate_call_plane_message)+4);
-		req->e = htolel(ACTIVATE_CALL_PLANE_MESSAGE);
+		if (!(req = req_alloc(sizeof(struct activate_call_plane_message), ACTIVATE_CALL_PLANE_MESSAGE)))
+			return;
+
 		req->data.activatecallplane.lineInstance = 0;
 		transmit_response(s, req);
-		memset(req, 0, memsize);
-		req->len = htolel(sizeof(close_receive_channel_message)+4);
-		req->e = htolel(CLOSE_RECEIVE_CHANNEL_MESSAGE);
+
+		if (!(req = req_alloc(sizeof(struct close_receive_channel_message), CLOSE_RECEIVE_CHANNEL_MESSAGE)))
+			return;
+
 		req->data.closereceivechannel.conferenceId = 0;
 		req->data.closereceivechannel.partyId = 0;
 		transmit_response(s, req);
-		memset(req, 0, memsize);
-		req->len = htolel(sizeof(stop_media_transmission_message)+4);
-		req->e = htolel(STOP_MEDIA_TRANSMISSION_MESSAGE);
+
+		if (!(req = req_alloc(sizeof(struct stop_media_transmission_message), STOP_MEDIA_TRANSMISSION_MESSAGE)))
+			return;
+
 		req->data.stopmedia.conferenceId = 0;
 		req->data.stopmedia.passThruPartyId = 0;
 		transmit_response(s, req);
@@ -1068,14 +1253,8 @@
 {
 	skinny_req *req;
 
-	req = req_alloc(sizeof(struct call_info_message));
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (!(req = req_alloc(sizeof(struct call_info_message), CALL_INFO_MESSAGE)))
 		return;
-	}
-
-	req->len = htolel(sizeof(struct call_info_message));
-	req->e = htolel(CALL_INFO_MESSAGE);
 
 	if (fromname) {
 		ast_copy_string(req->data.callinfo.callingPartyName, fromname, sizeof(req->data.callinfo.callingPartyName));
@@ -1100,13 +1279,9 @@
 	skinny_req *req;
 	struct skinny_line *l = s->device->lines;
 
-	req = req_alloc(sizeof(struct open_receive_channel_message));
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (!(req = req_alloc(sizeof(struct open_receive_channel_message), OPEN_RECEIVE_CHANNEL_MESSAGE)))
 		return;
-	}
-	req->len = htolel(sizeof(struct open_receive_channel_message));
-	req->e = htolel(OPEN_RECEIVE_CHANNEL_MESSAGE);
+
 	req->data.openreceivechannel.conferenceId = 0;
 	req->data.openreceivechannel.partyId = 0;
 	req->data.openreceivechannel.packets = htolel(20);
@@ -1121,58 +1296,42 @@
 	skinny_req *req;
 
 	if (tone > 0) {
-		req = req_alloc(sizeof(struct start_tone_message));
+		if (!(req = req_alloc(sizeof(struct start_tone_message), START_TONE_MESSAGE)))
+			return;
 	} else {
-		req = req_alloc(4);
-	}
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
-		return;
-	}
+		if (!(req = req_alloc(4, STOP_TONE_MESSAGE)))
+			return;
+	}
+
 	if (tone > 0) {
-		req->len = htolel(sizeof(start_tone_message)+4);
-		req->e = htolel(START_TONE_MESSAGE);
 		req->data.starttone.tone = htolel(tone);
 	} else {
 		req->len = htolel(4);
-		req->e = htolel(STOP_TONE_MESSAGE);
 	}
 	transmit_response(s, req);
 }
 
-#if 0
-/* XXX need to properly deal with softkeys */
 static void transmit_selectsoftkeys(struct skinnysession *s, int instance, int callid, int softkey)
 {
 	skinny_req *req;
-	int memsize = sizeof(struct select_soft_keys_message);
-
-	req = req_alloc(memsize);
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+
+	if (!(req = req_alloc(sizeof(struct select_soft_keys_message), SELECT_SOFT_KEYS_MESSAGE)))
 		return;
-	}
-	memset(req, 0, memsize);
-	req->len = htolel(sizeof(select_soft_keys_message)+4);
-	req->e = htolel(SELECT_SOFT_KEYS_MESSAGE);
+
 	req->data.selectsoftkey.instance = htolel(instance);
 	req->data.selectsoftkey.reference = htolel(callid);
 	req->data.selectsoftkey.softKeySetIndex = htolel(softkey);
+	req->data.selectsoftkey.validKeyMask = 0xFFFFFFFF;
 	transmit_response(s, req);
 }
-#endif
 
 static void transmit_lamp_indication(struct skinnysession *s, int stimulus, int instance, int indication)
 {
 	skinny_req *req;
 
-	req = req_alloc(sizeof(struct set_lamp_message));
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (!(req = req_alloc(sizeof(struct set_lamp_message), SET_LAMP_MESSAGE)))
 		return;
-	}
-	req->len = htolel(sizeof(set_lamp_message)+4);
-	req->e = htolel(SET_LAMP_MESSAGE);
+
 	req->data.setlamp.stimulus = htolel(stimulus);
 	req->data.setlamp.stimulusInstance = htolel(instance);
 	req->data.setlamp.deviceStimulus = htolel(indication);
@@ -1183,13 +1342,15 @@
 {
 	skinny_req *req;
 
-	req = req_alloc(sizeof(struct set_ringer_message));
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (skinnydebug)
+		ast_verbose("Setting ringer mode to '%d'.\n", mode);
+
+	if (!(req = req_alloc(sizeof(struct set_ringer_message), SET_RINGER_MESSAGE)))
 		return;
-	}
-	req->len = htolel(sizeof(set_ringer_message)+4);
-	req->e = htolel(SET_RINGER_MESSAGE);
+
+	/* XXX I don't know why, but my phone reboots unless I set this. */
+	req->len = htolel(0);
+
 	req->data.setringer.ringerMode = htolel(mode);
 	transmit_response(s, req);
 }
@@ -1199,49 +1360,37 @@
 	skinny_req *req;
 
 	if (text == 0) {
-		req = req_alloc(4);
-		if (req) {
-			req->len = htolel(4);
-			req->e = htolel(CLEAR_DISPLAY_MESSAGE);
-		}
+		if (!(req = req_alloc(4, CLEAR_DISPLAY_MESSAGE)))
+			return;
+
+//Qwell - why are we hardcoding here?
+		req->len = htolel(4);
+		if (skinnydebug)
+			ast_verbose("Clearing Display\n");
 	} else {
-		req = req_alloc(sizeof(struct displaytext_message));
-		if (req) {
-			ast_copy_string(req->data.displaytext.text, text, sizeof(req->data.displaytext.text));
-			req->len = htolel(sizeof(displaytext_message) + 4);
-			req->e = htolel(DISPLAYTEXT_MESSAGE);
-			if (skinnydebug) {
-				ast_verbose("Displaying message '%s'\n", req->data.displaytext.text);
-			}
-		}
-	}
-
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+		if (!(req = req_alloc(sizeof(struct displaytext_message), DISPLAYTEXT_MESSAGE)))
+			return;
+
+		ast_copy_string(req->data.displaytext.text, text, sizeof(req->data.displaytext.text));
+		if (skinnydebug)
+			ast_verbose("Displaying message '%s'\n", req->data.displaytext.text);
+	}
+
+	transmit_response(s, req);
+}
+
+static void transmit_displaynotify(struct skinnysession *s, char *text, int t)
+{
+	skinny_req *req;
+
+	if (!(req = req_alloc(sizeof(struct display_notify_message), DISPLAY_NOTIFY_MESSAGE)))
 		return;
-	}
-	transmit_response(s, req);
-}
-
-static void transmit_displaynotify(struct skinnysession *s, char *text, int t)
-{
-	skinny_req *req;
-
-	req = req_alloc(sizeof(struct display_notify_message));
-
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
-		return;
-	}
-
-	req->e = htolel(DISPLAY_NOTIFY_MESSAGE);
-	req->len = htolel(sizeof(display_notify_message) + 4);
+
 	ast_copy_string(req->data.displaynotify.displayMessage, text, sizeof(req->data.displaynotify.displayMessage));
 	req->data.displaynotify.displayTimeout = htolel(t);
 
-	if (skinnydebug) {
+	if (skinnydebug)
 		ast_verbose("Displaying notify '%s'\n", text);
-	}
 
 	transmit_response(s, req);
 }
@@ -1250,23 +1399,16 @@
 {
 	skinny_req *req;
 
-	req = req_alloc(sizeof(struct display_prompt_status_message));
-
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (!(req = req_alloc(sizeof(struct display_prompt_status_message), DISPLAY_PROMPT_STATUS_MESSAGE)))
 		return;
-	}
-
-	req->e = htolel(DISPLAY_PROMPT_STATUS_MESSAGE);
-	req->len = htolel(sizeof(display_prompt_status_message) + 4);
+
 	ast_copy_string(req->data.displaypromptstatus.promptMessage, text, sizeof(req->data.displaypromptstatus.promptMessage));
 	req->data.displaypromptstatus.messageTimeout = htolel(t);
 	req->data.displaypromptstatus.lineInstance = htolel(instance);
 	req->data.displaypromptstatus.callReference = htolel(callid);
 
-	if (skinnydebug) {
+	if (skinnydebug)
 		ast_verbose("Displaying Prompt Status '%s'\n", text);
-	}
 
 	transmit_response(s, req);
 }
@@ -1275,15 +1417,9 @@
 {
 	skinny_req *req;
 
-	req = req_alloc(sizeof(struct dialed_number_message));
-
-	if (!req) {
-		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+	if (!(req = req_alloc(sizeof(struct dialed_number_message), DIALED_NUMBER_MESSAGE)))
 		return;
-	}
-

[... 2188 lines stripped ...]


More information about the asterisk-commits mailing list