[asterisk-commits] russell: branch russell/aoc r199156 - in /team/russell/aoc: ./ include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 4 14:20:40 CDT 2009


Author: russell
Date: Thu Jun  4 14:20:35 2009
New Revision: 199156

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=199156
Log:
save off progress on ideas ...

Added:
    team/russell/aoc/aoc.txt   (with props)
    team/russell/aoc/main/aoc.c   (with props)
Modified:
    team/russell/aoc/include/asterisk/aoc.h
    team/russell/aoc/include/asterisk/event_defs.h

Added: team/russell/aoc/aoc.txt
URL: http://svn.asterisk.org/svn-view/asterisk/team/russell/aoc/aoc.txt?view=auto&rev=199156
==============================================================================
--- team/russell/aoc/aoc.txt (added)
+++ team/russell/aoc/aoc.txt Thu Jun  4 14:20:35 2009
@@ -1,0 +1,116 @@
+================================================================================
+===                   Asterisk Advice of Charge Support                      ===
+===                       asteriskteam at digium.com                            ===
+===                       (C) 2009 - Digium, Inc.                            ===
+================================================================================
+
+--------------------------------------------------------------------------------
+--- 0) Table of Contents -------------------------------------------------------
+--------------------------------------------------------------------------------
+
+    1) Introduction
+    2) Software Components
+    3) Internal AOC Handling
+    4) AOC State Handling
+    5) References
+
+--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+--- 1) Introduction ------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+    Advice of Charge is a common feature on ISDN networks, especially in Europe.
+This document describes the approach for adding AOC support to Asterisk.
+
+--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+--- 2) Software Components -----------------------------------------------------
+--------------------------------------------------------------------------------
+
+    Asterisk makes use of LibPRI via chan_dahdi for access to ISDN networks.
+LibPRI currently has support for encoding and decoding of AOC facility messages
+in both the ETSI and QSIG variants.  This LibPRI support for AOC will continue
+to be improved so that all of this information may be exposed to chan_dahdi in
+Asterisk.
+
+    Snom SIP phones also support AOC via a custom mechanism.  chan_sip in 
+Asterisk will be modified to support sending and receiving AOC via this method 
+if configured to do so.
+
+    Finally, in addition to support for AOC in chan_dahdi and chan_sip, some
+work must be done to have a generic representation of AOC updates in the
+Asterisk core to provide transport of the information between different
+technologies.
+
+--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+--- 3) Internal AOC Handling ---------------------------------------------------
+--------------------------------------------------------------------------------
+
+    Asterisk must have an internal representation for AOC so that the
+information may be passed between the different technologies that support
+this information.  The transport of this information will be done with a new
+control frame type, AST_CONTROL_AOC.  This control frame will have an on the
+wire compatible payload that contains the appropriate information.  Since the
+payload will be network compatible, it can be transparently passed over IAX2, as
+well, without any extra effort.
+
+    Even though there are minor differences in the representation of the
+information in AOC updates between the different variants, the core concepts are
+the same.  The payload of the Asterisk AOC control frames should cover these
+core concepts such that AOC messages can be regenerated as close to their
+original format as possible given the generic representation.
+
+    Every AOC update will have an associated type:
+        -> START
+        -> DURING
+        -> END
+
+    Beyond the type, each AOC update can have a number of information elements,
+which are each optional depending on what was received.
+        --- Charging
+            -> Yes (Costs money, the default)
+            -> No  (Free)
+        --- Charging Units
+            -> An incremental update to the amount charged
+        --- Charging Units Total
+            -> A summary of the amount charged so far
+        --- Multiplier
+            -> This is a factor applied to the charging units to get the actual
+               cost.  If not specified, it is assumed to be 1.
+        --- Currency
+            -> This identifies the currency associated with the charging units.
+
+--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+--- 4) AOC State Handling ------------------------------------------------------
+--------------------------------------------------------------------------------
+
+    TODO - Figure out the rules for storing AOC state on Asterisk channels.
+Keeping track of the amount charged so far is easy, and seems like it would be
+useful.  However, what happens to this information during a transfer, for
+example?
+
+--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+--- 5) References --------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+Snom SIP AOC Support:
+    http://wiki.snom.com/Features/Advice_of_Charge_(AOC)
+
+--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+================================================================================
+================================================================================

