Asterisk - The Open Source Telephony Project  18.5.0
res_pktccops.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2009, Attila Domjan
5  *
6  * Attila Domjan <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*!\file
20  *
21  * \brief PacketCable COPS
22  *
23  * \author Attila Domjan <[email protected]>
24  *
25  * \note
26  * This module is an add-on to chan_mgcp. It adds support for the
27  * PacketCable MGCP variation called NCS. Res_pktccops implements COPS
28  * (RFC 2748), a protocol used to manage dynamic bandwith allocation in
29  * CMTS's (HFC gateways). When you use NCS, you need to talk COPS with
30  * the CMTS to complete the calls.
31  */
32 
33 /*** MODULEINFO
34  <defaultenabled>no</defaultenabled>
35  <support_level>extended</support_level>
36  ***/
37 
38 #include "asterisk.h"
39 
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <fcntl.h>
43 #include <netdb.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #include <string.h>
48 #include <time.h>
49 #include <errno.h>
50 #include <arpa/inet.h>
51 #include <signal.h>
52 
53 #include "asterisk/file.h"
54 #include "asterisk/logger.h"
55 #include "asterisk/channel.h"
56 #include "asterisk/config.h"
57 #include "asterisk/options.h"
58 #include "asterisk/pbx.h"
59 #include "asterisk/module.h"
60 #include "asterisk/cli.h"
61 #include "asterisk/lock.h"
62 #define AST_API_MODULE
63 #include "asterisk/pktccops.h"
64 
65 #define DEFAULT_COPS_PORT "2126"
66 
67 #define COPS_HEADER_SIZE 8
68 #define COPS_OBJECT_HEADER_SIZE 4
69 #define GATE_SET_OBJ_SIZE 144
70 #define GATEID_OBJ_SIZE 8
71 #define GATE_INFO_OBJ_SIZE 24
72 
73 #define PKTCCOPS_SCOMMAND_GATE_ALLOC 1
74 #define PKTCCOPS_SCOMMAND_GATE_ALLOC_ACK 2
75 #define PKTCCOPS_SCOMMAND_GATE_ALLOC_ERR 3
76 #define PKTCCOPS_SCOMMAND_GATE_SET 4
77 #define PKTCCOPS_SCOMMAND_GATE_SET_ACK 5
78 #define PKTCCOPS_SCOMMAND_GATE_SET_ERR 6
79 #define PKTCCOPS_SCOMMAND_GATE_INFO 7
80 #define PKTCCOPS_SCOMMAND_GATE_INFO_ACK 8
81 #define PKTCCOPS_SCOMMAND_GATE_INFO_ERR 9
82 #define PKTCCOPS_SCOMMAND_GATE_DELETE 10
83 #define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK 11
84 #define PKTCCOPS_SCOMMAND_GATE_DELETE_ERR 12
85 #define PKTCCOPS_SCOMMAND_GATE_OPEN 13
86 #define PKTCCOPS_SCOMMAND_GATE_CLOSE 14
87 
90 static uint16_t cops_trid = 0;
91 
92 struct pktcobj {
93  uint16_t length;
94  unsigned char cnum;
95  unsigned char ctype;
96  char *contents;
97  struct pktcobj *next;
98 };
99 
100 struct copsmsg {
101  unsigned char verflag;
102  unsigned char opcode;
103  uint16_t clienttype;
104  uint32_t length;
105  struct pktcobj *object;
106  char *msg; /* != NULL if not packet cable message received */
107 };
108 
109 struct gatespec {
110  int direction; /* 0-DS, 1-US */
112  int flags; /* 0x00 */
113  int sessionclass; /* normal voip: 0x01, high priority voip: 0x02, unspecified: 0x00 */
114  uint32_t srcip;
115  uint32_t dstip;
116  uint16_t srcp;
117  uint16_t dstp;
118  int diffserv;
119  uint16_t t1;
120  uint16_t t7;
121  uint16_t t8;
122  uint32_t r; /* Token Bucket Rate */
123  uint32_t b; /* token Bucket Size */
124  uint32_t p; /* Peak Data Rate */
125  uint32_t m; /* Minimum Policed Size*/
126  uint32_t mm; /* Maximum Policed Size */
127  uint32_t rate;
128  uint32_t s; /* Allowable Jitter*/
129 };
130 
131 
132 struct cops_cmts {
134  char name[80];
135  char host[80];
136  char port[80];
137  uint16_t t1;
138  uint16_t t7;
139  uint16_t t8;
140  uint32_t keepalive;
141 
142  uint32_t handle;
143  int state;
144  time_t contime;
145  time_t katimer;
146  int sfd;
148 };
149 
150 struct cops_ippool {
152  uint32_t start;
153  uint32_t stop;
154  struct cops_cmts *cmts;
155 };
156 
157 static uint16_t t1 = 250;
158 static uint16_t t7 = 200;
159 static uint16_t t8 = 300;
160 static uint32_t keepalive = 60;
161 static int pktccopsdebug = 0;
162 static int pktcreload = 0;
163 static int gateinfoperiod = 60;
164 static int gatetimeout = 150;
165 
169 
170 static int pktccops_add_ippool(struct cops_ippool *ippool);
171 static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate);
172 static void pktccops_unregister_ippools(void);
173 static int load_pktccops_config(void);
174 
175 static uint32_t ftoieeef(float n)
176 {
177  uint32_t res;
178  memcpy(&res, &n, 4);
179  return htonl(res);
180 }
181 
182 static uint16_t cops_constructgatespec(struct gatespec *gs, char *res)
183 {
184  if (res == NULL) {
185  return 0;
186  }
187 
188  *res = (char) gs->direction;
189  *(res + 1) = (char) gs->protocolid;
190  *(res + 2) = (char) gs->flags;
191  *(res + 3) = (char) gs->sessionclass;
192 
193  *((uint32_t *) (res + 4)) = gs->srcip;
194  *((uint32_t *) (res + 8)) = gs->dstip;
195 
196  *((uint16_t *) (res + 12)) = gs->srcp;
197  *((uint16_t *) (res + 14)) = gs->dstp;
198 
199  *(res + 16) = (char) gs->diffserv;
200  *(res + 17) = 0; /* reserved */
201  *(res + 18) = 0; /* reserved */
202  *(res + 19) = 0; /* reserved */
203 
204  *((uint16_t *) (res + 20)) = gs->t1;
205  *(res + 22) = 0; /* reserved */
206  *(res + 23) = 0; /* reserved */
207 
208  *((uint16_t *) (res + 24)) = gs->t7;
209  *((uint16_t *) (res + 26)) = gs->t8;
210 
211  *((uint32_t *) (res + 28)) = gs->r;
212  *((uint32_t *) (res + 32)) = gs->b;
213  *((uint32_t *) (res + 36)) = gs->p;
214  *((uint32_t *) (res + 40)) = gs->m;
215  *((uint32_t *) (res + 44)) = gs->mm;
216  *((uint32_t *) (res + 48)) = gs->rate;
217  *((uint32_t *) (res + 52)) = gs->s;
218  return 56; /* length */
219 };
220 
221 static uint16_t cops_construct_gate (int cmd, char *p, uint16_t trid,
222  uint32_t mtahost, uint32_t actcount, float rate, uint32_t psizegateid,
223  uint32_t ssip, uint16_t ssport, uint32_t gateid, struct cops_cmts *cmts)
224 {
225  struct gatespec gs;
226  int offset = 0;
227 
228  ast_debug(3, "CMD: %d\n", cmd);
229 
230  /* Transaction Identifier 8 octets */
231  *(p + offset++) = 0;
232  *(p + offset++) = 8; /* length */
233  *(p + offset++) = 1; /* snum */
234  *(p + offset++) = 1; /* stype */
235  *((uint16_t *) (p + offset)) = htons(trid);
236  offset += 2;
237  *(p + offset++) = 0;
238  *(p + offset++) = (cmd == GATE_DEL) ? PKTCCOPS_SCOMMAND_GATE_DELETE : (cmd != GATE_INFO) ? PKTCCOPS_SCOMMAND_GATE_SET : PKTCCOPS_SCOMMAND_GATE_INFO; /* 4: GATE-SET, 7: GATE-INFO */
239 
240  /*Subscriper Identifier 8 octets */
241  *(p + offset++) = 0;
242  *(p + offset++) = 8; /* length */
243  *(p + offset++) = 2; /* snum */
244  *(p + offset++) = 1; /* stype */
245  *((uint32_t *) (p + offset)) = htonl(mtahost);
246  offset += 4;
247 
248  if (cmd == GATE_INFO || cmd == GATE_SET_HAVE_GATEID || cmd == GATE_DEL) {
249  /* Gate ID 8 Octets */
250  *(p + offset++) = 0;
251  *(p + offset++) = 8; /* length */
252  *(p + offset++) = 3; /* snum */
253  *(p + offset++) = 1; /* stype */
254  *((uint32_t *) (p + offset)) = htonl(gateid);
255  offset += 4;
256  if (cmd == GATE_INFO || cmd == GATE_DEL) {
257  return offset;
258  }
259 
260  }
261 
262  /* Activity Count 8 octets */
263  *(p + offset++) = 0;
264  *(p + offset++) = 8; /* length */
265  *(p + offset++) = 4; /* snum */
266  *(p + offset++) = 1; /* stype */
267  *((uint32_t *) (p + offset)) = htonl(actcount);
268  offset += 4;
269 
270 
271  /* Gate Spec 2*60 Octets */
272  gs.direction = 0; /* DS */
273  gs.protocolid = 17; /* UDP */
274  gs.flags = 0;
275  gs.sessionclass = 1;
276  gs.srcip = htonl(ssip);
277  gs.dstip = htonl(mtahost);
278  gs.srcp = htons(ssport);
279  gs.dstp = 0;
280 /* gs.diffserv = 0xa0;*/
281  gs.diffserv = 0;
282  gs.t1 = htons(cmts->t1);
283  gs.t7 = htons(cmts->t7);
284  gs.t8 = htons(cmts->t8);
285  gs.r = ftoieeef(rate);
286  gs.b = ftoieeef(psizegateid);
287  gs.p = ftoieeef(rate);
288  gs.m = htonl((uint32_t) psizegateid);
289  gs.mm = htonl((uint32_t) psizegateid);
290  gs.rate = ftoieeef(rate);
291  gs.s = htonl(800);
292 
293 
294  *(p + offset) = 0;
295  offset++;
296  *(p + offset) = 60; /* length */
297  offset++;
298  *(p + offset) = 5; /* snum */
299  offset++;
300  *(p + offset) = 1; /* stype */
301  offset++;
302  offset += cops_constructgatespec(&gs, p + offset);
303 
304 
305  gs.direction = 1; /* US */
306  gs.srcip = htonl(mtahost);
307  gs.dstip = htonl(ssip);
308  gs.srcp = 0;
309  gs.dstp = htons(ssport);
310  *(p + offset) = 0;
311  offset++;
312  *(p + offset) = 60; /* length */
313  offset++;
314  *(p + offset) = 5; /* snum */
315  offset++;
316  *(p + offset) = 1; /* stype */
317  offset++;
318  offset += cops_constructgatespec(&gs, p + offset);
319 
320  return(offset);
321 }
322 
323 static int cops_getmsg (int sfd, struct copsmsg *recmsg)
324 {
325  int len, lent;
326  char buf[COPS_HEADER_SIZE];
327  struct pktcobj *pobject = NULL;
328  uint16_t *ubuf = (uint16_t *) buf;
329  recmsg->msg = NULL;
330  recmsg->object = NULL;
331  len = recv(sfd, buf, COPS_HEADER_SIZE, MSG_DONTWAIT);
332  if (len < COPS_HEADER_SIZE) {
333  return len;
334  }
335  recmsg->verflag = *buf;
336  recmsg->opcode = *(buf + 1);
337  recmsg->clienttype = ntohs(*((uint16_t *) (buf + 2)));
338  recmsg->length = ntohl(*((uint32_t *) (buf + 4)));
339  /* Eg KA msg*/
340  if (recmsg->clienttype != 0x8008 ) {
341  if (!(recmsg->msg = ast_malloc(recmsg->length - COPS_HEADER_SIZE))) {
342  return -1;
343  }
344  lent = recv(sfd, recmsg->msg, recmsg->length - COPS_HEADER_SIZE, MSG_DONTWAIT);
345  if (lent < recmsg->length - COPS_HEADER_SIZE) {
346  return lent;
347  }
348  len += len;
349  } else {
350  /* PacketCable Objects */
351  while (len < recmsg->length) {
352  if (len == COPS_HEADER_SIZE) {
353  /* 1st round */
354  if (!(recmsg->object = ast_malloc(sizeof(struct pktcobj)))) {
355  return -1;
356  }
357  pobject = recmsg->object;
358  } else {
359  if (!(pobject->next = ast_malloc(sizeof(struct pktcobj)))) {
360  return -1;
361  }
362  pobject = pobject->next;
363  }
364  pobject->next = NULL;
365  lent = recv(sfd, buf, COPS_OBJECT_HEADER_SIZE, MSG_DONTWAIT);
366  if (lent < COPS_OBJECT_HEADER_SIZE) {
367  ast_debug(3, "Too short object header len: %i\n", lent);
368  return lent;
369  }
370  len += lent;
371  pobject->length = ntohs(*ubuf);
372  pobject->cnum = *(buf + 2);
373  pobject->ctype = *(buf + 3);
374  if (!(pobject->contents = ast_malloc(pobject->length - COPS_OBJECT_HEADER_SIZE))) {
375  return -1;
376  }
377  lent = recv(sfd, pobject->contents, pobject->length - COPS_OBJECT_HEADER_SIZE, MSG_DONTWAIT);
378  if (lent < pobject->length - COPS_OBJECT_HEADER_SIZE) {
379  ast_debug(3, "Too short object content len: %i\n", lent);
380  return lent;
381  }
382  len += lent;
383  }
384  }
385  return len;
386 }
387 
388 static int cops_sendmsg (int sfd, struct copsmsg * sendmsg)
389 {
390  char *buf;
391  int bufpos;
392  struct pktcobj *pobject;
393 
394  if (sfd < 0) {
395  return -1;
396  }
397 
398  ast_debug(3, "COPS: sending opcode: %i len: %u\n", sendmsg->opcode, sendmsg->length);
399  if (sendmsg->length < COPS_HEADER_SIZE) {
400  ast_log(LOG_WARNING, "COPS: invalid msg size!!!\n");
401  return -1;
402  }
403  if (!(buf = ast_malloc((size_t) sendmsg->length))) {
404  return -1;
405  }
406  *buf = sendmsg->verflag ;
407  *(buf + 1) = sendmsg->opcode;
408  *((uint16_t *)(buf + 2)) = htons(sendmsg->clienttype);
409  *((uint32_t *)(buf + 4)) = htonl(sendmsg->length);
410 
411  if (sendmsg->msg != NULL) {
412  memcpy(buf + COPS_HEADER_SIZE, sendmsg->msg, sendmsg->length - COPS_HEADER_SIZE);
413  } else if (sendmsg->object != NULL) {
414  bufpos = 8;
415  pobject = sendmsg->object;
416  while(pobject != NULL) {
417  ast_debug(3, "COPS: Sending Object : cnum: %i ctype %i len: %i\n", pobject->cnum, pobject->ctype, pobject->length);
418  if (sendmsg->length < bufpos + pobject->length) {
419  ast_log(LOG_WARNING, "COPS: Invalid msg size len: %u objectlen: %i\n", sendmsg->length, pobject->length);
420  ast_free(buf);
421  return -1;
422  }
423  *(uint16_t *) (buf + bufpos) = htons(pobject->length);
424  *(buf + bufpos + 2) = pobject->cnum;
425  *(buf + bufpos + 3) = pobject->ctype;
426  if (sendmsg->length < pobject->length + bufpos) {
427  ast_log(LOG_WARNING, "COPS: Error sum of object len more the msg len %u < %i\n", sendmsg->length, pobject->length + bufpos);
428  ast_free(buf);
429  return -1;
430  }
431  memcpy((buf + bufpos + 4), pobject->contents, pobject->length - 4);
432  bufpos += pobject->length;
433  pobject = pobject->next;
434  }
435  }
436 
437  errno = 0;
438 #ifdef HAVE_MSG_NOSIGNAL
439 #define SENDFLAGS MSG_NOSIGNAL | MSG_DONTWAIT
440 #else
441 #define SENDFLAGS MSG_DONTWAIT
442 #endif
443  if (send(sfd, buf, sendmsg->length, SENDFLAGS) == -1) {
444  ast_log(LOG_WARNING, "COPS: Send failed errno=%i\n", errno);
445  ast_free(buf);
446  return -2;
447  }
448 #undef SENDFLAGS
449  ast_free(buf);
450  return 0;
451 }
452 
453 static void cops_freemsg(struct copsmsg *p)
454 {
455  struct pktcobj *pnext;
456  ast_free(p->msg);
457  p->msg = NULL;
458  while (p->object != NULL) {
459  pnext = p->object->next;
460  ast_free(p->object->contents);
461  p->object->contents = NULL;
462  ast_free(p->object);
463  p->object = pnext;
464  }
465  p->object = NULL;
466 }
467 
469  struct cops_gate *gate, uint32_t mta, uint32_t actcount, float bitrate,
470  uint32_t psize, uint32_t ssip, uint16_t ssport,
471  int (* const got_dq_gi) (struct cops_gate *gate),
472  int (* const gate_remove) (struct cops_gate *gate))
473 {
474  while (pktcreload) {
475  sched_yield();
476  }
477 
478  if (cmd == GATE_SET_HAVE_GATEID && gate) {
479  ast_debug(3, "------- gate modify gateid 0x%x ssip: 0x%x\n", gate->gateid, ssip);
480  /* TODO implement it */
481  ast_log(LOG_WARNING, "Modify GateID not implemented\n");
482  }
483 
484  if ((gate = cops_gate_cmd(cmd, NULL, cops_trid++, mta, actcount, bitrate, psize, ssip, ssport, gate))) {
485  ast_debug(3, "COPS: Allocating gate for mta: 0x%x\n", mta);
486  gate->got_dq_gi = got_dq_gi;
487  gate->gate_remove = gate_remove;
488  return(gate);
489  } else {
490  ast_debug(3, "COPS: Couldn't allocate gate for mta: 0x%x\n", mta);
491  return NULL;
492  }
493 }
494 
495 static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts,
496  uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate,
497  uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
498 {
499  struct copsmsg *gateset;
500  struct cops_gate *new;
501  struct cops_ippool *ippool;
502 
503  if (cmd == GATE_DEL) {
504  if (gate == NULL) {
505  return NULL;
506  } else {
507  cmts = gate->cmts;
508  }
509  }
510 
511  if (!cmts) {
513  AST_LIST_TRAVERSE(&ippool_list, ippool, list) {
514  if (mta >= ippool->start && mta <= ippool->stop) {
515  cmts = ippool->cmts;
516  break;
517  }
518  }
520  if (!cmts) {
521  ast_log(LOG_WARNING, "COPS: couldn't find cmts for mta: 0x%x\n", mta);
522  return NULL;
523  }
524  if (cmts->sfd < 0) {
525  ast_log(LOG_WARNING, "CMTS: %s not connected\n", cmts->name);
526  return NULL;
527  }
528  }
529 
530  if (cmd == GATE_SET) {
531  new = ast_calloc(1, sizeof(*new));
532  new->gateid = 0;
533  new->trid = trid;
534  new->mta = mta;
535  new->state = GATE_ALLOC_PROGRESS;
536  new->checked = time(NULL);
537  new->allocated = time(NULL);
538  new->cmts = cmts;
539  new->got_dq_gi = NULL;
540  new->gate_remove = NULL;
541  new->gate_open = NULL;
542  new->tech_pvt = NULL;
543  new->deltimer = 0;
547  gate = new;
548  } else {
549  if (gate) {
550  gate->trid = trid;
551  }
552  }
553 
554  gate->in_transaction = time(NULL);
555 
556  if (!(gateset = ast_malloc(sizeof(struct copsmsg)))) {
557  ast_free(gateset);
558  return NULL;
559  }
560  gateset->msg = NULL;
561  gateset->verflag = 0x10;
562  gateset->opcode = 2; /* Decision */
563  gateset->clienttype = 0x8008; /* =PacketCable */
564 
565  /* Handle object */
566  gateset->object = ast_malloc(sizeof(struct pktcobj));
567  if (!gateset->object) {
568  cops_freemsg(gateset);
569  ast_free(gateset);
570  return NULL;
571  }
572  gateset->object->length = COPS_OBJECT_HEADER_SIZE + 4;
573  gateset->object->cnum = 1; /* Handle */
574  gateset->object->ctype = 1; /* client */
575  if (!(gateset->object->contents = ast_malloc(sizeof(uint32_t)))) {
576  cops_freemsg(gateset);
577  ast_free(gateset);
578  return NULL;
579  }
580  *((uint32_t *) gateset->object->contents) = htonl(cmts->handle);
581 
582  /* Context Object */
583  if (!(gateset->object->next = ast_malloc(sizeof(struct pktcobj)))) {
584  cops_freemsg(gateset);
585  ast_free(gateset);
586  return NULL;
587  }
588  gateset->object->next->length = COPS_OBJECT_HEADER_SIZE + 4;
589  gateset->object->next->cnum = 2; /* Context */
590  gateset->object->next->ctype = 1; /* Context */
591  if (!(gateset->object->next->contents = ast_malloc(sizeof(uint32_t)))) {
592  cops_freemsg(gateset);
593  ast_free(gateset);
594  return NULL;
595  }
596  *((uint32_t *) gateset->object->next->contents) = htonl(0x00080000); /* R-Type = 8 configuration request, M-Type = 0 */
597 
598  /* Decision Object: Flags */
599  if (!(gateset->object->next->next = ast_malloc(sizeof(struct pktcobj)))) {
600  cops_freemsg(gateset);
601  ast_free(gateset);
602  return NULL;
603  }
604  gateset->object->next->next->length = COPS_OBJECT_HEADER_SIZE + 4;
605  gateset->object->next->next->cnum = 6; /* Decision */
606  gateset->object->next->next->ctype = 1; /* Flags */
607  if (!(gateset->object->next->next->contents = ast_malloc(sizeof(uint32_t)))) {
608  cops_freemsg(gateset);
609  ast_free(gateset);
610  return NULL;
611  }
612  *((uint32_t *) gateset->object->next->next->contents) = htonl(0x00010001); /* Install, Trigger Error */
613 
614  /* Decision Object: Data */
615  if (!(gateset->object->next->next->next = ast_malloc(sizeof(struct pktcobj)))) {
616  cops_freemsg(gateset);
617  ast_free(gateset);
618  return NULL;
619  }
621  gateset->object->next->next->next->cnum = 6; /* Decision */
622  gateset->object->next->next->next->ctype = 4; /* Decision Data */
623  gateset->object->next->next->next->contents = ast_malloc(((cmd != GATE_INFO && cmd != GATE_DEL) ? GATE_SET_OBJ_SIZE : GATE_INFO_OBJ_SIZE) + ((cmd == GATE_SET_HAVE_GATEID) ? GATEID_OBJ_SIZE : 0));
624  if (!gateset->object->next->next->next->contents) {
625  cops_freemsg(gateset);
626  ast_free(gateset);
627  return NULL;
628  }
629  gateset->object->next->next->next->next = NULL;
630 
631  gateset->length = COPS_HEADER_SIZE + gateset->object->length + gateset->object->next->length + gateset->object->next->next->length + gateset->object->next->next->next->length;
632 
633  if ((cmd == GATE_INFO || cmd == GATE_SET_HAVE_GATEID || cmd == GATE_DEL) && gate) {
634  ast_debug(1, "Construct gate with gateid: 0x%x\n", gate->gateid);
635  cops_construct_gate(cmd, gateset->object->next->next->next->contents, trid, mta, actcount, bitrate, psize, ssip, ssport, gate->gateid, cmts);
636  } else {
637  ast_debug(1, "Construct new gate\n");
638  cops_construct_gate(cmd, gateset->object->next->next->next->contents, trid, mta, actcount, bitrate, psize, ssip, ssport, 0, cmts);
639  }
640  if (pktccopsdebug) {
641  ast_debug(3, "send cmd\n");
642  }
643  cops_sendmsg(cmts->sfd, gateset);
644  cops_freemsg(gateset);
645  ast_free(gateset);
646  return gate;
647 }
648 
649 static int cops_connect(char *host, char *port)
650 {
651  int s, sfd = -1;
652  struct addrinfo hints;
653  struct addrinfo *rp;
654  struct addrinfo *result;
655 #ifdef HAVE_SO_NOSIGPIPE
656  int trueval = 1;
657 #endif
658 
659  memset(&hints, 0, sizeof(struct addrinfo));
660 
661  hints.ai_family = AF_UNSPEC;
662  hints.ai_socktype = SOCK_STREAM;
663  hints.ai_flags = 0;
664  hints.ai_protocol = 0;
665 
666  s = getaddrinfo(host, port, &hints, &result);
667  if (s != 0) {
668  ast_log(LOG_WARNING, "COPS: getaddrinfo: %s\n", gai_strerror(s));
669  return -1;
670  }
671 
672  for (rp = result; rp != NULL; rp = rp->ai_next) {
673  sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
674  if (sfd == -1) {
675  ast_log(LOG_WARNING, "Failed socket\n");
676  }
677  ast_fd_set_flags(sfd, O_NONBLOCK);
678 #ifdef HAVE_SO_NOSIGPIPE
679  setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, &trueval, sizeof(trueval));
680 #endif
681  connect(sfd, rp->ai_addr, rp->ai_addrlen);
682  if (sfd == -1) {
683  ast_log(LOG_WARNING, "Failed connect\n");
684  }
685  }
686  freeaddrinfo(result);
687 
688  ast_debug(3, "Connecting to cmts: %s:%s\n", host, port);
689  return(sfd);
690 }
691 
692 #define PKTCCOPS_DESTROY_CURRENT_GATE \
693  AST_LIST_REMOVE_CURRENT(list); \
694  if (gate->gate_remove) { \
695  gate->gate_remove(gate); \
696  } \
697  ast_free(gate);
698 
699 static void *do_pktccops(void *data)
700 {
701  int res, nfds, len;
702  struct copsmsg *recmsg, *sendmsg;
703  struct copsmsg recmsgb, sendmsgb;
704  struct pollfd *pfds = NULL, *tmp;
705  struct pktcobj *pobject;
706  struct cops_cmts *cmts;
707  struct cops_gate *gate;
708  char *sobjp;
709  uint16_t snst, sobjlen, scommand, recvtrid, actcount, reason, subreason;
710  uint32_t gateid, subscrid, pktcerror;
711  time_t last_exec = 0;
712 
713  recmsg = &recmsgb;
714  sendmsg = &sendmsgb;
715 
716  ast_debug(3, "COPS: thread started\n");
717 
718  for (;;) {
719  ast_free(pfds);
720  pfds = NULL;
721  nfds = 0;
723  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
724  if (last_exec != time(NULL)) {
725  if (cmts->state == 2 && cmts->katimer + cmts->keepalive < time(NULL)) {
726  ast_log(LOG_WARNING, "KA timer (%us) expired cmts: %s\n", cmts->keepalive, cmts->name);
727  cmts->state = 0;
728  cmts->katimer = -1;
729  close(cmts->sfd);
730  cmts->sfd = -1;
731  }
732  }
733  if (cmts->sfd > 0) {
734  if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) {
735  continue;
736  }
737  pfds = tmp;
738  pfds[nfds].fd = cmts->sfd;
739  pfds[nfds].events = POLLIN;
740  pfds[nfds].revents = 0;
741  nfds++;
742  } else {
743  cmts->sfd = cops_connect(cmts->host, cmts->port);
744  if (cmts->sfd > 0) {
745  cmts->state = 1;
746  if (cmts->sfd > 0) {
747  if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) {
748  continue;
749  }
750  pfds = tmp;
751  pfds[nfds].fd = cmts->sfd;
752  pfds[nfds].events = POLLIN;
753  pfds[nfds].revents = 0;
754  nfds++;
755  }
756  }
757  }
758  }
760 
761  if (last_exec != time(NULL)) {
762  last_exec = time(NULL);
765  if (gate) {
766  if (gate->deltimer && gate->deltimer < time(NULL)) {
767  gate->deltimer = time(NULL) + 5;
768  gate->trid = cops_trid++;
769  cops_gate_cmd(GATE_DEL, gate->cmts, gate->trid, 0, 0, 0, 0, 0, 0, gate);
770  ast_debug(3, "COPS: requested Gate-Del: CMTS: %s gateid: 0x%x\n", (gate->cmts) ? gate->cmts->name : "null", gate->gateid);
771  }
772  if (time(NULL) - gate->checked > gatetimeout) {
773  ast_debug(3, "COPS: remove from list GATE, CMTS: %s gateid: 0x%x\n", (gate->cmts) ? gate->cmts->name : "null", gate->gateid);
774  gate->state = GATE_TIMEOUT;
776  } else if (time(NULL) - gate->checked > gateinfoperiod && (gate->state == GATE_ALLOCATED || gate->state == GATE_OPEN)) {
777  if (gate->cmts && (!gate->in_transaction || ( gate->in_transaction + 5 ) < time(NULL))) {
778  gate->trid = cops_trid++;
779  ast_debug(3, "COPS: Gate-Info send to CMTS: %s gateid: 0x%x\n", gate->cmts->name, gate->gateid);
780  cops_gate_cmd(GATE_INFO, gate->cmts, gate->trid, gate->mta, 0, 0, 0, 0, 0, gate);
781  }
782  }
783  }
784  }
787  }
788 
789  if (pktcreload == 2) {
790  pktcreload = 0;
791  }
792  if ((res = ast_poll(pfds, nfds, 1000))) {
794  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
795  int idx;
796  if ((idx = ast_poll_fd_index(pfds, nfds, cmts->sfd)) > -1 && (pfds[idx].revents & POLLIN)) {
797  len = cops_getmsg(cmts->sfd, recmsg);
798  if (len > 0) {
799  ast_debug(3, "COPS: got from %s:\n Header: versflag=0x%02hhx opcode=%i clienttype=0x%04hx msglength=%u\n",
800  cmts->name, recmsg->verflag,
801  recmsg->opcode, recmsg->clienttype, recmsg->length);
802  if (recmsg->object != NULL) {
803  pobject = recmsg->object;
804  while (pobject != NULL) {
805  ast_debug(3, " OBJECT: length=%i cnum=%i ctype=%i\n", pobject->length, pobject->cnum, pobject->ctype);
806  if (recmsg->opcode == 1 && pobject->cnum == 1 && pobject->ctype == 1 ) {
807  cmts->handle = ntohl(*((uint32_t *) pobject->contents));
808  ast_debug(3, " REQ client handle: %u\n", cmts->handle);
809  cmts->state = 2;
810  cmts->katimer = time(NULL);
811  } else if (pobject->cnum == 9 && pobject->ctype == 1) {
812  sobjp = pobject->contents;
813  subscrid = 0;
814  recvtrid = 0;
815  scommand = 0;
816  pktcerror = 0;
817  actcount = 0;
818  gateid = 0;
819  reason = 0;
820  subreason = 0;
821  while (sobjp < (pobject->contents + pobject->length - 4)) {
822  sobjlen = ntohs(*((uint16_t *) sobjp));
823  snst = ntohs(*((uint16_t *) (sobjp + 2)));
824  ast_debug(3, " S-Num S-type: 0x%.4x len: %i\n", (unsigned)snst, sobjlen);
825  if (snst == 0x0101 ) {
826  recvtrid = ntohs(*((uint16_t *) (sobjp + 4)));
827  scommand = ntohs(*((uint16_t *) (sobjp + 6)));
828  ast_debug(3, " Transaction Identifier command: %i trid %i\n", scommand, recvtrid);
829  } else if (snst == 0x0201) {
830  subscrid = ntohl(*((uint32_t *) (sobjp + 4)));
831  ast_debug(3, " Subscriber ID: 0x%.8x\n", subscrid);
832  } else if (snst == 0x0301) {
833  gateid = ntohl(*((uint32_t *) (sobjp + 4)));
834  ast_debug(3, " Gate ID: 0x%x 0x%.8x\n", gateid, gateid);
835  } else if (snst == 0x0401) {
836  actcount = ntohs(*((uint16_t *) (sobjp + 6)));
837  ast_debug(3, " Activity Count: %i\n", actcount);
838  } else if (snst == 0x0901) {
839  pktcerror = ntohl(*((uint32_t *) (sobjp + 4)));
840  ast_debug(3, " PKTC Error: 0x%.8x\n", pktcerror);
841  } else if (snst == 0x0d01) {
842  reason = ntohs(*((uint16_t *) (sobjp + 4)));
843  subreason = ntohs(*((uint16_t *) (sobjp + 6)));
844  ast_debug(3, " Reason: %d Subreason: %d\n", reason, subreason);
845  }
846  sobjp += sobjlen;
847  if (!sobjlen)
848  break;
849  }
850  if (scommand == PKTCCOPS_SCOMMAND_GATE_CLOSE || scommand == PKTCCOPS_SCOMMAND_GATE_OPEN) {
853  if (gate->cmts == cmts && gate->gateid == gateid) {
854  if (scommand == PKTCCOPS_SCOMMAND_GATE_CLOSE && gate->state != GATE_CLOSED && gate->state != GATE_CLOSED_ERR ) {
855  ast_debug(3, "COPS Gate Close Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
856  if (subreason) {
857  gate->state = GATE_CLOSED_ERR;
859  } else {
860  gate->state = GATE_CLOSED;
862  }
863  break;
864  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_OPEN && gate->state == GATE_ALLOCATED) {
865  ast_debug(3, "COPS Gate Open Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
866  gate->state = GATE_OPEN;
867  if (gate->gate_open) {
868  ast_debug(3, "Calling GATE-OPEN callback function\n");
869  gate->gate_open(gate);
870  gate->gate_open = NULL;
871  }
872  break;
873  }
874  }
875  }
881  if (gate->cmts == cmts && gate->trid == recvtrid) {
882  gate->gateid = gateid;
883  gate->checked = time(NULL);
884  if (scommand == PKTCCOPS_SCOMMAND_GATE_SET_ACK) {
885  ast_debug(3, "COPS Gate Set Ack Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
886  gate->state = GATE_ALLOCATED;
887  if (gate->got_dq_gi) {
888  gate->got_dq_gi(gate);
889  gate->got_dq_gi = NULL;
890  }
891  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_SET_ERR) {
892  ast_debug(3, "COPS Gate Set Error TrId: %i ErrorCode: 0x%.8x CMTS: %s\n ", recvtrid, pktcerror, cmts->name);
893  gate->state = GATE_ALLOC_FAILED;
894  if (gate->got_dq_gi) {
895  gate->got_dq_gi(gate);
896  gate->got_dq_gi = NULL;
897  }
899  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_INFO_ACK) {
900  ast_debug(3, "COPS Gate Info Ack Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
901  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_INFO_ERR) {
902  ast_debug(3, "COPS Gate Info Error Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
903  gate->state = GATE_ALLOC_FAILED;
905  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_DELETE_ACK) {
906  ast_debug(3, "COPS Gate Deleted Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
907  gate->state = GATE_DELETED;
909  }
910  gate->in_transaction = 0;
911  break;
912  }
913  }
916  }
917  }
918  pobject = pobject->next;
919  }
920  }
921 
922  if (recmsg->opcode == 6 && recmsg->object && recmsg->object->cnum == 11 && recmsg->object->ctype == 1) {
923  ast_debug(3, "COPS: Client open %s\n", cmts->name);
924  sendmsg->msg = NULL;
925  sendmsg->verflag = 0x10;
926  sendmsg->opcode = 7; /* Client Accept */
927  sendmsg->clienttype = 0x8008; /* =PacketCable */
929  sendmsg->object = ast_malloc(sizeof(struct pktcobj));
930  sendmsg->object->length = 4 + COPS_OBJECT_HEADER_SIZE;
931  sendmsg->object->cnum = 10; /* keppalive timer*/
932  sendmsg->object->ctype = 1;
933  sendmsg->object->contents = ast_malloc(sizeof(uint32_t));
934  *((uint32_t *) sendmsg->object->contents) = htonl(cmts->keepalive & 0x0000ffff);
935  sendmsg->object->next = NULL;
936  cops_sendmsg(cmts->sfd, sendmsg);
937  cops_freemsg(sendmsg);
938  } else if (recmsg->opcode == 9) {
939  ast_debug(3, "COPS: Keepalive Request got echoing back %s\n", cmts->name);
940  cops_sendmsg(cmts->sfd, recmsg);
941  cmts->state = 2;
942  cmts->katimer = time(NULL);
943  }
944  }
945  if (len <= 0) {
946  ast_debug(3, "COPS: lost connection to %s\n", cmts->name);
947  close(cmts->sfd);
948  cmts->sfd = -1;
949  cmts->state = 0;
950  }
951  cops_freemsg(recmsg);
952  }
953  }
955  }
956  if (pktcreload) {
957  ast_debug(3, "Reloading pktccops...\n");
961  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
962  cmts->need_delete = 1;
963  }
966  if (cmts && cmts->need_delete) {
967  AST_LIST_TRAVERSE(&gate_list, gate, list) {
968  if (gate->cmts == cmts) {
969  ast_debug(3, "Null gate %s\n", gate->cmts->name);
970  gate->cmts = NULL;
971  }
972  gate->in_transaction = 0;
973  }
975  ast_debug(3, "removing cmts: %s\n", cmts->name);
976  if (cmts->sfd > 0) {
977  close(cmts->sfd);
978  }
980  ast_free(cmts);
981  }
982  }
986  pktcreload = 2;
987  }
988  pthread_testcancel();
989  }
990  return NULL;
991 }
992 
993 static int restart_pktc_thread(void)
994 {
996  return 0;
997  }
999  ast_log(LOG_WARNING, "Unable to lock pktccops\n");
1000  return -1;
1001  }
1002  if (pktccops_thread == pthread_self()) {
1004  ast_log(LOG_WARNING, "Cannot kill myself\n");
1005  return -1;
1006  }
1008  /* Wake up the thread */
1009  pthread_kill(pktccops_thread, SIGURG);
1010  } else {
1011  /* Start a new monitor */
1014  ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
1015  return -1;
1016  }
1017  }
1019  return 0;
1020 }
1021 
1022 static int load_pktccops_config(void)
1023 {
1024  static char *cfg = "res_pktccops.conf";
1025  struct ast_config *config;
1026  struct ast_variable *v;
1027  struct cops_cmts *cmts;
1028  struct cops_ippool *new_ippool;
1029  const char *host, *cat, *port;
1030  int update;
1031  int res = 0;
1032  uint16_t t1_temp, t7_temp, t8_temp;
1033  uint32_t keepalive_temp;
1034  unsigned int a,b,c,d,e,f,g,h;
1035  struct ast_flags config_flags = {0};
1036 
1037  if (!(config = ast_config_load(cfg, config_flags))) {
1038  ast_log(LOG_WARNING, "Unable to load config file res_pktccops.conf\n");
1039  return -1;
1040  }
1041  for (cat = ast_category_browse(config, NULL); cat; cat = ast_category_browse(config, cat)) {
1042  if (!strcmp(cat, "general")) {
1043  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1044  if (!strcasecmp(v->name, "t1")) {
1045  t1 = atoi(v->value);
1046  } else if (!strcasecmp(v->name, "t7")) {
1047  t7 = atoi(v->value);
1048  } else if (!strcasecmp(v->name, "t8")) {
1049  t8 = atoi(v->value);
1050  } else if (!strcasecmp(v->name, "keepalive")) {
1051  keepalive = atoi(v->value);
1052  } else if (!strcasecmp(v->name, "gateinfoperiod")) {
1053  gateinfoperiod = atoi(v->value);
1054  } else if (!strcasecmp(v->name, "gatetimeout")) {
1055  gatetimeout = atoi(v->value);
1056  } else {
1057  ast_log(LOG_WARNING, "Unkown option %s in general section of res_ptkccops.conf\n", v->name);
1058  }
1059  }
1060  } else {
1061  /* Defaults */
1062  host = NULL;
1063  port = NULL;
1064  t1_temp = t1;
1065  t7_temp = t7;
1066  t8_temp = t8;
1067  keepalive_temp = keepalive;
1068 
1069  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1070  if (!strcasecmp(v->name, "host")) {
1071  host = v->value;
1072  } else if (!strcasecmp(v->name, "port")) {
1073  port = v->value;
1074  } else if (!strcasecmp(v->name, "t1")) {
1075  t1_temp = atoi(v->value);
1076  } else if (!strcasecmp(v->name, "t7")) {
1077  t7_temp = atoi(v->value);
1078  } else if (!strcasecmp(v->name, "t8")) {
1079  t8_temp = atoi(v->value);
1080  } else if (!strcasecmp(v->name, "keepalive")) {
1081  keepalive_temp = atoi(v->value);
1082  } else if (!strcasecmp(v->name, "pool")) {
1083  /* we weill parse it in 2nd round */
1084  } else {
1085  ast_log(LOG_WARNING, "Unkown option %s in res_ptkccops.conf\n", v->name);
1086  }
1087  }
1088 
1089  update = 0;
1090  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1091  if (!strcmp(cmts->name, cat)) {
1092  update = 1;
1093  break;
1094  }
1095 
1096  }
1097  if (!update) {
1098  cmts = ast_calloc(1, sizeof(*cmts));
1099  if (!cmts) {
1100  res = -1;
1101  break;
1102  }
1103  AST_LIST_INSERT_HEAD(&cmts_list, cmts, list);
1104  }
1105  if (cat) {
1106  ast_copy_string(cmts->name, cat, sizeof(cmts->name));
1107  }
1108  if (host) {
1109  ast_copy_string(cmts->host, host, sizeof(cmts->host));
1110  }
1111  if (port) {
1112  ast_copy_string(cmts->port, port, sizeof(cmts->port));
1113  } else {
1114  ast_copy_string(cmts->port, DEFAULT_COPS_PORT, sizeof(cmts->port));
1115  }
1116 
1117  cmts->t1 = t1_temp;
1118  cmts->t7 = t7_temp;
1119  cmts->t8 = t8_temp;
1120  cmts->keepalive = keepalive_temp;
1121  if (!update) {
1122  cmts->state = 0;
1123  cmts->sfd = -1;
1124  }
1125  cmts->need_delete = 0;
1126  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1127  /* parse ipppol when we have cmts ptr */
1128  if (!strcasecmp(v->name, "pool")) {
1129  if (sscanf(v->value, "%3u.%3u.%3u.%3u %3u.%3u.%3u.%3u", &a, &b, &c, &d, &e, &f, &g, &h) == 8) {
1130  new_ippool = ast_calloc(1, sizeof(*new_ippool));
1131  if (!new_ippool) {
1132  res = -1;
1133  break;
1134  }
1135  new_ippool->start = a << 24 | b << 16 | c << 8 | d;
1136  new_ippool->stop = e << 24 | f << 16 | g << 8 | h;
1137  new_ippool->cmts = cmts;
1138  pktccops_add_ippool(new_ippool);
1139  } else {
1140  ast_log(LOG_WARNING, "Invalid ip pool format in res_pktccops.conf\n");
1141  }
1142  }
1143  }
1144  }
1145  }
1146  ast_config_destroy(config);
1147  return res;
1148 }
1149 
1150 static char *pktccops_show_cmtses(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1151 {
1152  struct cops_cmts *cmts;
1153  char statedesc[16];
1154  int katimer;
1155 
1156  switch(cmd) {
1157  case CLI_INIT:
1158  e->command = "pktccops show cmtses";
1159  e->usage =
1160  "Usage: pktccops show cmtses\n"
1161  " List PacketCable COPS CMTSes.\n";
1162 
1163  return NULL;
1164  case CLI_GENERATE:
1165  return NULL;
1166  }
1167 
1168  ast_cli(a->fd, "%-16s %-24s %-12s %7s\n", "Name ", "Host ", "Status ", "KA timer ");
1169  ast_cli(a->fd, "%-16s %-24s %-12s %7s\n", "------------", "--------------------", "----------", "-----------");
1171  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1172  katimer = -1;
1173  if (cmts->state == 2) {
1174  ast_copy_string(statedesc, "Connected", sizeof(statedesc));
1175  katimer = (int) (time(NULL) - cmts->katimer);
1176  } else if (cmts->state == 1) {
1177  ast_copy_string(statedesc, "Connecting", sizeof(statedesc));
1178  } else {
1179  ast_copy_string(statedesc, "N/A", sizeof(statedesc));
1180  }
1181  ast_cli(a->fd, "%-16s %-15s:%-8s %-12s %-7d\n", cmts->name, cmts->host, cmts->port, statedesc, katimer);
1182  }
1184  return CLI_SUCCESS;
1185 }
1186 
1187 static char *pktccops_show_gates(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1188 {
1189  struct cops_gate *gate;
1190  char state_desc[16];
1191 
1192  switch(cmd) {
1193  case CLI_INIT:
1194  e->command = "pktccops show gates";
1195  e->usage =
1196  "Usage: pktccops show gates\n"
1197  " List PacketCable COPS GATEs.\n";
1198 
1199  return NULL;
1200  case CLI_GENERATE:
1201  return NULL;
1202  }
1203 
1204  ast_cli(a->fd, "%-16s %-12s %-12s %-10s %-10s %-10s\n" ,"CMTS", "Gate-Id","MTA", "Status", "AllocTime", "CheckTime");
1205  ast_cli(a->fd, "%-16s %-12s %-12s %-10s %-10s %-10s\n" ,"--------------" ,"----------", "----------", "--------", "--------", "--------\n");
1208  AST_LIST_TRAVERSE(&gate_list, gate, list) {
1209  if (gate->state == GATE_ALLOC_FAILED) {
1210  ast_copy_string(state_desc, "Failed", sizeof(state_desc));
1211  } else if (gate->state == GATE_ALLOC_PROGRESS) {
1212  ast_copy_string(state_desc, "In Progress", sizeof(state_desc));
1213  } else if (gate->state == GATE_ALLOCATED) {
1214  ast_copy_string(state_desc, "Allocated", sizeof(state_desc));
1215  } else if (gate->state == GATE_CLOSED) {
1216  ast_copy_string(state_desc, "Closed", sizeof(state_desc));
1217  } else if (gate->state == GATE_CLOSED_ERR) {
1218  ast_copy_string(state_desc, "ClosedErr", sizeof(state_desc));
1219  } else if (gate->state == GATE_OPEN) {
1220  ast_copy_string(state_desc, "Open", sizeof(state_desc));
1221  } else if (gate->state == GATE_DELETED) {
1222  ast_copy_string(state_desc, "Deleted", sizeof(state_desc));
1223  } else {
1224  ast_copy_string(state_desc, "N/A", sizeof(state_desc));
1225  }
1226 
1227  ast_cli(a->fd, "%-16s 0x%.8x 0x%08x %-10s %10i %10i %u\n", (gate->cmts) ? gate->cmts->name : "null" , gate->gateid, gate->mta,
1228  state_desc, (int) (time(NULL) - gate->allocated), (gate->checked) ? (int) (time(NULL) - gate->checked) : 0, (unsigned int) gate->in_transaction);
1229  }
1232  return CLI_SUCCESS;
1233 }
1234 
1235 static char *pktccops_show_pools(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1236 {
1237  struct cops_ippool *ippool;
1238  char start[32];
1239  char stop[32];
1240 
1241  switch(cmd) {
1242  case CLI_INIT:
1243  e->command = "pktccops show pools";
1244  e->usage =
1245  "Usage: pktccops show pools\n"
1246  " List PacketCable COPS ip pools of MTAs.\n";
1247 
1248  return NULL;
1249  case CLI_GENERATE:
1250  return NULL;
1251  }
1252 
1253  ast_cli(a->fd, "%-16s %-18s %-7s\n", "Start ", "Stop ", "CMTS ");
1254  ast_cli(a->fd, "%-16s %-18s %-7s\n", "----------", "----------", "--------");
1256  AST_LIST_TRAVERSE(&ippool_list, ippool, list) {
1257  snprintf(start, sizeof(start), "%3u.%3u.%3u.%3u", ippool->start >> 24, (ippool->start >> 16) & 0x000000ff, (ippool->start >> 8) & 0x000000ff, ippool->start & 0x000000ff);
1258 
1259  snprintf(stop, sizeof(stop), "%3u.%3u.%3u.%3u", ippool->stop >> 24, (ippool->stop >> 16) & 0x000000ff, (ippool->stop >> 8) & 0x000000ff, ippool->stop & 0x000000ff);
1260  ast_cli(a->fd, "%-16s %-18s %-16s\n", start, stop, ippool->cmts->name);
1261  }
1263  return CLI_SUCCESS;
1264 }
1265 
1266 static char *pktccops_gatedel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1267 {
1268  int found = 0;
1269  int trid;
1270  uint32_t gateid;
1271  struct cops_gate *gate;
1272  struct cops_cmts *cmts;
1273 
1274  switch (cmd) {
1275  case CLI_INIT:
1276  e->command = "pktccops gatedel";
1277  e->usage =
1278  "Usage: pktccops gatedel <cmts> <gateid>\n"
1279  " Send Gate-Del to cmts.\n";
1280  return NULL;
1281  case CLI_GENERATE:
1282  return NULL;
1283  }
1284 
1285  if (a->argc < 4)
1286  return CLI_SHOWUSAGE;
1287 
1289  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1290  if (!strcmp(cmts->name, a->argv[2])) {
1291  ast_cli(a->fd, "Found cmts: %s\n", cmts->name);
1292  found = 1;
1293  break;
1294  }
1295  }
1297 
1298  if (!found)
1299  return CLI_SHOWUSAGE;
1300 
1301  trid = cops_trid++;
1302  if (!sscanf(a->argv[3], "%x", &gateid)) {
1303  ast_cli(a->fd, "bad gate specification (%s)\n", a->argv[3]);
1304  return CLI_SHOWUSAGE;
1305  }
1306 
1307  found = 0;
1309  AST_LIST_TRAVERSE(&gate_list, gate, list) {
1310  if (gate->gateid == gateid && gate->cmts == cmts) {
1311  found = 1;
1312  break;
1313  }
1314  }
1315 
1316  if (!found) {
1317  ast_cli(a->fd, "gate not found: %s\n", a->argv[3]);
1318  return CLI_SHOWUSAGE;
1319  }
1320 
1322  cops_gate_cmd(GATE_DEL, cmts, trid, 0, 0, 0, 0, 0, 0, gate);
1323  return CLI_SUCCESS;
1324 }
1325 
1326 static char *pktccops_gateset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1327 {
1328  int foundcmts = 0;
1329  int trid;
1330  unsigned int an,bn,cn,dn;
1331  uint32_t mta, ssip;
1332  struct cops_cmts *cmts;
1333 
1334  switch (cmd) {
1335  case CLI_INIT:
1336  e->command = "pktccops gateset";
1337  e->usage =
1338  "Usage: pktccops gateset <cmts> <mta> <acctcount> <bitrate> <packet size> <switch ip> <switch port>\n"
1339  " Send Gate-Set to cmts.\n";
1340  return NULL;
1341  case CLI_GENERATE:
1342  return NULL;
1343  }
1344 
1345  if (a->argc < 9)
1346  return CLI_SHOWUSAGE;
1347 
1348  if (!strcmp(a->argv[2], "null")) {
1349  cmts = NULL;
1350  } else {
1352  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1353  if (!strcmp(cmts->name, a->argv[2])) {
1354  ast_cli(a->fd, "Found cmts: %s\n", cmts->name);
1355  foundcmts = 1;
1356  break;
1357  }
1358  }
1360  if (!foundcmts) {
1361  ast_cli(a->fd, "CMTS not found: %s\n", a->argv[2]);
1362  return CLI_SHOWUSAGE;
1363  }
1364  }
1365 
1366  trid = cops_trid++;
1367  if (sscanf(a->argv[3], "%3u.%3u.%3u.%3u", &an, &bn, &cn, &dn) != 4) {
1368  ast_cli(a->fd, "MTA specification (%s) does not look like an ipaddr\n", a->argv[3]);
1369  return CLI_SHOWUSAGE;
1370  }
1371  mta = an << 24 | bn << 16 | cn << 8 | dn;
1372 
1373  if (sscanf(a->argv[7], "%3u.%3u.%3u.%3u", &an, &bn, &cn, &dn) != 4) {
1374  ast_cli(a->fd, "SSIP specification (%s) does not look like an ipaddr\n", a->argv[7]);
1375  return CLI_SHOWUSAGE;
1376  }
1377  ssip = an << 24 | bn << 16 | cn << 8 | dn;
1378 
1379  cops_gate_cmd(GATE_SET, cmts, trid, mta, atoi(a->argv[4]), atof(a->argv[5]), atoi(a->argv[6]), ssip, atoi(a->argv[8]), NULL);
1380  return CLI_SUCCESS;
1381 }
1382 
1383 static char *pktccops_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1384 {
1385  switch (cmd) {
1386  case CLI_INIT:
1387  e->command = "pktccops set debug {on|off}";
1388  e->usage =
1389  "Usage: pktccops set debug {on|off}\n"
1390  " Turn on/off debuging\n";
1391  return NULL;
1392  case CLI_GENERATE:
1393  return NULL;
1394  }
1395 
1396  if (a->argc != e->args)
1397  return CLI_SHOWUSAGE;
1398  if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
1399  pktccopsdebug = 1;
1400  ast_cli(a->fd, "PktcCOPS Debugging Enabled\n");
1401  } else if (!strncasecmp(a->argv[e->args - 1], "off", 2)) {
1402  pktccopsdebug = 0;
1403  ast_cli(a->fd, "PktcCOPS Debugging Disabled\n");
1404  } else {
1405  return CLI_SHOWUSAGE;
1406  }
1407  return CLI_SUCCESS;
1408 
1409 }
1410 
1411 static struct ast_cli_entry cli_pktccops[] = {
1412  AST_CLI_DEFINE(pktccops_show_cmtses, "List PacketCable COPS CMTSes"),
1413  AST_CLI_DEFINE(pktccops_show_gates, "List PacketCable COPS GATEs"),
1414  AST_CLI_DEFINE(pktccops_show_pools, "List PacketCable MTA pools"),
1415  AST_CLI_DEFINE(pktccops_gateset, "Send Gate-Set to cmts"),
1416  AST_CLI_DEFINE(pktccops_gatedel, "Send Gate-Det to cmts"),
1417  AST_CLI_DEFINE(pktccops_debug, "Enable/Disable COPS debugging")
1418 };
1419 
1420 static int pktccops_add_ippool(struct cops_ippool *ippool)
1421 {
1422  if (ippool) {
1426  return 0;
1427  } else {
1428  ast_log(LOG_WARNING, "Attempted to register NULL ippool?\n");
1429  return -1;
1430  }
1431 }
1432 
1434 {
1435  struct cops_cmts *cmts;
1436  struct cops_gate *gate;
1438  while ((cmts = AST_LIST_REMOVE_HEAD(&cmts_list, list))) {
1439  if (cmts->sfd > 0) {
1440  close(cmts->sfd);
1441  }
1442  ast_free(cmts);
1443  }
1445 
1447  while ((gate = AST_LIST_REMOVE_HEAD(&gate_list, list))) {
1448  ast_free(gate);
1449  }
1451 }
1452 
1454 {
1455  struct cops_ippool *ippool;
1457  while ((ippool = AST_LIST_REMOVE_HEAD(&ippool_list, list))) {
1458  ast_free(ippool);
1459  }
1461 }
1462 
1463 static int load_module(void)
1464 {
1465  int res;
1467  res = load_pktccops_config();
1469  if (res == -1) {
1470  return AST_MODULE_LOAD_DECLINE;
1471  }
1472  ast_cli_register_multiple(cli_pktccops, sizeof(cli_pktccops) / sizeof(struct ast_cli_entry));
1474 
1475  return 0;
1476 }
1477 
1478 static int unload_module(void)
1479 {
1480  if (!ast_mutex_lock(&pktccops_lock)) {
1482  pthread_cancel(pktccops_thread);
1483  pthread_kill(pktccops_thread, SIGURG);
1484  pthread_join(pktccops_thread, NULL);
1485  }
1488  } else {
1489  ast_log(LOG_ERROR, "Unable to lock the pktccops_thread\n");
1490  return -1;
1491  }
1492 
1493  ast_cli_unregister_multiple(cli_pktccops, sizeof(cli_pktccops) / sizeof(struct ast_cli_entry));
1497  return 0;
1498 }
1499 
1500 static int reload_module(void)
1501 {
1502  /* Prohibit unloading */
1503  if (pktcreload) {
1504  ast_log(LOG_NOTICE, "Previous reload in progress, please wait!\n");
1505  return -1;
1506  }
1507  pktcreload = 1;
1508  return 0;
1509 }
1510 
1511 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "PktcCOPS manager for MGCP",
1512  .support_level = AST_MODULE_SUPPORT_EXTENDED,
1513  .load = load_module,
1514  .unload = unload_module,
1515  .reload = reload_module,
1516 );
uint32_t length
Definition: res_pktccops.c:104
struct ast_variable * next
uint32_t dstip
Definition: res_pktccops.c:115
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:228
static int pktccops_add_ippool(struct cops_ippool *ippool)
static int load_module(void)
static int cops_sendmsg(int sfd, struct copsmsg *sendmsg)
Definition: res_pktccops.c:388
unsigned char opcode
Definition: res_pktccops.c:102
int state
Definition: pktccops.h:59
char * config
Definition: conf2ael.c:66
time_t katimer
Definition: res_pktccops.c:145
static uint32_t keepalive
Definition: res_pktccops.c:160
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static int gatetimeout
Definition: res_pktccops.c:164
#define PKTCCOPS_SCOMMAND_GATE_SET_ERR
Definition: res_pktccops.c:78
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
static int cops_connect(char *host, char *port)
Definition: res_pktccops.c:649
#define PKTCCOPS_SCOMMAND_GATE_DELETE
Definition: res_pktccops.c:82
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
struct cops_gate *AST_OPTIONAL_API_NAME() ast_pktccops_gate_alloc(int cmd, struct cops_gate *gate, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, int(*const got_dq_gi)(struct cops_gate *gate), int(*const gate_remove)(struct cops_gate *gate))
Definition: res_pktccops.c:468
static int gateinfoperiod
Definition: res_pktccops.c:163
Time-related functions and macros.
struct cops_ippool::@490 list
static ast_mutex_t pktccops_lock
Definition: res_pktccops.c:88
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static pthread_t pktccops_thread
Definition: res_pktccops.c:89
int diffserv
Definition: res_pktccops.c:118
static void cops_freemsg(struct copsmsg *p)
Definition: res_pktccops.c:453
descriptor for a cli entry.
Definition: cli.h:171
const int argc
Definition: cli.h:160
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static struct test_val d
static int tmp()
Definition: bt_open.c:389
#define PKTCCOPS_DESTROY_CURRENT_GATE
Definition: res_pktccops.c:692
time_t deltimer
Definition: pktccops.h:62
Structure for variables, used for configurations and for channel variables.
Definition: cli.h:152
unsigned int stop
Definition: app_meetme.c:1096
uint32_t mm
Definition: res_pktccops.c:126
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
uint16_t t1
Definition: res_pktccops.c:119
char name[80]
Definition: res_pktccops.c:134
static struct ast_cli_entry cli_pktccops[]
static char * pktccops_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
uint32_t m
Definition: res_pktccops.c:125
#define ast_mutex_lock(a)
Definition: lock.h:187
uint32_t handle
Definition: res_pktccops.c:142
static struct test_val c
static char * pktccops_gatedel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define PKTCCOPS_SCOMMAND_GATE_INFO_ACK
Definition: res_pktccops.c:80
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:67
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
time_t allocated
Definition: pktccops.h:60
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static uint16_t t7
Definition: res_pktccops.c:158
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
static struct cops_gate * cops_gate_cmd(int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
Definition: res_pktccops.c:495
struct cops_cmts::@489 list
int args
This gets set in ast_cli_register()
Definition: cli.h:185
#define PKTCCOPS_SCOMMAND_GATE_INFO_ERR
Definition: res_pktccops.c:81
#define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK
Definition: res_pktccops.c:83
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:567
#define PKTCCOPS_SCOMMAND_GATE_OPEN
Definition: res_pktccops.c:85
uint16_t srcp
Definition: res_pktccops.c:116
char * msg
Definition: res_pktccops.c:106
uint32_t start
Definition: res_pktccops.c:152
uint16_t t7
Definition: res_pktccops.c:120
Configuration File Parser.
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
Definition: utils.h:1009
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
static int unload_module(void)
#define ast_config_load(filename, flags)
Load a config file.
#define GATE_SET_OBJ_SIZE
Definition: res_pktccops.c:69
static char host[256]
Definition: muted.c:77
General Asterisk PBX channel definitions.
const int fd
Definition: cli.h:159
static uint32_t ftoieeef(float n)
Definition: res_pktccops.c:175
static uint16_t cops_constructgatespec(struct gatespec *gs, char *res)
Definition: res_pktccops.c:182
time_t checked
Definition: pktccops.h:61
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define ast_poll(a, b, c)
Definition: poll-compat.h:88
uint16_t t7
Definition: res_pktccops.c:138
#define PKTCCOPS_SCOMMAND_GATE_SET
Definition: res_pktccops.c:76
char * contents
Definition: res_pktccops.c:96
uint32_t s
Definition: res_pktccops.c:128
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define COPS_OBJECT_HEADER_SIZE
Definition: res_pktccops.c:68
uint16_t trid
Definition: pktccops.h:56
#define GATE_INFO_OBJ_SIZE
Definition: res_pktccops.c:71
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
PacketCable COPS.
Core PBX routines and definitions.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
Definition: linkedlists.h:290
const char *const * argv
Definition: cli.h:161
static int load_pktccops_config(void)
static uint16_t t8
Definition: res_pktccops.c:159
time_t in_transaction
Definition: pktccops.h:57
unsigned char ctype
Definition: res_pktccops.c:95
uint32_t gateid
Definition: pktccops.h:55
#define LOG_ERROR
Definition: logger.h:285
#define CLI_SHOWUSAGE
Definition: cli.h:45
int need_delete
Definition: res_pktccops.c:147
#define PKTCCOPS_SCOMMAND_GATE_SET_ACK
Definition: res_pktccops.c:77
uint16_t length
Definition: res_pktccops.c:93
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int ast_poll_fd_index(struct pollfd *haystack, int nfds, int needle)
Shortcut for conversion of FD_ISSET to poll(2)-based.
Definition: poll-compat.h:128
int errno
int protocolid
Definition: res_pktccops.c:111
int(* gate_open)(struct cops_gate *gate)
Definition: pktccops.h:66
static int pktcreload
Definition: res_pktccops.c:162
static uint16_t cops_trid
Definition: res_pktccops.c:90
static void * do_pktccops(void *data)
Definition: res_pktccops.c:699
#define LOG_NOTICE
Definition: logger.h:263
uint16_t t1
Definition: res_pktccops.c:137
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
char * command
Definition: cli.h:186
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static int reload(void)
Definition: cdr_mysql.c:741
struct cops_cmts * cmts
Definition: res_pktccops.c:154
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
int(* gate_remove)(struct cops_gate *gate)
Definition: pktccops.h:65
uint32_t srcip
Definition: res_pktccops.c:114
Structure used to handle boolean flags.
Definition: utils.h:199
#define PKTCCOPS_SCOMMAND_GATE_INFO
Definition: res_pktccops.c:79
#define PKTCCOPS_SCOMMAND_GATE_CLOSE
Definition: res_pktccops.c:86
Support for logging to various files, console and syslog Configuration in file logger.conf.
static char * pktccops_show_pools(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
const char * usage
Definition: cli.h:177
uint32_t r
Definition: res_pktccops.c:122
static char * pktccops_gateset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
struct pktcobj * next
Definition: res_pktccops.c:97
#define CLI_SUCCESS
Definition: cli.h:44
struct pktcobj * object
Definition: res_pktccops.c:105
uint32_t keepalive
Definition: res_pktccops.c:140
#define GATEID_OBJ_SIZE
Definition: res_pktccops.c:70
Standard Command Line Interface.
unsigned char verflag
Definition: res_pktccops.c:101
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
int direction
Definition: res_pktccops.c:110
static char * pktccops_show_cmtses(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int sessionclass
Definition: res_pktccops.c:113
#define AST_PTHREADT_STOP
Definition: lock.h:67
static int pktccopsdebug
Definition: res_pktccops.c:161
static PGresult * result
Definition: cel_pgsql.c:88
static int reload_module(void)
static void pktccops_unregister_cmtses(void)
Options provided by main asterisk program.
static struct test_val b
static void pktccops_unregister_ippools(void)
uint32_t stop
Definition: res_pktccops.c:153
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define AST_OPTIONAL_API_NAME(name)
Expands to the name of the implementation function.
Definition: optional_api.h:228
uint16_t t8
Definition: res_pktccops.c:139
#define DEFAULT_COPS_PORT
Definition: res_pktccops.c:65
static int cops_getmsg(int sfd, struct copsmsg *recmsg)
Definition: res_pktccops.c:323
char port[80]
Definition: res_pktccops.c:136
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
uint32_t b
Definition: res_pktccops.c:123
uint32_t p
Definition: res_pktccops.c:124
uint16_t clienttype
Definition: res_pktccops.c:103
Asterisk module definitions.
uint16_t dstp
Definition: res_pktccops.c:117
#define SENDFLAGS
struct ast_cli_entry::@250 list
uint32_t mta
Definition: pktccops.h:58
int(* got_dq_gi)(struct cops_gate *gate)
Definition: pktccops.h:64
#define AST_MUTEX_DEFINE_STATIC(mutex)
Definition: lock.h:518
char host[80]
Definition: res_pktccops.c:135
static int restart_pktc_thread(void)
Definition: res_pktccops.c:993
unsigned char cnum
Definition: res_pktccops.c:94
uint16_t t8
Definition: res_pktccops.c:121
static uint16_t cops_construct_gate(int cmd, char *p, uint16_t trid, uint32_t mtahost, uint32_t actcount, float rate, uint32_t psizegateid, uint32_t ssip, uint16_t ssport, uint32_t gateid, struct cops_cmts *cmts)
Definition: res_pktccops.c:221
static char * pktccops_show_gates(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
uint32_t rate
Definition: res_pktccops.c:127
#define ast_mutex_unlock(a)
Definition: lock.h:188
struct cops_cmts * cmts
Definition: pktccops.h:63
static uint16_t t1
Definition: res_pktccops.c:157
static struct test_val a
time_t contime
Definition: res_pktccops.c:144