Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DigitMap keyword for intuitively inserting digit map (dial plan) #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/packetcable_digitmap.cfg
Binary file not shown.
57 changes: 57 additions & 0 deletions examples/packetcable_digitmap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Main
{
MtaConfigDelimiter 1;
SnmpMibObject pktcMtaDevEnabled.0 Integer 1; /* true */
SnmpMibObject pktcEUEDevSipPort.0 Gauge32 5060;
SnmpMibObject pktcEUEDevOpDomain.1 String "yourOperatorDomain.com";
SnmpMibObject pktcEUEDevOpRowStatus.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUEDevPCSCFAddrType.1.1 Integer 1; /* ipv4 */
SnmpMibObject pktcEUEDevPCSCFAddr.1.1 String "10.11.12.13";
SnmpMibObject pktcEUEDevPCSCFSipPort.1.1 Gauge32 5060;
SnmpMibObject pktcEUEDevPCSCFRowStatus.1.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUEUsrIMPUIdType.1 Integer 3; /* publicIdentity */
SnmpMibObject pktcEUEUsrIMPUId.1 String "sip:[email protected]";
SnmpMibObject pktcEUEUsrIMPUIMPIIndexRef.1 Gauge32 1;
SnmpMibObject pktcEUEUsrIMPUOpIndexRefs.1 String "1";
SnmpMibObject pktcEUEUsrIMPUSigSecurity.1 Integer 2; /* false */
SnmpMibObject pktcEUEUsrIMPUAdditionalInfo.1 String "IEP#9;OEP#9";
SnmpMibObject pktcEUEUsrIMPURowStatus.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUEUsrIMPUIdType.2 Integer 3; /* publicIdentity */
SnmpMibObject pktcEUEUsrIMPUId.2 String "sip:[email protected]";
SnmpMibObject pktcEUEUsrIMPUIMPIIndexRef.2 Gauge32 1;
SnmpMibObject pktcEUEUsrIMPUOpIndexRefs.2 String "1";
SnmpMibObject pktcEUEUsrIMPUSigSecurity.2 Integer 2; /* false */
SnmpMibObject pktcEUEUsrIMPUAdditionalInfo.2 String "IEP#10;OEP#10";
SnmpMibObject pktcEUEUsrIMPURowStatus.2 Integer 4; /* createAndGo */
SnmpMibObject pktcEUEUsrAppMapAppOrgID.1.1 Gauge32 4491;
SnmpMibObject pktcEUEUsrAppMapAppIdentifier.1.1 Gauge32 1;
SnmpMibObject pktcEUEUsrAppMapAppIndexRef.1.1 Gauge32 1;
SnmpMibObject pktcEUEUsrAppMapRowStatus.1.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUEUsrAppMapAppOrgID.2.1 Gauge32 4491;
SnmpMibObject pktcEUEUsrAppMapAppIdentifier.2.1 Gauge32 1;
SnmpMibObject pktcEUEUsrAppMapAppIndexRef.2.1 Gauge32 1;
SnmpMibObject pktcEUEUsrAppMapRowStatus.2.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUERSTAppFeatID.1.1 Integer 2; /* digitMap */
SnmpMibObject pktcEUERSTAppFeatIndexRef.1.1 Gauge32 1;
SnmpMibObject pktcEUERSTAppStatus.1.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUERSTAppFeatID.1.2 Integer 3; /* basicCall */
SnmpMibObject pktcEUERSTAppFeatIndexRef.1.2 Gauge32 1;
SnmpMibObject pktcEUERSTAppStatus.1.2 Integer 4; /* createAndGo */
DigitMap "yourOperatorDialPlan.txt";
SnmpMibObject pktcEUERSTDMStatus.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUERSTBCallPrefCodecList.1 String "";
SnmpMibObject pktcEUERSTBCallStatus.1 Integer 4; /* createAndGo */
SnmpMibObject pktcEUERSTNfBCallOrigDTTimer.1 Gauge32 30;
SnmpMibObject pktcEUERSTNfBCallTermErrSigTimer.1 Gauge32 120;
SnmpMibObject pktcEUERSTNfBCallPermSeqTimer1.1 Gauge32 60;
SnmpMibObject pktcEUERSTNfBCallPermSeqTimer2.1 Gauge32 60;
SnmpMibObject pktcEUERSTNfBCallPermSeqTimer3.1 Gauge32 60;
SnmpMibObject pktcEUERSTNfBCallPermSeqTimer4.1 Gauge32 60;
SnmpMibObject pktcEUERSTNfBCallLORTimer.1 Gauge32 2;
SnmpMibObject pktcEUERSTNfBCallNEMDSCPValueMedia.1 Gauge32 15;
SnmpMibObject pktcEUERSTNfBCallNEMDSCPValueSig.1 Gauge32 15;
SnmpMibObject pktcEUERSTNFBCallOrigModLongIntDig.1 Gauge32 16;
SnmpMibObject pktcEUERSTNfBCallOverrideNotifyRejected.1 Integer 2; /* false */
SnmpMibObject pktcEUERSTNfBCallStatus.1 Integer 4; /* createAndGo */
MtaConfigDelimiter 255;
}
2 changes: 2 additions & 0 deletions src/docsis.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ struct tlv *create_cpemac_tlv (struct symbol_entry *sym_ptr,
union t_val *value);
struct tlv *create_external_file_tlv (struct symbol_entry *sym_ptr,
union t_val *value);
struct tlv *create_dialplan_tlv (struct symbol_entry *sym_ptr,
union t_val *value);


