static int
handleConfirmedRequestPdu(
		MmsServerConnection* self,
		ConfirmedRequestPdu_t* request,
		ByteBuffer* response)
{
	long invokeIdLong;
	int32_t invokeId;

	asn_INTEGER2long((INTEGER_t*) &(request->invokeID), &invokeIdLong);

	invokeId = (int32_t) invokeIdLong;

	if (DEBUG) printf("invokeId: %i\n", invokeId);

	switch(request->confirmedServiceRequest.present) {
	case ConfirmedServiceRequest_PR_getNameList:
		mmsServer_handleGetNameListRequest(self, &(request->confirmedServiceRequest.choice.getNameList),
				invokeId, response);
		break;
	case ConfirmedServiceRequest_PR_read:
		mmsServer_handleReadRequest(self, &(request->confirmedServiceRequest.choice.read),
				invokeId, response);
		break;
	case ConfirmedServiceRequest_PR_write:
		mmsServer_handleWriteRequest(self, &(request->confirmedServiceRequest.choice.write),
						invokeId, response);
		break;
	case ConfirmedServiceRequest_PR_getVariableAccessAttributes:
		mmsServer_handleGetVariableAccessAttributesRequest(self,
				&(request->confirmedServiceRequest.choice.getVariableAccessAttributes),
				invokeId, response);
		break;
	case ConfirmedServiceRequest_PR_defineNamedVariableList:
		mmsServer_handleDefineNamedVariableListRequest(self,
				&(request->confirmedServiceRequest.choice.defineNamedVariableList),
				invokeId, response);
		break;
	case ConfirmedServiceRequest_PR_getNamedVariableListAttributes:
		mmsServer_handleGetNamedVariableListAttributesRequest(self,
				&(request->confirmedServiceRequest.choice.getNamedVariableListAttributes),
				invokeId, response);
		break;
	case ConfirmedServiceRequest_PR_deleteNamedVariableList:
		mmsServer_handleDeleteNamedVariableListRequest(self,
				&(request->confirmedServiceRequest.choice.deleteNamedVariableList),
				invokeId, response);
		break;
	default:
		writeMmsRejectPdu(&invokeId, REJECT_UNRECOGNIZED_SERVICE, response);
		break;
	}
}
static void
handleConfirmedRequestPdu(
		MmsServerConnection* self,
		uint8_t* buffer, int bufPos, int maxBufPos,
		ByteBuffer* response)
{
	uint32_t invokeId = 0;

	if (DEBUG) printf("invokeId: %i\n", invokeId);

	while (bufPos < maxBufPos) {
		uint8_t tag = buffer[bufPos++];
		uint32_t length;

		bufPos = BerDecoder_decodeLength(buffer, (int*) &length, bufPos, maxBufPos);

		if (bufPos < 0)  {
			writeMmsRejectPdu((int*) &invokeId, REJECT_UNRECOGNIZED_SERVICE, response);
			return;
		}

		if (DEBUG) printf("tag %02x size: %i\n", tag, length);

		switch(tag) {
		case 0x02: /* invoke Id */
			invokeId = BerDecoder_decodeUint32(buffer, length, bufPos);
			break;
		case 0xa1: /* get-name-list-request */
			mmsServer_handleGetNameListRequest(self, buffer, bufPos, bufPos + length,
					invokeId, response);
			break;
		case 0xa4: /* read-request */
			mmsServer_handleReadRequest(self, buffer, bufPos, bufPos + length,
					invokeId, response);
			break;
		case 0xa5: /* write-request */
			mmsServer_handleWriteRequest(self, buffer, bufPos, bufPos + length,
							invokeId, response);
			break;
		case 0xa6: /* get-variable-access-attributes-request */
			mmsServer_handleGetVariableAccessAttributesRequest(self,
					buffer, bufPos, bufPos + length,
					invokeId, response);
			break;
		case 0xab: /* define-named-variable-list */
			mmsServer_handleDefineNamedVariableListRequest(self,
					buffer, bufPos, bufPos + length,
					invokeId, response);
			break;
		case 0xac: /* get-named-variable-list-attributes-request */
			mmsServer_handleGetNamedVariableListAttributesRequest(self,
					buffer, bufPos, bufPos + length,
					invokeId, response);
			break;
		case 0xad: /* delete-named-variable-list-request */
			mmsServer_handleDeleteNamedVariableListRequest(self,
					buffer, bufPos, bufPos + length,
					invokeId, response);
			break;
		default:
			writeMmsRejectPdu((int*) &invokeId, REJECT_UNRECOGNIZED_SERVICE, response);
			return;
			break;
		}

		bufPos += length;
	}
}