Propchange: team/russell/aoc/aoc.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/russell/aoc/aoc.txt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/russell/aoc/aoc.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/russell/aoc/include/asterisk/aoc.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/russell/aoc/include/asterisk/aoc.h?view=diff&rev=199156&r1=199155&r2=199156
==============================================================================
--- team/russell/aoc/include/asterisk/aoc.h (original)
+++ team/russell/aoc/include/asterisk/aoc.h Thu Jun  4 14:20:35 2009
@@ -25,64 +25,60 @@
 #ifndef __AST_AOC_H__
 #define __AST_AOC_H__
 
+#include <inttypes.h>
+
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
 
 enum ast_aoc_type {
 	/*! \brief AOC at the beginning of a call */
-	AST_AOC_START  = 0x0000,
+	AST_AOC_START  = 0,
 	/*! \brief AOC during a call */
-	AST_AOC_DURING = 0x0001,
+	AST_AOC_DURING = 1,
 	/*! \brief AOC at the end of a call */
-	AST_AOC_END    = 0x0002,
+	AST_AOC_END    = 2,
 };
 
 enum ast_aoc_charging_type {
 	/* \brief Call costs money. */
-	AST_AOC_CHARGING_YES,
+	AST_AOC_CHARGING_YES = 0,
 	/*! \brief Call is free. */
-	AST_AOC_CHARGING_NO,
+	AST_AOC_CHARGING_NO  = 1,
 };
 
-enum ast_aoc_ie_type {
-	/*!
-	 * \brief AOC type (ast_aoc_type)
-	 * \note Required
-	 * \note payload type uint32_t
-	 */
-	AST_AOC_IE_TYPE        = 0x0000,
-	/*!
-	 * \brief Charging Type (ast_aoc_charging_type)
-	 * \note Optional, assume YES if not present.
-	 * \note payload type uint32_t
-	 */
-	AST_AOC_IE_CHARGING    = 0x0001,
-	/*!
-	 * \brief An incremental update to charging units
-	 * \note Optional
-	 * \note payload type uint32_t
-	 */
-	AST_AOC_IE_UNITS       = 0x0002,
-	/*!
-	 * \brief An update to accumulated charging units
-	 * \note Optional
-	 * \note payload type uint32_t
-	 */
-	AST_AOC_IE_UNITS_TOTAL = 0x0003,
-	/*!
-	 * \brief A multiplier for reported charging units
-	 * \note Optional
-	 * \note payload type string representation of a floating point number
-	 */
-	AST_AOC_IE_MULTIPLIER  = 0x0004,
-	/*!
-	 * \brief Currency type
-	 * \note Optional
-	 * \note payload type string
-	 */
-	AST_AOC_IE_CURRENCY    = 0x0005,
-};
+struct ast_aoc_payload;
+
+struct ast_aoc_payload *ast_aoc_payload_alloc(enum ast_aoc_type type);
+
+/*!
+ * \return NULL always
+ */
+struct ast_aoc_payload *ast_aoc_payload_destroy(struct ast_aoc_payload *pl);
+
+enum ast_aoc_type ast_aoc_payload_get_type(struct ast_aoc_payload *pl);
+
+int ast_aoc_payload_get_charging(struct ast_aoc_payload *pl,
+		enum ast_aoc_charging_type *type);
+
+int ast_aoc_payload_set_charging(struct ast_aoc_payload **pl,
+		enum ast_aoc_charging_type type);
+
+int ast_aoc_payload_get_units(struct ast_aoc_payload *pl, uint32_t *units);
+
+int ast_aoc_payload_set_units(struct ast_aoc_payload **pl, uint32_t units);
+
+int ast_aoc_payload_get_units_total(struct ast_aoc_payload *pl, uint32_t *total);
+
+int ast_aoc_payload_set_units_total(struct ast_aoc_payload **pl, uint32_t total);
+
+const char *ast_aoc_payload_get_multiplier(struct ast_aoc_payload *pl);
+
+int ast_aoc_payload_set_multiplier(struct ast_aoc_payload **pl, const char *factor);
+
+const char *ast_aoc_payload_get_currency(struct ast_aoc_payload *pl);
+
+int ast_aoc_payload_set_currency(struct ast_aoc_payload **pl, const char *currency);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/russell/aoc/include/asterisk/event_defs.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/russell/aoc/include/asterisk/event_defs.h?view=diff&rev=199156&r1=199155&r2=199156
==============================================================================
--- team/russell/aoc/include/asterisk/event_defs.h (original)
+++ team/russell/aoc/include/asterisk/event_defs.h Thu Jun  4 14:20:35 2009
@@ -120,6 +120,11 @@
 	  * This IE indicates which server the event originated from
 	  */
 	 AST_EVENT_IE_EID      = 0x0A,
