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

Support for pjsip 2.9 #29

Open
wants to merge 17 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
build.mak
build/zsrtp/docs/html
zrtp/

.DS_Store
ZRTP4J.xcodeproj/
4 changes: 2 additions & 2 deletions build/zsrtp/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Adapt this path to your pjproject path

export PJDIR := ~/devhome/pjproject.git
# export PJDIR := ~/devhome/pjproject.git

include $(PJDIR)/build.mak
include $(PJDIR)/build/common.mak
Expand Down Expand Up @@ -126,7 +126,7 @@ $(ZSRTP_LIB):

clean:
$(MAKE) -f $(RULES_MAK) APP=ZSRTP app=libzsrtp $@
rm -f $(ZSRTP_LIB)
rm -f $(LIBDIR)/$(ZSRTP_LIB)

print_lib:
$(MAKE) -f $(RULES_MAK) APP=ZSRTP app=libzsrtp $@
Expand Down
2 changes: 1 addition & 1 deletion example/simple_pjsua.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pjmedia_transport* on_create_media_transport(pjsua_call_id call_id,
* our partners ZID, shared data etc. If the files does not exists it will
* be created an initialized.
*/
pjmedia_transport_zrtp_initialize(zrtp_tp, "simple.zid", PJ_TRUE);
pjmedia_transport_zrtp_initialize(zrtp_tp, "/tmp/simple.zid", PJ_TRUE);
return zrtp_tp;
}

Expand Down
131 changes: 0 additions & 131 deletions zrtp_patch_1.10.patch

This file was deleted.

Empty file modified zsrtp/getzrtp.sh
100644 → 100755
Empty file.
134 changes: 133 additions & 1 deletion zsrtp/transport_zrtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ struct tp_zrtp
void (*stream_rtp_cb)(void *user_data,
void *pkt,
pj_ssize_t);
#if defined(PJ_VERSION_NUM_MAJOR) && defined(PJ_VERSION_NUM_MINOR)
#if (PJ_VERSION_NUM_MAJOR >= 2) && (PJ_VERSION_NUM_MINOR >= 8)
void (*stream_rtp_cb2)(pjmedia_tp_cb_param *param);
#endif
#endif
void (*stream_rtcp_cb)(void *user_data,
void *pkt,
pj_ssize_t);
Expand Down Expand Up @@ -1021,7 +1026,107 @@ static void transport_rtp_cb(void *user_data, void *pkt, pj_ssize_t size)
}
if (!zrtp->started && zrtp->enableZrtp)
pjmedia_transport_zrtp_startZrtp((pjmedia_transport *)zrtp);
return;
}

// We assume all other packets are ZRTP packets here. Process
// if ZRTP processing is enabled. Because valid RTP packets are
// already handled we delete any packets here after processing.
if (zrtp->enableZrtp && zrtp->zrtpCtx != NULL)
{
unsigned char* zrtpMsg = NULL;
pj_uint32_t magic = *(pj_uint32_t*)(buffer + 4);

// Get CRC value into crc (see above how to compute the offset)
pj_uint16_t temp = (pj_uint16_t)(size - CRC_SIZE);
pj_uint32_t crc = *(uint32_t*)(buffer + temp);
crc = pj_ntohl(crc);

if (!zrtp_CheckCksum(buffer, temp, crc))
{
if (zrtp->userCallback.zrtp_showMessage != NULL)
zrtp->userCallback.zrtp_showMessage(zrtp->userCallback.userData, zrtp_Warning, zrtp_WarningCRCmismatch);
return;
}
magic = pj_ntohl(magic);

// Check if it is really a ZRTP packet, return, no further processing
if (magic != ZRTP_MAGIC || zrtp->zrtpCtx == NULL)
{
return;
}
// cover the case if the other party sends _only_ ZRTP packets at the
// beginning of a session. Start ZRTP in this case as well.
if (!zrtp->started)
{
pjmedia_transport_zrtp_startZrtp((pjmedia_transport *)zrtp);
}
// this now points beyond the undefined and length field.
// We need them, thus adjust
zrtpMsg = (buffer + 12);

// store peer's SSRC in host order, used when creating the CryptoContext
zrtp->peerSSRC = *(pj_uint32_t*)(buffer + 8);
zrtp->peerSSRC = pj_ntohl(zrtp->peerSSRC);
zrtp_processZrtpMessage(zrtp->zrtpCtx, zrtpMsg, zrtp->peerSSRC, size);
}
}

