]> git.sesse.net Git - rdpsrv/blobdiff - mcs.c
Pull in rdp.c from rdesktop, use rdp_recv().
[rdpsrv] / mcs.c
diff --git a/mcs.c b/mcs.c
index 9e6740f950022ab63751722393ebf82f16f4efee..e3690516e9fb75ec8a4cb244c9f25d8a5d7a97ac 100644 (file)
--- a/mcs.c
+++ b/mcs.c
@@ -180,7 +180,7 @@ mcs_send_connect_response()
        // aiee, no crypto info yet! :-)
        
        s_mark_end(s);
-       printf("LEN: %u\n", s->p - s->data);
+       printf("LEN: %u\n", s->p - s->iso_hdr);
        iso_send(s);
 
 }
@@ -215,35 +215,20 @@ mcs_send_aurq(void)
        iso_send(s);
 }
 
-/* Expect a AUcf message (ASN.1 PER) */
-static BOOL
-mcs_recv_aucf(uint16 * mcs_userid)
+/* Send a AUcf message (ASN.1 PER) */
+static void
+mcs_send_aucf(uint16 mcs_userid)
 {
-       uint8 opcode, result;
        STREAM s;
 
-       s = iso_recv();
-       if (s == NULL)
-               return False;
-
-       in_uint8(s, opcode);
-       if ((opcode >> 2) != MCS_AUCF)
-       {
-               error("expected AUcf, got %d\n", opcode);
-               return False;
-       }
-
-       in_uint8(s, result);
-       if (result != 0)
-       {
-               error("AUrq: %d\n", result);
-               return False;
-       }
-
-       if (opcode & 2)
-               in_uint16_be(s, *mcs_userid);
+       s = iso_init(5);
 
-       return s_check_end(s);
+       out_uint8(s, (MCS_AUCF << 2) | 2);  // | 2 = send user ID
+       out_uint8(s, 0);  // success
+       out_uint16_be(s, 0);
+       
+       s_mark_end(s);
+       iso_send(s);
 }
 
 /* Send a CJrq message (ASN.1 PER) */
@@ -265,35 +250,20 @@ mcs_send_cjrq(uint16 chanid)
 }
 
 /* Expect a CJcf message (ASN.1 PER) */
-static BOOL
-mcs_recv_cjcf(void)
+static void
+mcs_send_cjcf(uint16 userid, uint16 chanid)
 {
-       uint8 opcode, result;
        STREAM s;
 
-       s = iso_recv();
-       if (s == NULL)
-               return False;
-
-       in_uint8(s, opcode);
-       if ((opcode >> 2) != MCS_CJCF)
-       {
-               error("expected CJcf, got %d\n", opcode);
-               return False;
-       }
-
-       in_uint8(s, result);
-       if (result != 0)
-       {
-               error("CJrq: %d\n", result);
-               return False;
-       }
+       s = iso_init(5);
 
-       in_uint8s(s, 4);        /* mcs_userid, req_chanid */
-       if (opcode & 2)
-               in_uint8s(s, 2);        /* join_chanid */
+       out_uint8(s, (MCS_CJCF << 2));
+       out_uint8(s, 0); // success
+       out_uint16_be(s, g_mcs_userid);
+       out_uint16_be(s, chanid);
 
-       return s_check_end(s);
+       s_mark_end(s);
+       iso_send(s);
 }
 
 /* Initialise an MCS transport data packet */
@@ -338,7 +308,7 @@ mcs_send(STREAM s)
 STREAM
 mcs_recv(uint16 * channel)
 {
-       uint8 opcode, appid, length;
+       uint8 opcode, appid, length, userid;
        STREAM s;
 
        s = iso_recv();
@@ -347,23 +317,40 @@ mcs_recv(uint16 * channel)
 
        in_uint8(s, opcode);
        appid = opcode >> 2;
-       if (appid != MCS_SDIN)
-       {
-               if (appid != MCS_DPUM)
-               {
-                       error("expected data, got %d\n", opcode);
-               }
+
+       switch (appid) {
+       case MCS_SDRQ:
+               in_uint8s(s, 2);        /* userid */
+               in_uint16_be(s, *channel);
+               in_uint8s(s, 1);        /* flags */
+               in_uint8(s, length);
+               if (length & 0x80)
+                       in_uint8s(s, 1);        /* second byte of length */
+
+               return s;
+       case MCS_DPUM:
+               return NULL;
+       case MCS_EDRQ:
+               // Erect Domain (ignore)
+               printf("Received EDrq\n");
+               return NULL;
+       case MCS_AURQ:
+               // Attach User Request, respond with AUcf (Attach User Confirm)
+               printf("Received AUrq, sending AUcf\n");
+               mcs_send_aucf(0);
+               return NULL;
+       case MCS_CJRQ:
+               // Channel Join Request, respond with CJcf (Channel Join Confirm);
+               in_uint16_be(s, userid);
+               in_uint16_be(s, *channel);
+               printf("Received CJrq for channel %hu, sending CJcf\n", *channel);
+               mcs_send_cjcf(userid, *channel);
+               return NULL;
+       default:
+               error("expected data, got %d\n", opcode);
                return NULL;
        }
 
-       in_uint8s(s, 2);        /* userid */
-       in_uint16_be(s, *channel);
-       in_uint8s(s, 1);        /* flags */
-       in_uint8(s, length);
-       if (length & 0x80)
-               in_uint8s(s, 1);        /* second byte of length */
-
-       return s;
 }
 
 /* Disconnect from the MCS layer */