/* add a TLV to a list; create the list if NULL, otherwise re-alloc new list,
Expand Down
5 changes: 3 additions & 2 deletions src/docsis_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
#define _DOCSIS_COMMON_H

/* needed in docsis_symtable.h */
#define NUM_IDENTIFIERS 1536
#define NUM_IDENTIFIERS 1537

#define MAXINT 2000000000
#define TLV_VSIZE 1024
#define TLV_VSIZE 9000
#define TRUE 1
#define FALSE 0
#define MAX_DIALPLAN_SIZE 8192 /* defined in CL-PKTC-EUE-RST-MIB */

#define INDENT_NOOP 100
#define INDENT_CLEAR 101
Expand Down
9 changes: 4 additions & 5 deletions src/docsis_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "docsis_snmp.h"
#include "ethermac.h"

#define DIALPLAN_OUTPUT "dialplan_output.txt"

unsigned int is_vspecific = FALSE;

struct symbol_entry *
Expand Down Expand Up @@ -340,7 +342,7 @@ void decode_snmp_object (unsigned char *tlvbuf, symbol_type *sym, size_t length
memcpy (pr, tlvbuf + 24, 2);

if ( memcmp(pm, pn, 19) == 0 || memcmp(po, pp, 19) == 0 ) {
FILE *dialplan = fopen("dialplan.txt", "w");
FILE *dialplan = fopen(DIALPLAN_OUTPUT, "w");
// when dialplan is shorter than 7F
if (*(int*)pm == *(int*)pn) {
fwrite(tlvbuf+24, sizeof(char), length - 24, dialplan);
Expand All @@ -354,10 +356,7 @@ void decode_snmp_object (unsigned char *tlvbuf, symbol_type *sym, size_t length
}
}
fclose(dialplan);
printf("/* ");
printf("PC20 dialplan found, dialplan.txt file created.");
printf(" */");
printf("\n");
printf("DigitMap \"%s\"; /* file created. */\n", DIALPLAN_OUTPUT);
} else {
printf("%s ", sym->sym_ident);
decode_vbind (tlvbuf, length );
Expand Down
1 change: 1 addition & 0 deletions src/docsis_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ TlvValue { return T_TLV_VALUE; }
TlvString { return T_TLV_STR_VALUE; }
TlvStringZero { return T_TLV_STRZERO_VALUE; }
TlvType { return T_TLV_TYPE; }
DigitMap { yylval.symptr=find_symbol_by_name(yytext);return T_DIGITMAP; }
[A-Za-z]+[A-Za-z0-9]* {
yylval.symptr=find_symbol_by_name(yytext);
if(yydebug)
Expand Down
42 changes: 22 additions & 20 deletions src/docsis_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
oid oid_value[MAX_OID_LEN];
size_t oid_value_len = MAX_OID_LEN;
unsigned char *data_ptr;
unsigned char buf[SPRINT_MAX_LEN];
unsigned char *buf;
unsigned int ltmp;
struct tree *tp;
struct range_list *rp;
long len=0;
int rv;
long longval;
unsigned long ulongval;
unsigned int retlen = 0;

memset (buf, 0, SPRINT_MAX_LEN);
buf = (unsigned char *)malloc(TLV_VSIZE);
memset (buf, 0, TLV_VSIZE);
if (!get_node (oid_string, var_name, &name_len))
{
if (!read_objid (oid_string, var_name, &name_len))
Expand Down Expand Up @@ -91,6 +93,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
fprintf(stderr, "/* Error: Can't find oid %s at line %d */\n",
oid_string, line);
snmp_perror ("encode_vbind");
free(buf);
return 0;
}
}
Expand All @@ -109,7 +112,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
sizeof (long),
(unsigned char *) &longval,
&out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 'g':
Expand All @@ -121,7 +124,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
sizeof (unsigned long),
(unsigned char *) &ulongval,
&out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 'c':
Expand All @@ -133,7 +136,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
sizeof (unsigned long),
(unsigned char *) &ulongval,
&out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 'u':
Expand All @@ -145,7 +148,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
sizeof (unsigned long),
(unsigned char *) &ulongval,
&out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 't':
Expand All @@ -157,7 +160,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
sizeof (unsigned long),
(unsigned char *) &ulongval,
&out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 's':
Expand All @@ -171,25 +174,24 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
}
else if (oid_asntype == 's')
{
strncpy ((char *) buf, value->strval, SPRINT_MAX_LEN);
strncpy ((char *) buf, value->strval, TLV_VSIZE);
len = strlen ((char *) buf);
}
else if (oid_asntype == 'x')
{
if ((rv = hexadecimal_to_binary (value->strval, buf)) == -1)
{
fprintf(stderr, "Invalid hexadecimal string at line %d\n", line);
return 0;
break;
}
ltmp = (unsigned int) rv;
len = ltmp;
}

if (len < 0 || len > SPRINT_MAX_LEN - 1)
if (len < 0 || len > TLV_VSIZE - 1)
{
fprintf(stderr, "String too long at line %d, max allowed %d\n", line,
SPRINT_MAX_LEN);
return 0;
TLV_VSIZE);
break;
}
tp = get_tree (var_name, name_len, get_tree_head ());
Expand All @@ -207,7 +209,6 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
if (!rp)
{
fprintf(stderr, "Value too long at line %d\n", line);
return 0;
break;
}
}
Expand All @@ -230,22 +231,22 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
#ifdef DEBUG
fprintf (stderr, "encoded len %ld var_len %zd leftover %zd difference %zd\n", len, name_len, out_size, (data_ptr - out_buffer) );
#endif
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 'a':
if (!inet_aton (value->strval, (struct in_addr *) &ltmp))
{
fprintf(stderr, "Invalid IP address %s at line %d\n", value->strval, line);
return 0;
break;
}
data_ptr = _docsis_snmp_build_var_op (out_buffer,
var_name,
&name_len,
ASN_IPADDRESS,
sizeof (struct in_addr),
(unsigned char *) &ltmp, &out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;
case 'o':
Expand All @@ -256,7 +257,7 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
if (!read_objid ((char *) buf, oid_value, &oid_value_len))
{
fprintf(stderr, "Can't find oid %s at line %d\n", buf, line);
return 0;
break;
}

data_ptr = _docsis_snmp_build_var_op (out_buffer,
Expand All @@ -265,16 +266,17 @@ encode_vbind (char *oid_string, char oid_asntype, union t_val *value,
ASN_OBJECT_ID,
oid_value_len*sizeof(oid),
(unsigned char *) &oid_value, &out_size);
return data_ptr - out_buffer;
retlen = data_ptr - out_buffer;
break;
;;

default:
fprintf(stderr, "Variable type %s not supported yet\n", &oid_asntype);
return 0;
break;
;;
}
/* NOTREACHED */
free(buf);
return retlen;
}


