diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index 95a7d36..caeded5 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -996,8 +996,10 @@ int db_sms_store(struct gsm_sms *sms)
 
 	dbi_conn_quote_string_copy(conn, (char *)sms->text, &q_text);
 	dbi_conn_quote_string_copy(conn, (char *)sms->dest_addr, &q_daddr);
-	dbi_conn_quote_binary_copy(conn, sms->user_data, sms->user_data_len,
-				   &q_udata);
+
+	int octet_len = get_octet_len(sms->user_data_len);
+	dbi_conn_quote_binary_copy(conn, sms->user_data, octet_len, &q_udata);
+
 	/* FIXME: correct validity period */
 	result = dbi_conn_queryf(conn,
 		"INSERT INTO SMS "
@@ -1057,17 +1059,40 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
 		sms->dest_addr[sizeof(sms->dest_addr)-1] = '\0';
 	}
 
-	sms->user_data_len = dbi_result_get_field_length(result, "user_data");
-	user_data = dbi_result_get_binary(result, "user_data");
-	if (sms->user_data_len > sizeof(sms->user_data))
-		sms->user_data_len = (u_int8_t) sizeof(sms->user_data);
-	memcpy(sms->user_data, user_data, sms->user_data_len);
-
 	text = dbi_result_get_string(result, "text");
 	if (text) {
 		strncpy(sms->text, text, sizeof(sms->text));
 		sms->text[sizeof(sms->text)-1] = '\0';
 	}
+
+	// user_data_len contains the number of character, therefore use the "text"-field to get user_data_len.
+	// But each extension character has to be count twice, because they need 2 septets.
+	sms->user_data_len = strlen(text);
+	int i;
+	for(i = 0; i < strlen(text); i++){
+		switch(text[i]){
+		case '|':		/* character: | */
+		case '^':		/* character: ^ */
+		case '€':		/* character: € */
+		case '{':		/* character: { */
+		case '}':		/* character: } */
+		case '[':		/* character: [ */
+		case ']':		/* character: ] */
+		case '~':		/* character: ~ */
+		case '\\':		/* character: \ */
+			sms->user_data_len++;
+		default:
+			continue;
+		}
+	}
+	// if we don't want to use the switch statement, we could use gsm_7bit_encode which tells us the correct length:
+	// sms->user_data_len = gsm_7bit_encode(sms->user_data, text);
+
+	user_data = dbi_result_get_binary(result, "user_data");
+	if (sms->user_data_len > sizeof(sms->user_data))
+		sms->user_data_len = (u_int8_t) sizeof(sms->user_data);
+	memcpy(sms->user_data, user_data, sms->user_data_len);
+
 	return sms;
 }
 
diff --git a/openbsc/src/libmsc/gsm_04_11.c b/openbsc/src/libmsc/gsm_04_11.c
index 812e758..9111d22 100644
--- a/openbsc/src/libmsc/gsm_04_11.c
+++ b/openbsc/src/libmsc/gsm_04_11.c
@@ -125,7 +125,10 @@ struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, int dcs, const ch
 		return NULL;
 
 	sms->receiver = subscr_get(receiver);
-	strncpy(sms->text, text, sizeof(sms->text)-1);
+
+	// ATM: because you can't send multiple sms from the terminal, copy only max 160 characters
+	strncpy(sms->text, text, 160);
+	//strncpy(sms->text, text, sizeof(sms->text)-1);
 
 	/* FIXME: don't use ID 1 static */
 	sms->sender = subscr_get_by_id(receiver->net, 1);
@@ -526,9 +529,7 @@ static int gsm340_gen_tpdu(struct msgb *msg, struct gsm_sms *sms)
 	/* generate TP-UD */
 	switch (gsm338_get_sms_alphabet(sms->data_coding_scheme)) {
 	case DCS_7BIT_DEFAULT:
-		octet_len = sms->user_data_len*7/8;
-		if (sms->user_data_len*7%8 != 0)
-			octet_len++;
+		octet_len = get_octet_len(sms->user_data_len);
 		/* Warning, user_data_len indicates the amount of septets
 		 * (characters), we need amount of octets occupied */
 		smsp = msgb_put(msg, octet_len);
diff --git a/openbsc/src/libmsc/gsm_04_80.c b/openbsc/src/libmsc/gsm_04_80.c
index 494c319..27b4ce6 100644
--- a/openbsc/src/libmsc/gsm_04_80.c
+++ b/openbsc/src/libmsc/gsm_04_80.c
@@ -73,7 +73,9 @@ int gsm0480_send_ussd_response(struct gsm_subscriber_connection *conn,
 	/* First put the payload text into the message */
 	ptr8 = msgb_put(msg, 0);
 	response_len = gsm_7bit_encode(ptr8, response_text);
-	msgb_put(msg, response_len);
+
+	int octet_len = get_octet_len(response_len);
+	msgb_put(msg, octet_len);
 
 	/* Then wrap it as an Octet String */
 	msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG);
