Commit c60fab0f authored by Steve Arendt's avatar Steve Arendt

Initial checkin

parent e4f99aec
###
#
# Makefile for Mock DTCP library customized for OCAP RI.
#
###
HOSTOS := $(shell uname -o)
export HOSTOS
ifeq ($(HOSTOS),Cygwin)
CC = gcc-3 -mno-cygwin
DLL_SUFFIX = dll
MODULES_LINK_EXT = -lws2_32 -lwinmm
LINK_PATHS = -Llib/win32
else ifeq ($(HOSTOS),GNU/Linux)
CC = gcc
DLL_SUFFIX = so
LINK_PATHS = -Llib/linux
else
$(error Unsupported OS.)
endif
DTCPIP_DLL ?= dtcpip_mock.$(DLL_SUFFIX)
MODULE_MOCKDLL = mockdll
MODULE_LINK_PFX = $(addprefix -l,mockdll)
MODULE_LINK = $(addprefix -l,$(MODULE_MOCKDLL))
default: all
$(MODULE_MOCKDLL):
$(MAKE) -C _build build
all: $(MODULE_MOCKDLL)
build: $(MODULE_MOCKDLL)
shlib: build $(MODULE_MOCKDLL)
$(CC) -shared -o $(DTCPIP_DLL) -Wl,--whole-archive -lmockdll $(LINK_PATHS) -Wl,--no-whole-archive $(MODULE_LINK_EXT)
clean:
$(MAKE) -C _build clean
purge:
rm -f $(DTCPIP_DLL)
INC_DIRS = ../src
MOCKDLL_SRC_DIR = ../src
MOCKDLL_LIBNAME = libmockdll.a
COPT = -c -efi2 -fPIC\
-D_ARCH_IA32 -DUPNP_MICRO_STACK -DMICROSTACK_NO_STDAFX -DMPE_LITTLE_ENDIAN -O0 -g \
$(addprefix -I, $(INC_DIRS))
CSRC := $(wildcard $(MOCKDLL_SRC_DIR)/*.c)
ifeq ($(HOSTOS),Cygwin)
MOCKDLL_LIB_DIR = ../lib/win32
MOCKDLL_OBJ_DIR = ../obj/win32
MOCKDLL_OBJ_SUBDIR = ../obj/win32/win32
CC = gcc-3 -mno-cygwin
COPT += -DWINSOCK2
INC_DIRS += ../src/win32
INC_DIRS += ../src/win32/include
CSRCTEMP := $(wildcard $(MOCKDLL_SRC_DIR)/win32/*.c)
COBJ := $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/%.o,$(notdir $(CSRC)))
CSRC += $CSRCTEMP;
COBJ += $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/win32/%.o,$(notdir $(CSRCTEMP)))
else ifeq ($(HOSTOS),GNU/Linux)
MOCKDLL_LIB_DIR = ../lib/linux
MOCKDLL_OBJ_DIR = ../obj/linux
MOCKDLL_OBJ_SUBDIR = ../obj/linux/linux
CC = gcc
COPT += -Dunix -Dlinux -Dlinux32 -D_POSIX
INC_DIRS += ../src/linux
INC_DIRS += ../src/linux/include
CSRCTEMP := $(wildcard $(MOCKDLL_SRC_DIR)/linux/*.c)
COBJ := $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/%.o,$(notdir $(CSRC)))
CSRC += $CSRCTEMP;
COBJ += $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/linux/%.o,$(notdir $(CSRCTEMP)))
else
$(error Unsupported OS.)
endif
build: clean_lib prepare $(MOCKDLL_LIBNAME)
$(MOCKDLL_LIBNAME) : $(COBJ)
/usr/bin/ar q $(MOCKDLL_LIB_DIR)/$@ $(COBJ)
$(COBJ) : $(MOCKDLL_OBJ_DIR)/%.o : $(MOCKDLL_SRC_DIR)/%.c $(wildcard $(addsuffix /*.h, $(INC_DIRS)))
$(CC) $(COPT) -o $@ $<
clean: clean_lib
rm -fR $(MOCKDLL_OBJ_DIR)
clean_lib:
rm -fR $(MOCKDLL_LIB_DIR)/$(MOCKDLL_LIBNAME)
prepare:
mkdir -p $(MOCKDLL_OBJ_DIR)
mkdir -p $(MOCKDLL_OBJ_SUBDIR)
mkdir -p $(MOCKDLL_LIB_DIR)
File added
// COPYRIGHT_BEGIN
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
//
// Copyright (C) 2008-2011, Cable Television Laboratories, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2. This program is distributed
// in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Please contact CableLabs if you need additional information or
// have any questions.
//
// CableLabs
// 858 Coal Creek Cir
// Louisville, CO 80027-9750
// 303 661-9100
// oc-mail@cablelabs.com
//
// If you or the company you represent has a separate agreement with CableLabs
// concerning the use of this code, your rights and obligations with respect
// to this code shall be as set forth therein. No license is granted hereunder
// for any other purpose.
// COPYRIGHT_END
#include "mock_sync.h"
#include <stdio.h>
#include <string.h> // memcpy, strrchr, strlen
#if defined( WIN32 )
#define snprintf _snprintf
#endif
#include "MockDLL.h"
#define DTCPIP_SERVER_SESSION_START 65536
#define DTCPIP_SERVER_SESSIONS_MAX sizeof(uint32_t)
static struct
{
mock_Mutex mutex;
uint32_t sessions;
}
server_data;
int dtcpip_cmn_init(const char* storage_path)
{
return 0;
}
void dtcpip_cmn_get_version(char* string, size_t length)
{
snprintf(string, length, "NO-OP DTCP-IP library for OCAP Reference Implementation.");
}
int dtcpip_src_init(unsigned short dtcp_port)
{
int ret_code = -1;
if (mock_mutexNew(&server_data.mutex) != MPE_SUCCESS)
{
ret_code = -2;
}
else
{
ret_code = 0;
}
return ret_code;
}
int dtcpip_src_open(int* session_handle, int is_audio_only)
{
int ret_code = -1;
if (session_handle == NULL)
{
ret_code = -2;
}
else
{
int i = 0;
uint32_t session = 0;
mock_mutexAcquire(server_data.mutex);
for (i = 0; i < DTCPIP_SERVER_SESSIONS_MAX; i++)
{
session = 1 << i;
if ((server_data.sessions & session) == 0)
{
break;
}
}
if (i == DTCPIP_SERVER_SESSIONS_MAX)
{
ret_code = -3;
}
else
{
server_data.sessions ^= session;
*session_handle = (int) (DTCPIP_SERVER_SESSION_START + i);
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
}
return ret_code;
}
int dtcpip_src_alloc_encrypt(int session_handle,
unsigned char cci,
char* cleartext_data, size_t cleartext_size,
char** encrypted_data, size_t* encrypted_size)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_SERVER_SESSION_START);
mock_mutexAcquire(server_data.mutex);
if ((server_data.sessions & session) == 0)
{
ret_code = -2;
}
else if (cleartext_data == NULL && cleartext_size > 0) // only read if we have data
{
ret_code = -3;
}
else if (encrypted_data == NULL && cleartext_size > 0) // only written if we have data
{
ret_code = -4;
}
else if (encrypted_size == NULL) // always written
{
ret_code = -5;
}
else if (cleartext_size == 0)
{
*encrypted_size = 0;
ret_code = 0;
}
else if ((*encrypted_data = malloc(cleartext_size)) == NULL)
{
ret_code = -6;
}
else
{
memcpy(*encrypted_data, cleartext_data, cleartext_size);
*encrypted_size = cleartext_size;
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
return ret_code;
}
int dtcpip_src_free(char* encrypted_data)
{
free(encrypted_data);
return 0;
}
int dtcpip_src_close(int session_handle)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_SERVER_SESSION_START);
mock_mutexAcquire(server_data.mutex);
if ((server_data.sessions & session) == 0)
{
ret_code = -2;
}
else
{
server_data.sessions ^= session;
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
return ret_code;
}
#define DTCPIP_PLAYER_SESSION_START 16777216
#define DTCPIP_PLAYER_SESSIONS_MAX sizeof(uint32_t)
static struct
{
mock_Mutex mutex;
uint32_t sessions;
}
player_data;
int dtcpip_snk_init(void)
{
int ret_code = -1;
if (mock_mutexNew(&player_data.mutex) != MPE_SUCCESS)
{
ret_code = -2;
}
else
{
player_data.sessions = 0;
ret_code = 0;
}
return ret_code;
}
int dtcpip_snk_open(
char* ip_addr, unsigned short ip_port,
int *session_handle)
{
int ret_code = -1;
if (ip_addr == NULL)
{
ret_code = -2;
}
else if (session_handle == NULL)
{
ret_code = -3;
}
else
{
int i = 0;
uint32_t session = 0;
mock_mutexAcquire(player_data.mutex);
for (i = 0; i < DTCPIP_PLAYER_SESSIONS_MAX; i++)
{
session = 1 << i;
if ((player_data.sessions & session) == 0)
{
break;
}
}
if (i == DTCPIP_PLAYER_SESSIONS_MAX)
{
ret_code = -4;
}
else
{
player_data.sessions ^= session;
*session_handle = (int) (DTCPIP_PLAYER_SESSION_START + i);
ret_code = 0;
}
mock_mutexRelease(player_data.mutex);
}
return ret_code;
}
int dtcpip_snk_alloc_decrypt(int session_handle,
char* encrypted_data, size_t encrypted_size,
char** cleartext_data, size_t* cleartext_size)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_PLAYER_SESSION_START);
mock_mutexAcquire(player_data.mutex);
if ((player_data.sessions & session) == 0)
{
ret_code = -2;
}
else if (encrypted_data == NULL && encrypted_size > 0) // only read if we have data
{
ret_code = -3;
}
else if (cleartext_data == NULL && encrypted_size > 0) // only written if we have data
{
ret_code = -4;
}
else if (cleartext_size == NULL) // always written
{
ret_code = -5;
}
else if (encrypted_size == 0)
{
*cleartext_size = 0;
ret_code = 0;
}
else if ((*cleartext_data = malloc(encrypted_size)) == NULL)
{
ret_code = -6;
}
else
{
memcpy(*cleartext_data, encrypted_data, encrypted_size);
*cleartext_size = encrypted_size;
ret_code = 0;
}
mock_mutexRelease(player_data.mutex);
return ret_code;
}
int dtcpip_snk_free(char* cleartext_data)
{
free(cleartext_data);
return 0;
}
int dtcpip_snk_close(int session_handle)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_PLAYER_SESSION_START);
mock_mutexAcquire(player_data.mutex);
if ((player_data.sessions & session) == 0)
{
ret_code = -2;
}
else
{
player_data.sessions ^= session;
ret_code = 0;
}
mock_mutexRelease(player_data.mutex);
return ret_code;
}
// COPYRIGHT_BEGIN
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
//
// Copyright (C) 2008-2011, Cable Television Laboratories, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2. This program is distributed
// in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Please contact CableLabs if you need additional information or
// have any questions.
//
// CableLabs
// 858 Coal Creek Cir
// Louisville, CO 80027-9750
// 303 661-9100
// oc-mail@cablelabs.com
//
// If you or the company you represent has a separate agreement with CableLabs
// concerning the use of this code, your rights and obligations with respect
// to this code shall be as set forth therein. No license is granted hereunder
// for any other purpose.
// COPYRIGHT_END
#include "mock_sync.h"
#include <stdio.h>
#include <string.h> // memcpy, strrchr, strlen
#if defined( WIN32 )
#define snprintf _snprintf
#endif
#include "MockDLL.h"
#define DTCPIP_SERVER_SESSION_START 65536
#define DTCPIP_SERVER_SESSIONS_MAX sizeof(uint32_t)
static struct
{
mock_Mutex mutex;
uint32_t sessions;
}
server_data;
int dtcpip_cmn_init(const char* storage_path)
{
return 0;
}
void dtcpip_cmn_get_version(char* string, size_t length)
{
snprintf(string, length, "NO-OP DTCP-IP library for OCAP Reference Implementation.");
}
int dtcpip_src_init(unsigned short dtcp_port)
{
int ret_code = -1;
if (mock_mutexNew(&server_data.mutex) != MPE_SUCCESS)
{
ret_code = -2;
}
else
{
ret_code = 0;
}
return ret_code;
}
int dtcpip_src_open(int* session_handle, int is_audio_only)
{
int ret_code = -1;
if (session_handle == NULL)
{
ret_code = -2;
}
else
{
int i = 0;
uint32_t session = 0;
mock_mutexAcquire(server_data.mutex);
for (i = 0; i < DTCPIP_SERVER_SESSIONS_MAX; i++)
{
session = 1 << i;
if ((server_data.sessions & session) == 0)
{
break;
}
}
if (i == DTCPIP_SERVER_SESSIONS_MAX)
{
ret_code = -3;
}
else
{
server_data.sessions ^= session;
*session_handle = (int) (DTCPIP_SERVER_SESSION_START + i);
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
}
return ret_code;
}
int dtcpip_src_alloc_encrypt(int session_handle,
unsigned char cci,
char* cleartext_data, size_t cleartext_size,
char** encrypted_data, size_t* encrypted_size)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_SERVER_SESSION_START);
mock_mutexAcquire(server_data.mutex);
if ((server_data.sessions & session) == 0)
{
ret_code = -2;
}
else if (cleartext_data == NULL && cleartext_size > 0) // only read if we have data
{
ret_code = -3;
}
else if (encrypted_data == NULL && cleartext_size > 0) // only written if we have data
{
ret_code = -4;
}
else if (encrypted_size == NULL) // always written
{
ret_code = -5;
}
else if (cleartext_size == 0)
{
*encrypted_size = 0;
ret_code = 0;
}
else if ((*encrypted_data = malloc(cleartext_size)) == NULL)
{
ret_code = -6;
}
else
{
memcpy(*encrypted_data, cleartext_data, cleartext_size);
*encrypted_size = cleartext_size;
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
return ret_code;
}
int dtcpip_src_free(char* encrypted_data)
{
free((void *)encrypted_data);
return 0;
}
int dtcpip_src_close(int session_handle)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_SERVER_SESSION_START);
mock_mutexAcquire(server_data.mutex);
if ((server_data.sessions & session) == 0)
{
ret_code = -2;
}
else
{
server_data.sessions ^= session;
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
return ret_code;
}
#define DTCPIP_PLAYER_SESSION_START 16777216
#define DTCPIP_PLAYER_SESSIONS_MAX sizeof(uint32_t)
static struct
{
mock_Mutex mutex;
uint32_t sessions;
}
player_data;
int dtcpip_snk_init(void)
{
int ret_code = -1;
if (mock_mutexNew(&player_data.mutex) != MPE_SUCCESS)
{
ret_code = -2;
}
else
{
player_data.sessions = 0;
ret_code = 0;
}
return ret_code;
}
int dtcpip_snk_open(
char* ip_addr, unsigned short ip_port,
int *session_handle)
{
int ret_code = -1;
if (ip_addr == NULL)
{
ret_code = -2;
}
else if (session_handle == NULL)
{
ret_code = -3;
}
else
{
int i = 0;
uint32_t session = 0;
mock_mutexAcquire(player_data.mutex);
for (i = 0; i < DTCPIP_PLAYER_SESSIONS_MAX; i++)
{
session = 1 << i;
if ((player_data.sessions & session) == 0)
{
break;
}
}
if (i == DTCPIP_PLAYER_SESSIONS_MAX)
{
ret_code = -4;
}
else
{
player_data.sessions ^= session;
*session_handle = (int) (DTCPIP_PLAYER_SESSION_START + i);
ret_code = 0;
}
mock_mutexRelease(player_data.mutex);
}
return ret_code;
}
int dtcpip_snk_alloc_decrypt(int session_handle,
char* encrypted_data, size_t encrypted_size,
char** cleartext_data, size_t* cleartext_size)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_PLAYER_SESSION_START);
mock_mutexAcquire(player_data.mutex);
if ((player_data.sessions & session) == 0)
{
ret_code = -2;
}
else if (encrypted_data == NULL && encrypted_size > 0) // only read if we have data
{
ret_code = -3;
}
else if (cleartext_data == NULL && encrypted_size > 0) // only written if we have data
{
ret_code = -4;
}
else if (cleartext_size == NULL) // always written
{
ret_code = -5;
}
else if (encrypted_size == 0)
{
*cleartext_size = 0;
ret_code = 0;
}
else if ((*cleartext_data = malloc(encrypted_size)) == NULL)
{
ret_code = -6;
}