int mmrp_send_notifications(struct mmrp_attribute *attrib, int notify)
{
char *msgbuf;
- char *stage;
char *variant;
char *regsrc;
+ char mrp_state[8];
client_t *client;
if (NULL == attrib)
if (NULL == msgbuf)
return -1;
- stage = variant = regsrc = NULL;
+ variant = regsrc = NULL;
- stage = (char *)malloc(128);
variant = (char *)malloc(128);
regsrc = (char *)malloc(128);
- if ((NULL == stage) || (NULL == variant) || (NULL == regsrc))
+ if ((NULL == variant) || (NULL == regsrc))
goto free_msgbuf;
memset(msgbuf, 0, MAX_MRPD_CMDSZ);
attrib->registrar.macaddr[2],
attrib->registrar.macaddr[3],
attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]);
- switch (attrib->registrar.mrp_state) {
- case MRP_IN_STATE:
- sprintf(stage, "MIN %s %s\n", variant, regsrc);
- break;
- case MRP_LV_STATE:
- sprintf(stage, "MLV %s %s\n", variant, regsrc);
- break;
- case MRP_MT_STATE:
- sprintf(stage, "MMT %s %s\n", variant, regsrc);
- break;
- default:
- break;
- }
+
+ mrp_decode_state(&attrib->registrar, &attrib->applicant,
+ mrp_state, sizeof(mrp_state));
switch (notify) {
case MRP_NOTIFY_NEW:
- snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MNE %s\n", stage);
+ snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MNE %s %s %s\n", variant, regsrc, mrp_state);
break;
case MRP_NOTIFY_JOIN:
- snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MJO %s\n", stage);
+ snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MJO %s %s %s\n", variant, regsrc, mrp_state);
break;
case MRP_NOTIFY_LV:
- snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MLE %s\n", stage);
+ snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "MLE %s %s %s\n", variant, regsrc, mrp_state);
break;
default:
goto free_msgbuf;
free_msgbuf:
if (variant)
free(variant);
- if (stage)
- free(stage);
if (regsrc)
free(regsrc);
free(msgbuf);
uint8_t srclassprio_firstval;
uint16_t srclassvid_firstval;
int attriblistlen;
- struct msrp_attribute *attrib, *vattrib;
+ struct msrp_attribute *attrib;
+/* pending review and deletion */
+#ifdef MSRP_AGGREGATE_DOMAINS_VECTORS
+ struct msrp_attribute *vattrib;
+#endif
mrpdu_message_t *mrpdu_msg;
unsigned char *mrpdu_msg_ptr = msgbuf;
unsigned char *mrpdu_msg_eof = msgbuf_eof;
int msrp_send_notifications(struct msrp_attribute *attrib, int notify)
{
char *msgbuf;
- char *stage;
char *variant;
char *regsrc;
+ char mrp_state[8];
client_t *client;
if (NULL == attrib)
if (NULL == msgbuf)
return -1;
- stage = variant = regsrc = NULL;
+ variant = regsrc = NULL;
- stage = (char *)malloc(128);
variant = (char *)malloc(128);
regsrc = (char *)malloc(128);
- if ((NULL == stage) || (NULL == variant) || (NULL == regsrc))
+ if ((NULL == variant) || (NULL == regsrc))
goto free_msgbuf;
memset(msgbuf, 0, MAX_MRPD_CMDSZ);
attrib->registrar.macaddr[3],
attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]);
+ mrp_decode_state(&attrib->registrar, &attrib->applicant,
+ mrp_state, sizeof(mrp_state));
+
switch (notify) {
case MRP_NOTIFY_NEW:
- sprintf(msgbuf, "SNE %s %s\n", variant, regsrc);
+ sprintf(msgbuf, "SNE %s %s %s\n", variant, regsrc, mrp_state);
break;
case MRP_NOTIFY_JOIN:
- sprintf(msgbuf, "SJO %s %s\n", variant, regsrc);
+ sprintf(msgbuf, "SJO %s %s %s\n", variant, regsrc, mrp_state);
break;
case MRP_NOTIFY_LV:
- sprintf(msgbuf, "SLE %s %s\n", variant, regsrc);
+ sprintf(msgbuf, "SLE %s %s %s\n", variant, regsrc, mrp_state);
break;
default:
goto free_msgbuf;
free(regsrc);
if (variant)
free(variant);
- if (stage)
- free(stage);
free(msgbuf);
return 0;
}
switch (attrib->applicant.sndmsg) {
case MRP_SND_IN:
/*
- * If 'In' in indicated by the applicant attribute, the
+ * If 'In' is indicated by the applicant attribute, then
* look at the registrar state to determine whether to
* send an In (if registrar is also In) or an Mt if the
* registrar is either Mt or Lv.
vectevt[0] = MRPDU_LV;
break;
case MRP_SND_JOIN:
- /* IF 'Join' in indicated by the applicant, look at
+ /* If 'Join' in indicated by the applicant, look at
* the corresponding registrar state to determine whether
* to send a JoinIn (if the registar state is 'In') or
* a JoinMt if the registrar state is MT or LV.
switch (vattrib->applicant.sndmsg) {
case MRP_SND_IN:
/*
- * If 'In' in indicated by the applicant attribute, the
+ * If 'In' is indicated by the applicant attribute, then
* look at the registrar state to determine whether to
* send an In (if registrar is also In) or an Mt if the
* registrar is either Mt or Lv.
vectevt[vectevt_idx] = MRPDU_LV;
break;
case MRP_SND_JOIN:
- /* IF 'Join' in indicated by the applicant, look at
+ /* If 'Join' in indicated by the applicant, look at
* the corresponding registrar state to determine whether
* to send a JoinIn (if the registar state is 'In') or
* a JoinMt if the registrar state is MT or LV.
int mvrp_send_notifications(struct mvrp_attribute *attrib, int notify)
{
char *msgbuf;
- char *stage;
char *variant;
char *regsrc;
+ char mrp_state[8];
client_t *client;
if (NULL == attrib)
if (NULL == msgbuf)
return -1;
- stage = variant = regsrc = NULL;
+ variant = regsrc = NULL;
- stage = (char *)malloc(128);
variant = (char *)malloc(128);
regsrc = (char *)malloc(128);
- if ((NULL == stage) || (NULL == variant) || (NULL == regsrc))
+ if ((NULL == variant) || (NULL == regsrc))
goto free_msgbuf;
memset(msgbuf, 0, MAX_MRPD_CMDSZ);
attrib->registrar.macaddr[3],
attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]);
- switch (attrib->registrar.mrp_state) {
- case MRP_IN_STATE:
- sprintf(stage, "VIN %s %s", variant, regsrc);
- break;
- case MRP_LV_STATE:
- sprintf(stage, "VLV %s %s", variant, regsrc);
- break;
- case MRP_MT_STATE:
- sprintf(stage, "VMT %s %s", variant, regsrc);
- break;
- default:
- break;
- }
+ mrp_decode_state(&attrib->registrar, &attrib->applicant,
+ mrp_state, sizeof(mrp_state));
+
switch (notify) {
case MRP_NOTIFY_NEW:
- snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VNE %s\n", stage);
+ snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VNE %s %s %s\n", variant, regsrc, mrp_state);
break;
case MRP_NOTIFY_JOIN:
- snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VJO %s\n", stage);
+ snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VJO %s %s %s\n", variant, regsrc, mrp_state);
break;
case MRP_NOTIFY_LV:
- snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VLE %s\n", stage);
+ snprintf(msgbuf, MAX_MRPD_CMDSZ - 1, "VLE %s %s %s\n", variant, regsrc, mrp_state);
break;
default:
goto free_msgbuf;
free(regsrc);
if (variant)
free(variant);
- if (stage)
- free(stage);
free(msgbuf);
return 0;
}
static int parse_app_state(char *sz, struct mrpdhelper_notify *n)
{
int i;
+ char *r;
+
+ r = strstr(sz, "R=");
+ if (r)
+ r = strchr(r, ' ');
+ if (!r)
+ return -1;
+
+ sz = r + 1;
/* loop over mrp_app_state_mapping struct */
for (i=0; i < 12; i++) {
static int parse_state(char *sz, struct mrpdhelper_notify *n)
{
+ char *r;
+
+ r = strstr(sz, "R=");
+ if (r)
+ r = strchr(r, ' ');
+ if (!r)
+ return -1;
+ sz = r + 4;
+
if (strncmp(sz, "IN", 2) == 0) {
n->state = mrpdhelper_state_in;
} else if (strncmp(sz, "LV", 3) == 0) {
static int parse_mvrp(char *sz, size_t len, struct mrpdhelper_notify *n)
{
/* format
- VIN VJO 1234 R=112233445566
+ VJO 1234 R=112233445566
len = 28
*/
if (len < 28)
if (parse_notification(&sz[1], n) < 0)
return -1;
- if (parse_state(&sz[5], n) < 0)
+ n->attrib = mrpdhelper_attribtype_mvrp;
+ if (sscanf(&sz[4], "%04x ", &n->u.v.vid) != 1)
return -1;
- n->attrib = mrpdhelper_attribtype_mvrp;
- if (sscanf(&sz[8], "%04x ", &n->u.v.vid) != 1)
+ if (parse_registrar(sz, n, NULL) < 0)
return -1;
- return parse_registrar(sz, n, NULL);
+
+ if (parse_app_state(sz, n) < 0)
+ return -1;
+
+ return parse_state(sz, n);
}
static int parse_msrp_string(char *sz, size_t len, struct mrpdhelper_notify *n)
if (parse_msrp_string(&sz[4], len - 4, n) < 0)
return -1;
- return parse_registrar(sz, n, NULL);
+ if (parse_registrar(sz, n, NULL) < 0)
+ return -1;
+
+ if (parse_app_state(sz, n) < 0)
+ return -1;
+
+ return parse_state(sz, n);
}
static int parse_mmrp(char *sz, size_t len, struct mrpdhelper_notify *n)
{
- /* format
- MIN MJO M=112233445566 R=112233445566
- len = 38
- */
- if (len < 38)
- return -1;
-
if (parse_notification(&sz[1], n) < 0)
return -1;