vomp status and vomp dial command line apps added.

now debugging dial operation.
This commit is contained in:
gardners 2012-04-20 15:41:13 +09:30
parent 028b24261f
commit d843e59bd5
3 changed files with 111 additions and 35 deletions

View File

@ -30,17 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "serval.h"
#include "rhizome.h"
typedef struct command_line_option {
int (*function)(int argc,char **argv,struct command_line_option *o);
char *words[32]; // 32 words should be plenty!
unsigned long long flags;
#define CLIFLAG_NONOVERLAY (1<<0) /* Uses a legacy IPv4 DNA call instead of overlay mnetwork */
#define CLIFLAG_STANDALONE (1<<1) /* Cannot be issued to a running instance */
char *description; // describe this invocation
} command_line_option;
extern command_line_option command_line_options[];
static int servalNodeRunning(int *pid)
{
char *instancepath = serval_instancepath();
@ -424,27 +413,6 @@ int app_mdp_ping(int argc,char **argv,struct command_line_option *o)
overlay_mdp_frame mdp;
/* Get list of local addresses */
mdp.packetTypeAndFlags=MDP_GETADDRS;
mdp.addrlist.first_sid=-1;
mdp.addrlist.last_sid=0x7fffffff;
mdp.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;
int result=overlay_mdp_send(&mdp,MDP_AWAITREPLY,5000);
if (result) {
if (mdp.packetTypeAndFlags==MDP_ERROR)
{
fprintf(stderr,"Could not get list of local MDP addresses\n");
fprintf(stderr," MDP Server error #%d: '%s'\n",
mdp.error.error,mdp.error.message);
}
else
fprintf(stderr,"Could not get list of local MDP addresses\n");
return -1;
} else {
if (mdp.packetTypeAndFlags!=MDP_ADDRLIST)
return WHY("MDP Server returned wrong frame type.");
}
/* Bind to MDP socket and await confirmation */
int port=32768+(random()&32767);
mdp.packetTypeAndFlags=MDP_BIND;
@ -456,9 +424,10 @@ int app_mdp_ping(int argc,char **argv,struct command_line_option *o)
and mdp.addrlist share storage as a union in the mdp structure. */
bcopy(&mdp.addrlist.sids[0][0],mdp.bind.sid,SID_SIZE);
unsigned char srcsid[SID_SIZE];
if (overlay_mdp_getmyaddr(0,mdp.bind.sid)) return -1;
bcopy(mdp.bind.sid,srcsid,SID_SIZE);
mdp.bind.port_number=port;
result=overlay_mdp_send(&mdp,MDP_AWAITREPLY,5000);
int result=overlay_mdp_send(&mdp,MDP_AWAITREPLY,5000);
if (result) {
if (mdp.packetTypeAndFlags==MDP_ERROR)
fprintf(stderr,"Could not bind to MDP port %d: error=%d, message='%s'\n",
@ -924,6 +893,10 @@ command_line_option command_line_options[]={
"Create a new identity in the keyring protected by the provided PIN"},
{app_keyring_set_did,{"set","did","<sid>","<did>","[<pin>]",NULL},CLIFLAG_STANDALONE,
"Set the DID for the specified SID. Optionally supply PIN to unlock the SID record in the keyring."},
{app_vomp_status,{"vomp","status",NULL},0,
"Display status of any VoMP calls"},
{app_vomp_dial,{"vomp","<sid>","<did>","[<callerid>]",NULL},0,
"Attempt to dial the specified sid and did. Optionally supply the calling number"},
{NULL,{NULL}}
};

View File

@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define MALLOC_PARANOIA
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@ -1131,7 +1133,7 @@ typedef struct overlay_mdp_addrlist {
unsigned int server_sid_count;
unsigned int first_sid;
unsigned int last_sid;
unsigned char frame_sid_count; /* how many of the following 59 slots are
unsigned int frame_sid_count; /* how many of the following 59 slots are
populated */
/* 59*32 < (MDP_MTU-100), so up to 59 SIDs in a single reply.
Multiple replies can be used to respond with more. */
@ -1279,3 +1281,20 @@ typedef struct vomp_call_stateo {
int vomp_mdp_event(overlay_mdp_frame *mdp,
struct sockaddr_un *recvaddr,int recvaddrlen);
int vomp_mdp_received(overlay_mdp_frame *mdp);
typedef struct command_line_option {
int (*function)(int argc,char **argv,struct command_line_option *o);
char *words[32]; // 32 words should be plenty!
unsigned long long flags;
#define CLIFLAG_NONOVERLAY (1<<0) /* Uses a legacy IPv4 DNA call instead of overlay mnetwork */
#define CLIFLAG_STANDALONE (1<<1) /* Cannot be issued to a running instance */
char *description; // describe this invocation
} command_line_option;
extern command_line_option command_line_options[];
int cli_arg(int argc, char **argv, command_line_option *o, char *argname, char **dst, int (*validator)(const char *arg), char *defaultvalue);
int overlay_mdp_getmyaddr(int index,unsigned char *sid);
int app_vomp_status(int argc, char **argv, struct command_line_option *o);
int app_vomp_dial(int argc, char **argv, struct command_line_option *o);

86
vomp.c
View File

@ -276,6 +276,8 @@ int vomp_mdp_event(overlay_mdp_frame *mdp,
transported audio. In particular we inform when the call state changes,
including if any error has occurred.
*/
dump("vomp frame",mdp,256);
fprintf(stderr,"Flags=0x%x\n",mdp->vompevent.flags);
switch(mdp->vompevent.flags)
{
case VOMPEVENT_REGISTERINTEREST:
@ -394,6 +396,7 @@ int vomp_mdp_event(overlay_mdp_frame *mdp,
These need to be passed to the node being called to provide caller id,
and potentially handle call-routing, e.g., if it is a gateway.
*/
fprintf(stderr,"DIAL!\n");
{
/* Populate call structure */
if (vomp_call_count>=VOMP_MAX_CALLS)
@ -417,12 +420,13 @@ int vomp_mdp_event(overlay_mdp_frame *mdp,
return overlay_mdp_reply_error
(mdp_named_socket,recvaddr,recvaddrlen,4005,
"Insufficient entropy");
printf("session=0x%08x\n",call->local.session);
int i;
for(i=0;i<vomp_call_count;i++)
if (i!=slot)
if (call->local.session==vomp_call_states[i].local.session) break;
/* reject duplicate call session numbers */
if (i>=vomp_call_count) call->local.session=0;
if (i<vomp_call_count) call->local.session=0;
}
call->local.session&=VOMP_SESSION_MASK;
call->last_activity=overlay_gettime_ms();
@ -727,3 +731,83 @@ int vomp_mdp_received(overlay_mdp_frame *mdp)
return WHY("Malformed VoMP MDP packet?");
}
char *vomp_describe_state(int state)
{
switch(state) {
case VOMP_STATE_CALLENDED: return "CALLENDED";
case VOMP_STATE_INCALL: return "INCALL";
case VOMP_STATE_RINGINGIN: return "RINGINGIN";
case VOMP_STATE_RINGINGOUT: return "RINGINGOUT";
case VOMP_STATE_CALLPREP: return "CALLPREP";
case VOMP_STATE_NOCALL: return "NOCALL";
}
return "UNKNOWN";
}
int app_vomp_status(int argc, char **argv, struct command_line_option *o)
{
int i;
for(i=0;i<vomp_call_count;i++)
{
printf("%s\n-> %s\n (%s -> %s)\n",
vomp_call_states[i].local.sid,
vomp_call_states[i].remote.sid,
vomp_call_states[i].local.did,
vomp_call_states[i].remote.did);
printf(" local state=%s, remote state=%s\n",
vomp_describe_state(vomp_call_states[i].local.state),
vomp_describe_state(vomp_call_states[i].remote.state));
}
if (!vomp_call_count) printf("No active calls\n");
return 0;
}
int app_vomp_dial(int argc, char **argv, struct command_line_option *o)
{
char *sid,*did,*callerid;
cli_arg(argc, argv, o, "sid", &sid, NULL, "");
cli_arg(argc, argv, o, "did", &did, NULL, "");
cli_arg(argc, argv, o, "callerid", &callerid, NULL, NULL);
overlay_mdp_frame mdp;
bzero(&mdp,sizeof(mdp));
mdp.packetTypeAndFlags=MDP_VOMPEVENT;
mdp.vompevent.flags=VOMPEVENT_DIAL;
if (overlay_mdp_getmyaddr(0,&mdp.vompevent.local_sid[0])) return -1;
stowSid(mdp.vompevent.remote_sid,0,sid);
if (overlay_mdp_send(&mdp,MDP_AWAITREPLY,5000))
{
WHY("Dial request failed.");
}
return WHY("Not implemented");
}
int overlay_mdp_getmyaddr(int index,unsigned char *sid)
{
overlay_mdp_frame a;
a.packetTypeAndFlags=MDP_GETADDRS;
a.addrlist.first_sid=index;
a.addrlist.last_sid=0x7fffffff;
a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;
int result=overlay_mdp_send(&a,MDP_AWAITREPLY,5000);
if (result) {
if (a.packetTypeAndFlags==MDP_ERROR)
{
fprintf(stderr,"Could not get list of local MDP addresses\n");
fprintf(stderr," MDP Server error #%d: '%s'\n",
a.error.error,a.error.message);
}
else
fprintf(stderr,"Could not get list of local MDP addresses\n");
return -1;
}
if ((a.packetTypeAndFlags&MDP_TYPE_MASK)!=MDP_ADDRLIST)
return WHY("MDP Server returned something other than an address list");
bcopy(&a.addrlist.sids[0][0],sid,SID_SIZE);
return 0;
}