Hi List,

this is the patch i have written to generate a Generic ss7 Header from
the ANI Callerid number.

i might not be perfect but it works.

maybe there are some suggestions how to improve this further.

best regards

stefan
Index: l4isup.c
===================================================================
--- l4isup.c    (Revision 88)
+++ l4isup.c    (Arbeitskopie)
@@ -196,6 +196,7 @@
 int isup_called_party_num_encode(struct ss7_chan *pvt, char *number, unsigned 
char *param, int plen);
 int isup_called_party_num_encode_no_st(struct ss7_chan *pvt, char *number, 
unsigned char *param, int plen);
 int isup_calling_party_num_encode(char *number, int pres_restr, int si, 
unsigned char *param, int plen);
+int isup_generic_party_num_encode(char *number, int pres_restr, int si, 
unsigned char *param, int plen);
 
 static pthread_t continuity_check_thread = AST_PTHREADT_NULL;
 static int continuity_check_thread_running = 0;
@@ -1931,7 +1932,7 @@
 }
 
 static int isup_phonenum_digits(char *number, int add_st,
-                               int nlen, unsigned char *param) {
+                               int nlen, unsigned char *param, const int 
param_offset) {
   int i, d;
 
   for(i = 0; i <= nlen; i++) {
@@ -1956,9 +1957,9 @@
       }
     }
     if((i % 2) == 0) {
-      param[2 + i/2] = d;
+      param[param_offset + i/2] = d;
     } else {
-      param[2 + (i - 1)/2] |= d << 4;
+      param[param_offset + (i - 1)/2] |= d << 4;
     }
   }
 
@@ -1996,7 +1997,7 @@
     param[0] |= (is_international ? 4 : 3);
   param[1] = 0x10; /* Internal routing allowed, ISDN number plan */
 
-  if(isup_phonenum_digits(number, 1, nlen, param) == -1) {
+  if(isup_phonenum_digits(number, 1, nlen, param,2) == -1) {
     return -1;
   }
   return result_len;            /* Success */
@@ -2033,7 +2034,7 @@
     param[0] |= (is_international ? 4 : 3);
   param[1] = 0x10; /* Internal routing allowed, ISDN number plan */
 
-  if(isup_phonenum_digits(number, 0, nlen, param) == -1) {
+  if(isup_phonenum_digits(number, 0, nlen, param,2) == -1) {
     return -1;
   }
   return result_len;            /* Success */
@@ -2067,12 +2068,44 @@
     param[1] |= (0x1 << 2);
   }
 
-  if(isup_phonenum_digits(number, 0, nlen, param) == -1) {
+  if(isup_phonenum_digits(number, 0, nlen, param,2) == -1) {
     return -1;
   }
   return result_len;            /* Success */
 }
+int isup_generic_party_num_encode(char *number, int pres_restr, int si, 
unsigned char *param, int plen)
+{
+  int nlen;
+  int is_odd;
+  int is_international;
+  int result_len;
 
+  if(isup_phonenum_check(&number, &nlen, &is_international) == -1) {
+    return -1;
+  }
+
+  is_odd = nlen % 2;
+  /* Need room for three header bytes + all of the nlen digits. */
+  result_len = 3 + (nlen + 1)/2;
+  if(result_len > plen) {
+    ast_log(LOG_DEBUG, "Phonenumber too large to fit in parameter, "
+            "len %d < %d.\n", plen, result_len);
+    return -1;
+  }
+
+  param[0] = 0x6; /* additional calling party number Q.763 (3.26) */
+  param[1] = (is_odd << 7) | (is_international ? 4 : 3);
+  param[2] = 0x10 | si; /* Number complete; ISDN number plan; + screening 
indicator */
+  if(pres_restr) {
+    param[2] |= (0x1 << 2);
+  }
+
+  if(isup_phonenum_digits(number, 0, nlen, param,3) == -1) {
+    return -1;
+  }
+  return result_len;            /* Success */
+}
+
 static int isup_send_sam(struct ss7_chan *pvt, char* addr, int complete)
 {
   unsigned char msg[MTP_MAX_PCK_SIZE];
@@ -2228,6 +2261,28 @@
     isup_msg_add_optional(msg, sizeof(msg), &current, IP_CALLING_PARTY_NUMBER,
                           param, res);
   }
+  /* Generic partys number Q.763 (3.26). */
+#if defined(USE_ASTERISK_1_2) || defined(USE_ASTERISK_1_4) || 
defined(USE_ASTERISK_1_6)
+  if((chan->ani.cid_pres & AST_PRES_RESTRICTION) == AST_PRES_RESTRICTED) {
+    pres_restr = 1;
+  } else {
+    pres_restr = 0;
+  }
+  res = isup_generic_party_num_encode(chan->cid.ani_num, pres_restr, 0 /* 
additional calling party number user provided not screened */, param, 
sizeof(param));
+#else
+  if((chan->connected.ani.number.presentation & AST_PRES_RESTRICTION) == 
AST_PRES_RESTRICTED) {
+    pres_restr = 1;
+  } else {
+    pres_restr = 0;
+  }
+  res = isup_generic_party_num_encode(chan->connected.ani.number.str, 
pres_restr, 0 /* additional calling party number user provided not screened*/, 
param, sizeof(param));
+#endif
+  if(res < 0) {
+    ast_log(LOG_DEBUG, "Invalid format for ANI number, dropped.\n");
+  } else {
+    isup_msg_add_optional(msg, sizeof(msg), &current, IP_GENERIC_NUMBER,
+                          param, res);
+  }
 
   /* Some switches do not understand H.223. Those switches use Access Transport
    * (Low Layer Compatibility) to signal the video call end-to-end.
@@ -2321,6 +2376,10 @@
           (chan->connected.id.number.str ? chan->connected.id.number.str : 
"<NULL>"),
           chan->connected.id.number.presentation,
           
ast_describe_caller_presentation(chan->connected.id.number.presentation),
+          (chan->connected.ani.number.str ? chan->connected.ani.number.str : 
"<NULL>"),
+          chan->connected.ani.number.presentation,
+          
ast_describe_caller_presentation(chan->connected.ani.number.presentation),
+
          pvt->cic, pvt->link->linkset->name);
 #endif
 
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-ss7 mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-ss7

Reply via email to