static inline MmsIndication parseMmsPdu(MmsServerConnection* self, ByteBuffer* message, ByteBuffer* response) { MmsIndication retVal; uint8_t* buffer = message->buffer; if (message->size < 2) return MMS_ERROR; int bufPos = 0; uint8_t pduType = buffer[bufPos++]; int pduLength; bufPos = BerDecoder_decodeLength(buffer, &pduLength, bufPos, message->size); if (bufPos < 0) return MMS_ERROR; if (DEBUG) printf("mms_server: recvd MMS-PDU type: %02x size: %u\n", pduType, pduLength); switch (pduType) { case 0xa8: /* Initiate request PDU */ handleInitiateRequestPdu(self, buffer, bufPos, bufPos + pduLength, response); retVal = MMS_INITIATE; break; case 0xa0: /* Confirmed request PDU */ handleConfirmedRequestPdu(self, buffer, bufPos, bufPos + pduLength, response); retVal = MMS_CONFIRMED_REQUEST; break; case 0x8b: /* Conclude request PDU */ mmsServer_writeConcludeResponsePdu(response); IsoConnection_close(self->isoConnection); retVal = MMS_CONCLUDE; break; case 0xa4: /* Reject PDU */ //TODO evaluate reject PDU printf("received reject PDU!\n"); /* silently ignore */ retVal = MMS_OK; break; default: mmsServer_writeMmsRejectPdu(NULL, MMS_REJECT_UNKNOWN_PDU_TYPE, response); retVal = MMS_ERROR; break; } parseMmsPdu_exit: return retVal; }
static inline MmsIndication parseMmsPdu(MmsServerConnection* self, ByteBuffer* message, ByteBuffer* response) { MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */ MmsIndication retVal; asn_dec_rval_t rval; /* Decoder return value */ rval = ber_decode(NULL, &asn_DEF_MmsPdu, (void**) &mmsPdu, (void*) message->buffer, message->size); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); if (rval.code != RC_OK) { retVal = MMS_ERROR; goto parseMmsPdu_exit; } switch (mmsPdu->present) { case MmsPdu_PR_initiateRequestPdu: handleInitiateRequestPdu(self, &(mmsPdu->choice.initiateRequestPdu), response); retVal = MMS_INITIATE; break; case MmsPdu_PR_confirmedRequestPdu: handleConfirmedRequestPdu(self, &(mmsPdu->choice.confirmedRequestPdu), response); retVal = MMS_CONFIRMED_REQUEST; break; case MmsPdu_PR_concludeRequestPDU: mmsServer_writeConcludeResponsePdu(response); IsoConnection_close(self->isoConnection); retVal = MMS_CONCLUDE; break; default: writeMmsRejectPdu(NULL, REJECT_UNKNOWN_PDU_TYPE, response); retVal = MMS_ERROR; break; } parseMmsPdu_exit: asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return retVal; }