#if defined(PJ_VERSION_NUM_MAJOR) && defined(PJ_VERSION_NUM_MINOR)
#if (PJ_VERSION_NUM_MAJOR >= 2) && (PJ_VERSION_NUM_MINOR >= 8)
static void transport_rtp_cb2(pjmedia_tp_cb_param *param)
{
struct tp_zrtp *zrtp = (struct tp_zrtp*)param->user_data;

void *pkt = param->pkt;
pj_uint8_t* buffer = (pj_uint8_t*)pkt;
int32_t newLen = 0;
pj_ssize_t size = param->size;
pj_status_t rc = PJ_SUCCESS;

pj_assert(zrtp && zrtp->stream_rtcp_cb && pkt);

// check if this could be a real RTP/SRTP packet.
if ((*buffer & 0xf0) != 0x10)
{
// Could be real RTP, check if we are in secure mode
if (zrtp->srtpReceive == NULL || size < 0)
{
struct pjmedia_tp_cb_param tp = { zrtp->stream_user_data, pkt, size, NULL, PJ_FALSE };
zrtp->stream_rtp_cb2(&tp);
}
else
{
rc = zsrtp_unprotect(zrtp->srtpReceive, (pj_uint8_t*)pkt, size, &newLen);
if (rc == 1)
{
zrtp->unprotect++;
struct pjmedia_tp_cb_param tp = { zrtp->stream_user_data, pkt, newLen, NULL, PJ_FALSE };
zrtp->stream_rtp_cb2(&tp);
// zrtp->stream_rtp_cb2(zrtp->stream_user_data, pkt,
// newLen);
zrtp->unprotect_err = 0;
}
else
{
if (zrtp->userCallback.zrtp_showMessage != NULL)
{
if (rc == -1) {
zrtp->userCallback.zrtp_showMessage(zrtp->userCallback.userData,
zrtp_Warning,
zrtp_WarningSRTPauthError);
}
else {
zrtp->userCallback.zrtp_showMessage(zrtp->userCallback.userData,
zrtp_Warning,
zrtp_WarningSRTPreplayError);
}
}
zrtp->unprotect_err = rc;
}
}
if (!zrtp->started && zrtp->enableZrtp)
pjmedia_transport_zrtp_startZrtp((pjmedia_transport *)zrtp);
return;
}

Expand Down Expand Up @@ -1067,6 +1172,8 @@ static void transport_rtp_cb(void *user_data, void *pkt, pj_ssize_t size)
zrtp_processZrtpMessage(zrtp->zrtpCtx, zrtpMsg, zrtp->peerSSRC, size);
}
}
#endif
#endif


/* This is our RTCP callback, that is called by the slave transport when it
Expand Down Expand Up @@ -1161,6 +1268,11 @@ static void transport_detach(pjmedia_transport *tp, void *strm)
pjmedia_transport_detach(zrtp->slave_tp, zrtp);
zrtp->stream_user_data = NULL;
zrtp->stream_rtp_cb = NULL;
#if defined(PJ_VERSION_NUM_MAJOR) && defined(PJ_VERSION_NUM_MINOR)
#if (PJ_VERSION_NUM_MAJOR >= 2) && (PJ_VERSION_NUM_MINOR >= 8)
zrtp->stream_rtp_cb2 = NULL;
#endif
#endif
zrtp->stream_rtcp_cb = NULL;
}
}
Expand Down Expand Up @@ -1488,16 +1600,31 @@ static pj_status_t transport_attach2(pjmedia_transport *tp, pjmedia_transport_at
pj_assert(zrtp->stream_user_data == NULL);
zrtp->stream_user_data = att_param->user_data;
zrtp->stream_rtp_cb = att_param->rtp_cb;
#if defined(PJ_VERSION_NUM_MAJOR) && defined(PJ_VERSION_NUM_MINOR)
#if (PJ_VERSION_NUM_MAJOR >= 2) && (PJ_VERSION_NUM_MINOR >= 8)
zrtp->stream_rtp_cb2 = att_param->rtp_cb2;
#endif
#endif
// zrtp->stream_rtp_cb = att_param->rtp_cb; //! att_param->rtp_cb is NULL
zrtp->stream_rtcp_cb = att_param->rtcp_cb;

//! zrtp->stream_rtp_cb is NULL here
PJ_LOG(4, (THIS_FILE, "Assigned within transport_attach2 to zrtp->stream_rtp_cb2: %p", zrtp->stream_rtp_cb2));

pjmedia_transport_attach_param param = {NULL,
PJMEDIA_TYPE_AUDIO, //Video calls later?
att_param->rem_addr,
att_param->rem_rtcp,
att_param->addr_len,
zrtp,
&transport_rtp_cb,
&transport_rtcp_cb};
&transport_rtcp_cb
#if defined(PJ_VERSION_NUM_MAJOR) && defined(PJ_VERSION_NUM_MINOR)
#if (PJ_VERSION_NUM_MAJOR >= 2) && (PJ_VERSION_NUM_MINOR >= 8)
, &transport_rtp_cb2
#endif
#endif
};



Expand All @@ -1506,6 +1633,11 @@ static pj_status_t transport_attach2(pjmedia_transport *tp, pjmedia_transport_at
{
zrtp->stream_user_data = NULL;
zrtp->stream_rtp_cb = NULL;
#if defined(PJ_VERSION_NUM_MAJOR) && defined(PJ_VERSION_NUM_MINOR)
#if (PJ_VERSION_NUM_MAJOR >= 2) && (PJ_VERSION_NUM_MINOR >= 8)
zrtp->stream_rtp_cb2 = NULL;
#endif
#endif
zrtp->stream_rtcp_cb = NULL;
return status;
}
Expand Down