Expand Down
1 change: 1 addition & 0 deletions src/docsis_symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,7 @@ symbol_type symtable[NUM_IDENTIFIERS] = {
{ 1534, "Snmpv1v2Settings", 53, 1532, (encode_nothing), (decode_aggregate), 0, 0 }, /* TLV 217.53 HOST2.1-I17 15.2.1 */
{ 1535, "Snmpv1v2CommunityName", 1, 1534, (encode_string), (decode_string), 1, 32 }, /* TLV 217.53.1 HOST2.1-I17 15.2.1.1 */

{ 1536, "DigitMap", 11, 0, (encode_nothing), (decode_snmp_object), 0, 0 },
/* Generic TLV ... we only use the limits, code and length don't matter ...*/
{ 998, "GenericTLV", 0, 0, (encode_nothing), (decode_special), 0, 0 },
/* PacketCable MTA Configuration File Delimiter */
Expand Down
44 changes: 44 additions & 0 deletions src/docsis_yy.y
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct tlv *_my_tlvtree_head;
%token <symptr> T_IDENT_SNMPSET
%token <symptr> T_IDENT_GENERIC
%token <symptr> T_IDENT_CVC
%token <symptr> T_DIGITMAP
%token <strval> T_ETHERMASK
%token <strval> T_LABEL_OID
%token <strval> T_SUBMGT_FILTERS
Expand Down Expand Up @@ -215,6 +216,8 @@ assignment_stmt: T_IDENTIFIER T_INTEGER ';' {
$$ = create_generic_str_tlv($1,$3, (union t_val *)&$5); }
| T_IDENT_GENERIC T_TLV_CODE T_INTEGER T_TLV_STRZERO_VALUE T_STRING ';' {
$$ = create_generic_strzero_tlv($1,$3, (union t_val *)&$5); }
| T_DIGITMAP T_STRING ';' {
$$ = create_dialplan_tlv($1, (union t_val *)&$2);}
| generic_stmt {
$$ = $1; }
;
Expand Down Expand Up @@ -456,6 +459,47 @@ create_external_file_tlv ( struct symbol_entry *sym_ptr,
return first_tlvbuf;
}

struct tlv * create_dialplan_tlv(struct symbol_entry *sym_ptr, union t_val *value) {
struct tlv *tlvbuf=NULL;
unsigned int fileSize;
FILE *dialplan_file;
char *dialplan_buffer;
char oidStr[] = "1.3.6.1.4.1.4491.2.2.8.2.1.1.3.1.1.2.1";
char *oidStr2;

if ((dialplan_file = fopen (value->strval, "rb")) == NULL) {
fprintf(stderr, "Error: can't open file %s at line %d\n", value->strval, line);
exit (-5);
}
fseek(dialplan_file, 0, SEEK_END);
fileSize = ftell(dialplan_file);
if (fileSize > MAX_DIALPLAN_SIZE) {
fprintf(stderr, "Dialplan file %s too big at line %d. Must <= %d\n",
value->strval, line, MAX_DIALPLAN_SIZE);
exit(-5);
}
fseek(dialplan_file, 0, SEEK_SET);
dialplan_buffer = (char *)malloc(fileSize);
if (!dialplan_buffer) {
fprintf(stderr, "Fatal error allocating memory for dialplan buffer, closing.\n");
exit(-5);
}
if (!fread(dialplan_buffer, fileSize, 1, dialplan_file)) {
fprintf(stderr, "Something went wrong reading the dialplan file, closing.\n");
exit(-5);
}

fclose(dialplan_file);

value->strval = dialplan_buffer;
value->strval[fileSize] = '\0';
oidStr2 = (char *)malloc(strlen(oidStr) + 1); // malloc becasue create_snmpset_tlv will free it
strcpy(oidStr2, oidStr);
tlvbuf = create_snmpset_tlv(sym_ptr, oidStr2, 's', value);
free(dialplan_buffer);
return tlvbuf;
}

/* Given a code, type, and value, creates a TLV encoding.
** Expected to be used for VendorSpecific settings
*/
Expand Down