#ifndef _UWAV_NUMBER_H
#define _UWAV_NUMBER_H

#include "../include/public.h"

/*
 * Number type definition:
 * 32 digits number is used for party number handling
 * 16 digits number is used for prefix parameter
 * 8 digits number is used for short number parameter, i.e. cc, ndc
 */
typedef struct number32 {
	u8 num_of_digit;
	u8 digit[32];
} num32_t;

typedef struct number16 {
	u8 num_of_digit;
	u8 digit[16];
} num16_t;

typedef struct number8 {
	u8 num_of_digit;
	u8 digit[8];
} num8_t;

typedef struct isdn_num {
	u8 nai;		/* Nature of Address Indicator */
//	u8 npi;		/* Number Plan Indicator */
	u8 pi;
	u8 si;		/* Screen Indicator */
	num32_t num;
} isdn_t;

struct number_change {
	u8 nai;
	u8 del_count;
	num16_t insert;
};

#define is_dail_digit(digit) (digit < 0x0e)
#define char_to_digit(digit, ch) do { \
	if((ch >= '0') && (ch <= '9')) \
		digit = ch - '0'; \
	else if(ch == '*') \
		digit = 0x0b; \
	else if(ch == '#') \
		digit = 0x0c; \
	else \
		break; \
} while(0)
#define digit_to_char(ch, digit) do { \
	if(digit <= 9) \
		ch = digit + '0'; \
	else if(digit == 0x0b) \
		ch = '*'; \
	else if(digit == 0x0c) \
		ch = '#'; \
} while(0)

extern u8 nai_gsm_to_itu(u8 nai);
extern u8 nai_itu_to_gsm(u8 nai);
extern u8 *msc_isdn_to_bcd(u8 *bcd, const isdn_t *isdn);
extern isdn_t *netbcd_to_isdn(isdn_t *isdn, const u8 *bcd);
extern u8 *isdn_to_netbcd(u8 *bcd, const isdn_t *isdn);
extern int tbcd_to_string(char *str, const u8 *tbcd, u8 tbcd_len);
extern isdn_t *tpaddr_to_isdn(isdn_t *isdn, const u8 *tpaddr);
extern int string_to_num32(num32_t *num, const char *str);
extern int num32_to_string(char *str, const num32_t *num);
extern int string_to_num16(num16_t *num, const char *str);
extern int num16_to_string(char *str, const num16_t *num);
extern int string_to_num8(num8_t *num, const char *str);
extern int num8_to_string(char *str, const num8_t *num);
extern int digit2netbcd(u8 *netbcd, u8 *digit, u8 max_digit);
extern int netbcd2digit(u8 *digit, u8 *netbcd, u8 max_digit);
extern int digit_to_netbcd(u8 *netbcd, u8 *digit, u8 max_digit);
extern int netbcd_to_digit(u8 *digit, u8 *netbcd, u8 max_digit);
extern void msc_save_lai(u8 *lai, u8 *mcc, u8 *mnc, int lac);
extern void msc_load_lai(u8 *mcc, u8 *mnc, int *lac, u8 *lai);

#endif