+	 /*!
+	  * \brief Event Version
+	  * Payload type: UINT
+	  */
+	 AST_EVENT_IE_VERSION  = 0x0B,
 };
 
 #define AST_EVENT_IE_MAX AST_EVENT_IE_EID

Added: team/russell/aoc/main/aoc.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/russell/aoc/main/aoc.c?view=auto&rev=199156
==============================================================================
--- team/russell/aoc/main/aoc.c (added)
+++ team/russell/aoc/main/aoc.c Thu Jun  4 14:20:35 2009
@@ -1,0 +1,178 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2009, Digium, Inc.
+ *
+ * Russell Bryant <russell at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Advice of Charge Support
+ * \author Russell Bryant <russell at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/options.h"
+#include "asterisk/event.h"
+#include "asterisk/aoc.h"
+
+/*!
+ * \brief Encoding Version
+ *
+ * This will make it easy to detect a change in the encoding that is not
+ * backwards compatible if needed in the future.
+ *
+ * The current encoding (ab)uses the ast_event API to generate an on-the-wire
+ * compatible encoding.  We overload the IE values with our own, and we _never_
+ * put the "events" through the Asterisk event queue.
+ */
+static const uint32_t AST_AOC_ENCODING_VERSION = 1;
+
+enum ast_aoc_ie_type {
+	/*!
+	 * \brief AOC type (ast_aoc_type)
+	 * \note Required
+	 * \note payload type uint32_t
+	 */
+	AST_AOC_IE_TYPE        = 0x0000,
+	/*!
+	 * \brief Charging Type (ast_aoc_charging_type)
+	 * \note Optional, assume YES if not present.
+	 * \note payload type uint32_t
+	 */
+	AST_AOC_IE_CHARGING    = 0x0001,
+	/*!
+	 * \brief An incremental update to charging units
+	 * \note Optional
+	 * \note payload type uint32_t
+	 */
+	AST_AOC_IE_UNITS       = 0x0002,
+	/*!
+	 * \brief An update to accumulated charging units
+	 * \note Optional
+	 * \note payload type uint32_t
+	 */
+	AST_AOC_IE_UNITS_TOTAL = 0x0003,
+	/*!
+	 * \brief A multiplier for reported charging units
+	 * \note Optional
+	 * \note payload type string representation of a floating point number
+	 */
+	AST_AOC_IE_MULTIPLIER  = 0x0004,
+	/*!
+	 * \brief Currency type
+	 * \note Optional
+	 * \note payload type string
+	 */
+	AST_AOC_IE_CURRENCY    = 0x0005,
+};
+
+#define AST_EVENT_P(e) ((struct ast_event *) e)
+#define AST_EVENT_PP(e) ((struct ast_event **) e)
+
+struct ast_aoc_payload *ast_aoc_payload_alloc(enum ast_aoc_type type)
+{
+	return (struct ast_aoc_payload *) ast_event_new(AST_EVENT_CUSTOM,
+		AST_EVENT_IE_VERSION, AST_EVENT_IE_PLTYPE_UINT, AST_AOC_ENCODING_VERSION,
+		AST_AOC_IE_TYPE, AST_EVENT_IE_PLTYPE_UINT, type,
+		AST_EVENT_IE_END);
+}
+
+struct ast_aoc_payload *ast_aoc_payload_destroy(struct ast_aoc_payload *pl)
+{
+	struct ast_event *evt_pl = AST_EVENT_P(pl);
+
+	ast_event_destroy(evt_pl);
+
+	return NULL;
+}
+
+enum ast_aoc_type ast_aoc_payload_get_type(struct ast_aoc_payload *pl)
+{
+	return ast_event_get_ie_uint(AST_EVENT_P(pl), AST_AOC_IE_TYPE);
+}
+
+int ast_aoc_payload_get_charging(struct ast_aoc_payload *pl,
+		enum ast_aoc_charging_type *type)
+{
+	if (!ast_event_get_ie_raw(AST_EVENT_P(pl), AST_AOC_IE_CHARGING)) {
+		return -1;
+	}
+
+	*type = ast_event_get_ie_uint(AST_EVENT_P(pl), AST_AOC_IE_CHARGING);
+
+	return 0;
+}
+
+int ast_aoc_payload_set_charging(struct ast_aoc_payload **pl,
+		enum ast_aoc_charging_type type)
+{
+	return ast_event_append_ie_uint(AST_EVENT_PP(pl), AST_AOC_IE_CHARGING, type);
+}
+
+int ast_aoc_payload_get_units(struct ast_aoc_payload *pl, uint32_t *units)
+{
+	if (!ast_event_get_ie_raw(AST_EVENT_P(pl), AST_AOC_IE_UNITS)) {
+		return -1;
+	}
+
+	*units = ast_event_get_ie_uint(AST_EVENT_P(pl), AST_AOC_IE_UNITS);
+
+	return 0;
+}
+
+int ast_aoc_payload_set_units(struct ast_aoc_payload **pl, uint32_t units)
+{
+	return ast_event_append_ie_uint(AST_EVENT_PP(pl), AST_AOC_IE_UNITS, units);
+}
+
+int ast_aoc_payload_get_units_total(struct ast_aoc_payload *pl, uint32_t *total)
+{
+	if (!ast_event_get_ie_raw(AST_EVENT_P(pl), AST_AOC_IE_UNITS_TOTAL)) {
+		return -1;
+	}
+
+	*total = ast_event_get_ie_uint(AST_EVENT_P(pl), AST_AOC_IE_UNITS_TOTAL);
+
+	return 0;
+}
+
+int ast_aoc_payload_set_units_total(struct ast_aoc_payload **pl, uint32_t total)
+{
+	return ast_event_append_ie_uint(AST_EVENT_PP(pl), AST_AOC_IE_UNITS_TOTAL, total);
+}
+
+const char *ast_aoc_payload_get_multiplier(struct ast_aoc_payload *pl)
+{
+	return ast_event_get_ie_str(AST_EVENT_P(pl), AST_AOC_IE_MULTIPLIER);
+}
+
+int ast_aoc_payload_set_multiplier(struct ast_aoc_payload **pl, const char *factor)
+{
+	return ast_event_append_ie_str(AST_EVENT_PP(pl), AST_AOC_IE_MULTIPLIER, factor);
+}
+
+const char *ast_aoc_payload_get_currency(struct ast_aoc_payload *pl)
+{
+	return ast_event_get_ie_str(AST_EVENT_P(pl), AST_AOC_IE_CURRENCY);
+}
+
+int ast_aoc_payload_set_currency(struct ast_aoc_payload **pl, const char *currency)
+{
+	return ast_event_append_ie_str(AST_EVENT_PP(pl), AST_AOC_IE_CURRENCY, currency);
+}
+

Propchange: team/russell/aoc/main/aoc.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/russell/aoc/main/aoc.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/russell/aoc/main/aoc.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list