diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index e0086fa7e..f5e3cfce2 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -50,6 +50,7 @@ struct mgcp_rtp_state { uint16_t base_seq; uint16_t max_seq; int seq_offset; + int cycles; uint32_t last_timestamp; int32_t timestamp_offset; diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c index 85d03090a..233418b87 100644 --- a/openbsc/src/libmgcp/mgcp_network.c +++ b/openbsc/src/libmgcp/mgcp_network.c @@ -73,6 +73,10 @@ struct rtp_hdr { uint32_t ssrc; } __attribute__((packed)); +#define RTP_SEQ_MOD (1 << 16) +#define RTP_MAX_DROPOUT 3000 +#define RTP_MAX_MISORDER 100 + enum { DEST_NETWORK = 0, @@ -116,7 +120,7 @@ int mgcp_send_dummy(struct mgcp_endpoint *endp) static void patch_and_count(struct mgcp_endpoint *endp, struct mgcp_rtp_state *state, int payload, struct sockaddr_in *addr, char *data, int len) { - uint16_t seq; + uint16_t seq, udelta; uint32_t timestamp; struct rtp_hdr *rtp_hdr; @@ -154,6 +158,21 @@ static void patch_and_count(struct mgcp_endpoint *endp, struct mgcp_rtp_state *s rtp_hdr->timestamp = htonl(timestamp); } + /* + * The below takes the shape of the validation from Appendix A. Check + * if there is something weird with the sequence number, otherwise check + * for a wrap around in the sequence number. + */ + udelta = seq - state->max_seq; + if (udelta < RTP_MAX_DROPOUT) { + if (seq < state->max_seq) + state->cycles += RTP_SEQ_MOD; + } else if (udelta <= RTP_SEQ_MOD + RTP_MAX_MISORDER) { + LOGP(DMGCP, LOGL_NOTICE, + "RTP seqno made a very large jump on 0x%x delta: %u\n", + ENDPOINT_NUMBER(endp), udelta); + } + state->max_seq = seq; state->last_timestamp = timestamp;